Map<String,Object> map=new HashMap<String,Object>(); map.put("start",Integer.parseInt(page)); map.put("size", 3); map.put("userName","%李%");
<!-- choose(判断参数) - 按顺序将实体类 User 第一个不为空的属性作为:where条件 --> <select id="getUserList_choose" resultMap="resultMap_user" parameterType="com.yiibai.pojo.User"> SELECT * FROM User u <where> <choose> <when test="username !=null "> u.username LIKE CONCAT(CONCAT('%', #{username, jdbcType=VARCHAR}),'%') </when > <when test="sex != null and sex != '' "> AND u.sex = #{sex, jdbcType=INTEGER} </when > <when test="birthday != null "> AND u.birthday = #{birthday, jdbcType=DATE} </when > <otherwise> </otherwise> </choose> </where></select>
<select id="dynamicChooseTest" parameterType="Blog" resultType="Blog"> select * from t_blog where 1 = 1 <choose> <when test="title != null"> and title = #{title} </when> <when test="content != null"> and content = #{content} </when> <otherwise> and owner = "owner1" </otherwise> </choose> </select><select id="find" parameterType="Map" resultMap="UserResult">
select * from t_user
<if test="start!=null and size!=null">
limit #{start},#{size}
</if>
</select>
<select id="find2" parameterType="Map" resultMap="UserResult">
select * from t_user
<where> <!-- 自动加上where -->
<choose>
<when test="userName!=null">
and userName like #{userName}
</when>
<otherwise>
</otherwise>
</choose>
</where>
</select>