One, the additional configuration in the XML configuration version 1.properties file: Mybatis.config-locations=classpath:mybatis/mybatis-config.xml Mybatis.mapper-locations=classpath:mybatis/mapper/*.xml2.mybatis-config.xml file configuration mapper file inside the Jdbctype rename
<configuration> <typeAliases> <typealias alias="Integer"Type="Java.lang.Integer"/> <typealias alias="Long"Type="Java.lang.Long"/> <typealias alias="HashMap"Type="Java.util.HashMap"/> <typealias alias="Linkedhashmap"Type="Java.util.LinkedHashMap"/> <typealias alias="ArrayList"Type="java.util.ArrayList"/> <typealias alias="LinkedList"Type="java.util.LinkedList"/> </typeAliases> </configuration>
3. Add the user's mapping file
<?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.neo.mapper.UserMapper" >
<resultmap id= "Baseresultmap" type= "com.neo.entity.UserEntity" > <id column= "id" property= "id" jdbctype= "BIG INT "/> <result column=" userName "property=" UserName "jdbctype=" VARCHAR "/> <result column=" PassWord " Property= "PassWord" jdbctype= "VARCHAR"/> <result column= "user_sex" property= "Usersex" javatype= "com.neo.enums . Usersexenum "/> <result column=" Nick_name "property=" nickname "jdbctype=" VARCHAR "/> </resultMap> < SQL id= "base_column_list" > ID, UserName, PassWord, User_sex, nick_name </sql> <select id= "GetAll" resultmap= "Baseresultmap" > select <include refid= "Base_column_list"/> from users </select> <select id= "GetOne" Parametertype= "Java.lang.Long" resultmap= "Baseresultmap" >SELECT<include refid= "Base_column_list"/> from users WHERE id = #{id} </select> <insert id= "Insert" Parametertyp E= "Com.neo.entity.UserEntity" > INSERT into Users (username,password,user_sex) VALUES (#{username}, #{password}, #{ Usersex}) </insert> <update id= "Update" parametertype= "com.neo.entity.UserEntity" > Update users SET
<ifTest= "UserName! = null" >username = #{username},</if>
<ifTest= "PassWord! = null" >password = #{password},</if>
Nick_name = #{nickname} WHERE id = #{id}
</update>
<delete id= "Delete" parametertype= "Java.lang.Long" >
DELETE from users WHERE ID =#{id}
</delete>
</mapper>
interface of the 4.dao layer
Public Interface usermapper { List<UserEntity> getAll (); Userentity GetOne (Long ID); void Insert (userentity user); void Update (userentity user); void Delete (Long id);}
5. Unit test: See Annotated mode integration MyBatis Case 6. Problems that may occur:
solutions;
Spring boot simple XML configuration Integration MyBatis