当前位置:网站首页>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 |


边栏推荐
- 424. The longest repeated character after replacement ●●
- 【LeetCode】5. Valid palindrome
- Go language introduction detailed tutorial (I): go language in the era
- 3: Chapter 1: understanding JVM specification 2: JVM specification, introduction;
- QCombox(重写)+QCompleter(自动补全,自动加载qcombox的下拉选项,设置背景颜色)
- Live tiktok shop 2022 latest gameplay card slot overseas live e-commerce new traffic
- LeetCode——Add Binary
- Huawei simulator ENSP - hcip - MPLS experiment
- UVA11294-Wedding(2-SAT)
- VS2010编写动态链接库DLL和单元测试,转让DLL测试的正确性
猜你喜欢

CIS基准测试工具kube-bench使用

2: Chapter 1: understanding JVM specification 1: introduction to JVM;

成为程序员的你,后悔了吗?

Dynamic memory management (malloc/calloc/realloc)

Technical specifications and model selection guidelines for TVs tubes and ESD tubes - recommended by jialichuang

98. 验证二叉搜索树 ●●

98. Verify the binary search tree ●●

GFS分布式文件系統

698. Divided into k equal subsets ●●

开关电源Buck电路CCM及DCM工作模式
随机推荐
2022.6.20-6.26 AI industry weekly (issue 103): new little life
VS2010 writes DLL and unit test of dynamic link library, and transfers the correctness of DLL test
Do you regret becoming a programmer?
C# 反射与Type
TVS管和ESD管的技術指標和選型指南-嘉立創推薦
When to use useImperativeHandle, useLayoutEffect, and useDebugValue
Practice of concurrent search
GFS Distributed File System
yate. conf
Spire Office 7.5.4 for NET
Multi camera stereo calibration
There are 14 God note taking methods. Just choose one move to improve your learning and work efficiency by 100 times!
Attacking technology Er - Automation
11gR2 Database Services for &quot; Policy&quot; and &quot; Administrator&quot; Managed databases (file I
Xinyuan & Lichuang EDA training camp - brushless motor drive
【经典控制理论】自控实验总结
Mathematical formula screenshot recognition artifact mathpix unlimited use tutorial
Leetcode sword finger offer brush questions - day 21
Fiddler Everywhere 3.2.1 Crack
C# 文件与文件夹操作