MP教程-配置

配置

一、Mybatis原生配置

  • application.properties


mybatis-plus.config-location=classpath:mybatis.xml

 

  • mybatis.xml


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
</configuration>

 

 

二、使用Mybatis的原生Mapper配置

  • application.properties

    
    
    mybatis-plus.mapper-locations=classpath*:mybatis/*.xml

     

  • UserMapper.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.will.learn.springboot.mapper.UserMapper">
      <select id="selById" resultType="com.will.learn.springboot.pojo.User">
        select * from tb_user where id = #{id}
      </select>
    </mapper>

     

三、进阶配置

  • MyBatis别名包扫名路径配置


mybatis-plus.type-aliases-package = com.will.learn.springboot.pojo

 

  • DB策略配置(IdType)


mybatis-plus.global-config.db-config.id-type=auto

 

  • DB策略配置(tablePrefix)


mybatis-plus.global-config.db-config.table-prefix=tb_

 

posted on 2020-03-28 21:27  DeeperMiner  阅读(341)  评论(0编辑  收藏  举报

导航