当前位置:网站首页>Use mapper: --- tkmapper
Use mapper: --- tkmapper
2022-07-05 23:39:00 【Chen Hu_ sixty-three】
Introduce dependencies :
Import dependence
<!--tkMapper Integrate mybatis+SpringBoot-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.1.5</version>
</dependency>
<!--tkMapper Integrate mybatis-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>3.1.2</version>
</dependency>
To configure :
One 、 Set up TkMapper and GukeMapper Put it in a bag
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;
public interface TkMapper<T> extends Mapper<T>, MySqlMapper<T> {
}
GukeMapper Inherit TkMapper Use
public interface GukeMapper extends TkMapper<Guke>{
}
Database corresponds to entity class :
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
@Table(name = " Table name ")
public class Guke{
// Primary key automatic hump mapping
@Id // Primary key ID Fields in the table test_id
// @GeneratedValue(strategy = GenerationType.AUTO)// Automatically switch the primary key generation strategy according to the underlying database
@GeneratedValue(strategy = GenerationType.IDENTITY)// Use mysql The primary key generation strategy of
// @GeneratedValue(strategy = GenerationType.SEQUENCE)// Use Oracle The primary key generation strategy of
private Integer id;
private String testId;
@Id // Primary key ID Fields in the table test_no
private String testNo;
@Column(name = "name_no")
private String nameNo;
get/set
}
Four 、 Add scanning in the startup class TestMapper
@tk.mybatis.spring.annotation.MapperScan("com.swhysc.mapper.*")
Common methods and precautions :
public interface BaseMapper<T> extends tk.mybatis.mapper.common.BaseMapper<T>, IdsMapper<T>, MySqlMapper<T>, OracleMapper<T> {
}
notes : For demonstration, we also quote MySqlMapper and OracleMapper Normally, only one method can be cited because they have the same method insertList(List list), When using, it will report errors
Generic ( Entity class ) The type of must meet the requirements
Entity classes are converted to database tables according to the following rules , Notes are all JPA The annotations in :
- The table name uses the class name by default , Hump underline ( Only uppercase letters are processed ), Such as UserInfo The default corresponding table name is user_info.
- The table name can use @Table(name = “tableName”) Make a designation , For those that do not conform to the first default rule, you can specify the table name in this way .
- Fields default to and @Column equally , Will be used as table fields , The table field defaults to Java Object's Field Name hump to underline .
- have access to @Column(name = “fieldName”) The designation does not conform to article 3 Field name of rule .
- Use @Transient Annotations can ignore fields , Fields with this annotation will not be used as table fields .
- The suggestion must be that there is one @Id Annotate the field as the primary key , There can be multiple @Id Annotated fields are used as joint primary keys .
- // Primary key automatic hump mapping
@Id // Primary key ID Fields in the table test_id
// @GeneratedValue(strategy = GenerationType.AUTO)// Automatically switch the primary key generation strategy according to the underlying database
@GeneratedValue(strategy = GenerationType.IDENTITY)// Use mysql The primary key generation strategy of
// @GeneratedValue(strategy = GenerationType.SEQUENCE)// Use Oracle The primary key generation strategy of
private Integer id;
be-all mapper Inheriting this class will have the following general methods
Query methods
BaseSelectMapper General method under
| Method name | effect |
|---|---|
| List selectAll(); | Query all data |
| oolean existsWithPrimaryKey(Object key); | Query whether this primary key exists through the primary key |
| T selectByPrimaryKey(Object key); | Query by primary key |
| – | – |
| T selectOne(T record); | Query single data through entities |
| – | – |
| List select(T record); | Query multiple data through entities |
| – | – |
| int selectCount(T record); | Query the number of entities through entities |
SelectByIdsMapper General method under
| Method name | effect |
|---|---|
| List selectByIds(String var1); | Query data through multiple primary keys |


边栏推荐
- TVS管和ESD管的技术指标和选型指南-嘉立创推荐
- yate. conf
- UVA – 11637 garbage remembering exam (combination + possibility)
- ts类型声明declare
- 保研笔记一 软件工程与计算卷二(1-7章)
- Technical specifications and model selection guidelines for TVs tubes and ESD tubes - recommended by jialichuang
- 15 MySQL-存储过程与函数
- 21.PWM应用编程
- 4 points tell you the advantages of the combination of real-time chat and chat robots
- Code farmers to improve productivity
猜你喜欢

开源crm客户关系统管理系统源码,免费分享

GFS分布式文件系統

Rasa 3.x 学习系列-Rasa 3.2.1 新版本发布

20. Migrate freetype font library

《牛客刷verilog》Part III Verilog企业真题

TVS管和ESD管的技术指标和选型指南-嘉立创推荐

98. 验证二叉搜索树 ●●

Comparison of parameters between TVs tube and zener diode

Xinyuan & Lichuang EDA training camp - brushless motor drive

TVS管和ESD管的技術指標和選型指南-嘉立創推薦
随机推荐
4 points tell you the advantages of the combination of real-time chat and chat robots
VS2010 writes DLL and unit test of dynamic link library, and transfers the correctness of DLL test
Switching power supply buck circuit CCM and DCM working mode
There are 14 God note taking methods. Just choose one move to improve your learning and work efficiency by 100 times!
VS2010编写动态链接库DLL和单元测试,转让DLL测试的正确性
[original] what is the core of programmer team management?
Attacking technology Er - Automation
How to design API return code (error code)?
STM32__ 06 - single channel ADC
数学公式截图识别神器Mathpix无限使用教程
How to insert data into MySQL database- How can I insert data into a MySQL database?
3: Chapter 1: understanding JVM specification 2: JVM specification, introduction;
【原创】程序员团队管理的核心是什么?
It is proved that POJ 1014 module is optimized and pruned, and some recursion is wrong
AsyncSocket长连接棒包装问题解决
From the perspective of quantitative genetics, why do you get the bride price when you get married
(4) UART application design and simulation verification 2 - TX module design (stateless machine)
UVA11294-Wedding(2-SAT)
(4)UART应用设计及仿真验证2 —— RX模块设计(无状态机)
ts类型声明declare