版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文章只是mybatis的一些判断使用案例。
1.关于封装map使用
<!-- map封装 -->
<!--<resultMap id="UserResultMap" type="map">
<id property="id" column="id" />
<result property="userName" column="user_name" />
</resultMap>
<select id="getUserMap" resultMap="UserResultMap">
select id,user_name from user_t where id = #{id}
</select>-->
2.关于case when else end的使用
<select id="findStudentAll" resultType="com.example.demo.model.Student"> select a.id, a.name, (case a.sex when 1 then '男' when 0 then '女' else '空的' end )sex from student_t a </select>
3.关于查询返回值判断问题
<select id="getById" resultType="com.example.demo.model.Student"> select a.id, a.name, IF(a.sex IS NULL,'你都没性别',a.sex) sex from student_t a where id = '4' </select>
4.字符串的拼接使用
<select id="findConcatAll" resultType="com.example.demo.model.Student"> select a.id, a.name, concat('老家是',a.adress) adress from student_t a </select>