Spring boot simple XML configuration Integration MyBatis

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.