栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

MybatisPlus相关个人笔记

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

MybatisPlus相关个人笔记

Mybatis与MybatisPlus整合 Mapper继承baseMapper,就拥有了baseMapper中的所有方法 相关配置 SpringBoot配置文件参考
spring.application.name=itcast-mp-springboot
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/mp?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=123

# 指定全局配置文件
mybatis-plus.config-location=classpath:mybatis-config.xml
# 指定mapper.xml文件的路径
mybatis-plus.mapper-locations= classpath*:mybatis/*.xml
# 实体对象扫描包
mybatis-plus.type-aliases-package= cn.itcast.mp.pojo
# 关闭自动驼峰映射,该参数不能和mybatis-plus.config-location同时存在 可以配置到mybatis-config.xml里边
#mybatis-plus.configuration.map-underscore-to-camel-case=false
# 是否禁用缓存
mybatis-plus.configuration.cache-enabled=false
# 全局id策略
mybatis-plus.global-config.db-config.id-type=auto
# 全局的表明的前缀
mybatis-plus.global-config.db-config.table-prefix=tb_
SpringBoot配置类配置分页器
@Configuration
@MapperScan("cn.itcast.mp.mapper") //设置mapper接口的扫描包
public class MybatisPlusConfig {

    @Bean //配置分页插件
    public PaginationInterceptor paginationInterceptor(){
        return new PaginationInterceptor();
    }

}
在Mybatis-config.xml文件中配置分页器
 

    
    
        
    
POJO类相关注释
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("tb_user")
public class User {
    @TableId(type = IdType.AUTO)
    private Long id;
    private String userName;
    @TableField(select = false) //查询时不反回该字段的值
    private String password;
    private String name;
    private Integer age;
    @TableField(value = "email") //指定数据库字段名映射
    private String mail;
    @TableField(exist = false)
    private String address; //在数据库表中不存在
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/337771.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号