tkmapper mybatis plus 集成_gitea docker

tkmapper mybatis plus 集成_gitea docker———————————————————————————————————————————-一、设置TkMapper单独放在一个包:这个包只有TkMapper一个文件importtk.mybatis.mapper.common.M…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

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.net/185097.html原文链接:https://javaforall.net

(0)
上一篇 2022年10月7日 上午6:46
下一篇 2022年10月7日 上午6:46


相关推荐

  • 无人驾驶感知篇之超声波雷达

    无人驾驶感知篇之超声波雷达昨天上海又新增了快六千多例,早上醒来的第一眼都很关注,这个时候,在想如果无人驾驶送餐车在各个街道行驶送餐那该多好,希望这一天能早点到来,让无人驾驶遍布咱们生活的每个角落。OK,言归正传,首先讲讲什么是超声波雷达。1.什么是超声波雷达安装在汽车周边的超声波雷达,主要用于倒车时的防撞报警系统,又俗称倒车雷达。超声波是一种在弹性介质中的机械振荡,纵向分辨率较高,对色彩、光照、电磁场不敏感,因此超声波测距系统对于黑暗,有灰尘或者烟幕、有毒等恶劣环境有很强的适应能力。超声波测距…

    2025年10月27日
    4
  • 薪资涨幅30% 怎么算(如何把自己的薪资提高)

    列出薪金高于在部门30bySamWilliams通过山姆·威廉姆斯我如何在五个月内将薪金提高一倍并获得一份了不起的工作(HowIDoubledmySalaryinFiveMonthsandGotanAmazingJob)SixmonthsagoIquitmyjobasajuniorJavaScriptdeveloperandtrav…

    2022年4月15日
    116
  • SPSS 性别卡方分析[通俗易懂]

    SPSS 性别卡方分析[通俗易懂]1.新建数据集2.打开变量视图,分别输出group、sex和number其中标签是对数据的说明,值是spss中的显示,比如定义1=subject,则输入1就等价于subject变量视图:数据视图:3.数据分析:点击数据–个案加权–将人数加入个案加权系数否则结果一般有误4.卡方检验分析–描述统计–交叉表–统计–卡方检验确定结果输出:…

    2022年5月16日
    100
  • c语言中图书管理系统_c语言图书管理系统排序

    c语言中图书管理系统_c语言图书管理系统排序课件C语言图书管理系统代码#include#include#includestructbook{intnum;charbname[50];charwname[20];charpress[50];charsort[50];inttime;floatprice;structbook*next;};structbook*creatbook();…

    2022年8月31日
    7
  • 有组织纠缠之OpenClaw一个奥地利的间谍智能体

    有组织纠缠之OpenClaw一个奥地利的间谍智能体

    2026年3月14日
    2
  • 蚂蚁金服通信框架SOFABolt解析 | 连接管理剖析

    蚂蚁金服通信框架SOFABolt解析 | 连接管理剖析

    2021年6月18日
    143

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号