.xml文件中添加SQL数,返回主键ID
在 .xml文件中写插入的sql语句;
<insert id="addUpload" parameterType="int" keyProperty="id" keyColumn="id">
insert into 表名 (
<if test="name != null and name != ">name,</if>
<if test="path != null and path != ">path,</if>
<if test="mime != null and mime != ">mime,</if>
<if test="size != null">size,</if>
<if test="md5 != null and md5 != ">md5,</if>
<if test="sha1 != null and sha1 != ">sha1,</if>
<if test="createBy != null and createBy != ">create_by,</if>
create_date
)values(
<if test="name != null and name != ">#{name},</if>
<if test="path != null and path != ">#{path},</if>
<if test="mime != null and mime != ">#{mime},</if>
<if test="size != null">#{size},</if>
<if test="md5 != null and md5 != ">#{md5},</if>
<if test="sha1 != null and sha1 != ">#{sha1},</if>
<if test="createBy != null and createBy != ">#{createBy},</if>
sysdate()
)
</insert>
上面的添加语句关键就在于
keyProperty="id" keyColumn="id" //这里的id指的是 对象中对应的主键id 因为是自增的,所以这里不显示
如果使用
int ii = uploadMapper.addUpload(upload); //upload 时添加的对应对象; //这里我们直接 通过 upload.getId() 直接获取,就可以获取到 ID ; Long id = upload.getId();
返还对象集合 parameterType=list 即可;
<select id="findDataItemById" parameterType="list" resultMap="dataItemResult">
selete * from where d_menu_id=#{id}
</select>
返回 List 的集合
resultType="java.util.Map"
