上源码
TestMapper.xml
<?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="com.example.demo.dao.TestMapper"> <resultMap id="BaseResultMap" type="com.example.demo.entry.Test"> <id column="id" jdbcType="VARCHAR" property="id" /> <result column="name" jdbcType="VARCHAR" property="name" /> </resultMap> <insert id="insert"> <selectKey keyProperty="id" resultType="java.lang.String" order="BEFORE"> SELECT uuid() </selectKey> insert into test (id,name) values(#{id},#{name}); </insert> </mapper>
上面红色要注意的,其他和平时差不多,id的话是在Test类里面id属性。select uuid()直接生成uuid
TestMapper.java
package com.example.demo.dao; import com.example.demo.entry.Test; /** * @program: demo * @description * @author: dajitui * @create: 2018-06-16 11:52 **/ public interface TestMapper { int insert(Test test); }
然后单元测试,注入mapper应该简单的。