xml文件
<settings>
<setting name="logImpl" value="STDOUT_LOGGING"/>
<!-- 是否开启驼峰命名自动映射,即从经典数据库列名 A_COLUMN 映射到经典 Java 属性名 aColumn-->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<typeAliases>
<typeAlias type="com.yao.pojo.Blog" alias="Blog"/>
<!-- 通过包-->
<!-- <package name="com.yao.pojo"/>-->
</typeAliases>
public interface BlogMapper {
//插入数据
int addBlog(Blog blog);
//查询博客
List<Blog> queryBlogIf(Map map);
List<Blog> queryBlogChoose(Map map);
//更新
int updateBlog(Map map);
}
================
<select id="queryBlogIf" parameterType="Map" resultType="blog">
select * from blog where 1=1
<if test="title!=null">
and title=#{title}
</if>
<if test="author!=null">
and title=#{author}
</if>
</select>
<select id="queryBlogChoose" parameterType="map" resultType="blog">
select * from blog
<where>
<choose>
<when test="title!=null">
title=#{title}
</when>
<when test="author!=null">
and author=#{author}
</when>
<otherwise>
and views=#{views}
</otherwise>
</choose>
</where>
</select>
<update id="updateBlog" parameterType="map">
update blog
<set>
<if test="title!=null">
title=#{title},
</if>
<if test="author!=null">
author=#{author}
</if>
</set>
where id=#{id}
</update>
原文:https://www.cnblogs.com/yyyyyou/p/14614442.html