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


边栏推荐
- 保研笔记四 软件工程与计算卷二(8-12章)
- Attacking technology Er - Automation
- Fiddler Everywhere 3.2.1 Crack
- Spire.PDF for NET 8.7.2
- Fiddler Everywhere 3.2.1 Crack
- JVM的简介
- grafana工具界面显示报错influxDB Error
- Switching power supply buck circuit CCM and DCM working mode
- Dynamic memory management (malloc/calloc/realloc)
- MySQL (1) -- related concepts, SQL classification, and simple operations
猜你喜欢

98. 验证二叉搜索树 ●●

GFS Distributed File System

Creative mode 1 - single case mode

Fiddler Everywhere 3.2.1 Crack

Research notes I software engineering and calculation volume II (Chapter 1-7)

Fiddler Everywhere 3.2.1 Crack

【经典控制理论】自控实验总结

TVS管 与 稳压二极管参数对比

Scala concurrent programming (II) akka

Neural structured learning 4 antagonistic learning for image classification
随机推荐
Rsync remote synchronization
MySQL replace primary key delete primary key add primary key
ts类型声明declare
yate. conf
Spire.PDF for NET 8.7.2
Solution to the packaging problem of asyncsocket long connecting rod
TVS管 与 稳压二极管参数对比
The PNG image is normal when LabVIEW is opened, and the full black image is obtained when Photoshop is opened
idea 连接mysql ,直接贴配置文件的url 比较方便
Spécifications techniques et lignes directrices pour la sélection des tubes TVS et ESD - Recommandation de jialichuang
(4)UART應用設計及仿真驗證2 —— TX模塊設計(無狀態機)
Summary of binary tree recursive routines
Rasa 3. X learning series -rasa 3.2.1 new release
GFS分布式文件系統
UVA – 11637 Garbage Remembering Exam (组合+可能性)
如何获取localStorage中存储的所有值
Rasa 3.x 学习系列-Rasa X 社区版(免费版) 更改
Go language introduction detailed tutorial (I): go language in the era
Creative mode 1 - single case mode
How to improve eloquence