resultMap元素
是mybatis中高级查询映射的一个元素,当表中字段名与pojo类中的属性不同,或者是多表查询,嵌套查询一般都会使用resultMap元素进行自定义映射。
mysql中也可以对共性部分进行封装
sql这个元素可以用来定义可重用的 SQL 代码片段,以便在其它语句中使用。 参数可以静态地(在加载的时候)确定下来,并且可以在不同的 include 元素中定义不同的参数值。比如:
<sql id="queryWhereId">
from sys_logs
<where>
<if test="username!=''and username!=null">username like concat("%", #{username}, "%")</if>
</where>
</sql>
这个 SQL 片段可以在其它语句中使用,例如:
<select id="getRowCount" resultType="int">
select count(*)
<include refid="queryWhereId"></include>
</select>
useGeneratedKeys和keyProperty的使用
<!--useGeneratedKeys表示要使用自增的主键值
keyProperty表示要将自增主键值赋值给参数对象的id属性
-->
<insert id="insertObject" parameterType="com.cy.pj.sys.pojo.SysRole" keyProperty="id" useGeneratedKeys="true">
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。