resultMap的使用(当数据库表的字段名和pojo的属性名不同时,查询结果为空)
<resultMap type="order" id="order_list_map">
<!-- 主键映射 -->
<id property="id" column="id" />
<!-- 其他属性映射 -->
<result property="userId" column="user_id"/>
<result property="number" column="number"/>
<result property="createtime" column="createtime"/>
<result property="note" column="note"/>
</resultMap>
<select id="getOrderListMap" resultMap="order_list_map">
select * from `order`
</select>
动态SQL
if标签
<if test="username != null and username != ''">
and username like '%${username}%'
</if>
<if test="sex != null and sex != ''">
and sex = #{sex}
</if>
where标签
select * from user
<where>
<if test="username != null and username != ''">
and username like '%${username}%'
</if>
<if test="sex != null and sex != ''">
and sex = #{sex}
</if>
</where>
sql片段
<!-- sql片段 -->
<sql id="user_sql">
select * from `user`
</sql>
<select id="testsql">
<!-- 引入sql片段 -->
<include refid="user_sql"></include>
</select>