增加

1
2
3
<insert id="add" parameterType="BlogType">
insert into t_blogtype (name, sortNum) values (#{name},#{sortNum});
</insert>

删除

1
2
3
<delete id="delete" parameterType="integer">
delete from t_blogtype where id=#{id}
</delete>

修改

1
2
3
4
5
6
7
8
9
10
11
12
<update id="update" parameterType="BlogType">
update t_blogtype
<set>
<if test="name != null and name != ''">
name=#{name},
</if>
<if test="sortNum != null">
sortNum=#{sortNum},
</if>
</set>
where id=#{id}
</update>

查询

1
2
3
<select id="findById" parameterType="integer" resultMap="BlogTypeResult">
select * from t_blogtype where id=#{id}
</select>

PS.

相关元素查看博客:mybatis的元素属性