工程结构
pom.xml
springboot-demo cn.xiaojf 1.0-SNAPSHOT 4.0.0 UTF-8 1.8 1.8 springboot-mybatis-plus org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-freemarker com.baomidou mybatis-plus 2.1.7 com.baomidou mybatisplus-spring-boot-starter 1.0.5 mysql mysql-connector-java 5.1.45
application.properties
#应用端口号server.port=8010#freemarker 默认文件后缀spring.freemarker.suffix=.html#数据库设置spring.datasource.driverClassName=com.mysql.jdbc.Driverspring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8spring.datasource.username=rootspring.datasource.password=root#mybatis plus 设置mybatis-plus.mapper-locations=classpath:/mapper/*Mapper.xml#实体扫描,多个package用逗号或者分号分隔mybatis-plus.typeAliasesPackage=cn.xiaojf.springboot.mybatisplus.entity#主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";mybatis-plus.global-config.id-type=2#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"mybatis-plus.global-config.field-strategy=2#驼峰下划线转换mybatis-plus.global-config.db-column-underline=true#刷新mapper 调试神器mybatis-plus.global-config.refresh-mapper=true#数据库大写下划线转换#mybatis-plus.global-config.capital-mode=true#序列接口实现类配置#mybatis-plus.global-config.key-generator=com.baomidou.springboot.xxx#逻辑删除配置mybatis-plus.global-config.logic-delete-value=0mybatis-plus.global-config.logic-not-delete-value=1#自定义填充策略接口实现#mybatis-plus.global-config.meta-object-handler=com.baomidou.springboot.xxx#自定义SQL注入器#mybatis-plus.global-config.sql-injector=com.baomidou.springboot.xxxmybatis-plus.configuration.map-underscore-to-camel-case=truemybatis-plus.configuration.cache-enabled=false
MybatisPlusConfig.java
package cn.xiaojf.springboot.mybatisplus.configure;import org.mybatis.spring.annotation.MapperScan;import org.springframework.context.annotation.Configuration;@Configuration@MapperScan("cn.xiaojf.springboot.mybatisplus.mapper*")public class MybatisPlusConfig {}
UserMapper.java
package cn.xiaojf.springboot.mybatisplus.mapper;import cn.xiaojf.springboot.mybatisplus.SuperMapper;import cn.xiaojf.springboot.mybatisplus.entity.User;import java.util.List;public interface UserMapper extends SuperMapper{ List findByUserName(String name); User findUserAddrByName(String name);}
UserMapper.xml
源码
https://gitee.com/xiaojf/springboot-demo/tree/master/springboot-mybatis-plus