- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="test">
- <insert id="insertUser" parameterType="dancheng.mybatis.po.User">
- <!--
- keyProperty:将查询出的主键设置到parameterType中的哪个属性上
- order:相对于sql语句的执行顺序
- resultType:指定返回值类型
- LAST_INSERT_ID():获取ID函数
- -->
- <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
- SELECT LAST_INSERT_ID()
- </selectKey>
- insert into user(username,birthday,sex,address) value(#{username},#{birthday},#{sex},#{address})
- </insert>
- </mapper>
- <mapper namespace="test">
- <insert id="insertUser" parameterType="dancheng.mybatis.po.User">
- <!--
- keyProperty:将查询出的主键设置到parameterType中的哪个属性上
- order:相对于sql语句的执行顺序
- resultType:指定返回值类型
- LAST_INSERT_ID():获取ID函数
- -->
- <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.String">
- SELECT uuid()
- </selectKey>
- insert into user(id,username,birthday,sex,address) value(#{id}.#{username},#{birthday},#{sex},#{address})
- </insert>
- </mapper>