前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >tkmapper mybatis plus 集成_gitea docker

tkmapper mybatis plus 集成_gitea docker

作者头像
全栈程序员站长
发布2022-11-08 17:29:04
2740
发布2022-11-08 17:29:04
举报
文章被收录于专栏:全栈程序员必看

spring boot 配置文件

#数据库配置

spring.datasource.url=jdbc:mysql://ip地址:3306/dcpp?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull spring.datasource.username=root spring.datasource.password=123456 spring.datasource.driver-class-name=com.mysql.jdbc.Driver

#mybatisMapper #mybatis映射地址 mybatis.type-aliases-package=com.core.entity mybatis.mapper-locations=classpath:mapper/*.xml #TkMapper地址 mapper.mappers=com.common.core.tkMapper.TkMapper mapper.identity=MYSQL

#分页助手 pagehelper.helperDialect=mysql pagehelper.reasonable=true pagehelper.supportMethodsArguments=true

pagehelper.params=count=countSql

———————————————————————————————————————————-

一、设置TkMapper单独放在一个包:这个包只有TkMapper一个文件

import tk.mybatis.mapper.common.Mapper;

import tk.mybatis.mapper.common.MySqlMapper;

public interface TkMapper<T> extends Mapper<T>, MySqlMapper<T> {

}

二、继承TkMapper使用

public interface TestMapper extends TkMapper<TestBean>{

}

TestBean :

import javax.persistence.Column; import javax.persistence.Id; import javax.persistence.Table; @Table(name = “表名”) public class TestBean{ //主键自动驼峰映射 @Id //主键ID 表中字段 test_id private String testId; @Id //主键ID 表中字段 test_no private String testNo; @Column(name = “name_no”) private String nameNo; get/set }

三、在启动类添加扫描TestMapper

TestMapper包路径

@MapperScan(basePackages = { “xx.xx.xx” })

四、使用

@Autowired private TestMapper mapper;

mapper.方法

等号的CRUD: * List<T> select(T record); 根据实体中的属性值进行查询,查询条件使用等号 * T selectByPrimaryKey(Object key); 根据主键字段进行查询,方法参数必须包含完整的主键属性,查询条件使用等号 * List<T> selectAll(); 查询全部结果,select(null)方法能达到同样的效果 * T selectOne(T record); 根据实体中的属性进行查询,只能有一个返回值,有多个结果是抛出异常,查询条件使用等号 * int selectCount(T record); 根据实体中的属性查询总数,查询条件使用等号 * int insert(T record); 保存一个实体,null的属性也会保存,不会使用数据库默认值 * int insertSelective(T record); 保存一个实体,null的属性不会保存,会使用数据库默认值 * int updateByPrimaryKey(T record); 根据主键更新实体全部字段,null值会被更新 * int updateByPrimaryKeySelective(T record); 根据主键更新属性不为null的值 * int delete(T record); 根据实体属性作为条件进行删除,查询条件使用等号 * int deleteByPrimaryKey(Object key); 根据主键字段进行删除,方法参数必须包含完整的主键属性 * * 条件的CRUD: * List<T> selectByCondition(Object condition); 根据Condition条件进行查询 * int selectCountByCondition(Object condition); 根据Condition条件进行查询总数 * int updateByCondition(@Param(“record”) T record, @Param(“example”) Object condition); 根据Condition条件更新实体record包含的全部属性,null值会被更新 * int updateByConditionSelective(@Param(“record”) T record, @Param(“example”) Object condition); 根据Condition条件更新实体record包含的不是null的属性值

* int deleteByCondition(Object condition); 根据Condition条件删除数据

五、带条件的SQL:

Example example = new Example(TransDetailEntity.class); example.createCriteria().andLike(“datetime”, “%2018-05-20%”).andEqualTo(“direct”, “1”);

transList = mapper.selectByExample(example);

六、自定义SQL:

public interface TestMapper extends TkMapper<TestBean>{ //传入一个参数 @Select(” sql语句 where name= #{name} “) TestBean findExchRela(@Param(“name”) String name); //传入bean @Select(” sql语句 where name= #{name} “) TestBean findExchRela(TestBean testBean);

}

七、POM

<!– mybatis –> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>2.0.0</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.3</version> </dependency>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/185097.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年10月7日 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档