File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 7
7
当前项目没有直接提供可用的通用方法,方法在 ** mybatis-mapper/mapper** ( [ gitee] ( https://gitee.com/mybatis-mapper/mapper )
8
8
| [ GitHub] ( https://github.com/mybatis-mapper/mapper ) )中提供。
9
9
10
+ 注解详细使用文档: [ https://mapper.mybatis.io/docs/v2.x/3.1.entity.html ] ( https://mapper.mybatis.io/docs/v2.x/3.1.entity.html )
11
+
10
12
## 注解
11
13
12
14
核心提供了一套实体类的注解,简单示例如下:
13
15
14
16
``` java
15
17
18
+ @Entity.Table (" sys_user" )
19
+ public class User {
20
+ @Entity.Column (id = true , useGeneratedKeys = true )
21
+ private Long id;
22
+ private String name;
23
+ private boolean admin;
24
+ private Integer seq;
25
+ private Double points;
26
+ private String password;
27
+ private Date whenCreated;
28
+ private String info;
29
+ private String noEntityColumn;
30
+ }
31
+ ```
32
+
33
+ 2.x 版本默认将所有字段映射为表字段,使用驼峰转小写下划线方式,还可以像下面这样给所有字段加注解:
34
+ ``` java
16
35
@Entity.Table (value = " user" )
17
36
public class User {
18
37
@Entity.Column (id = true )
@@ -80,13 +99,12 @@ class DemoProvider {
80
99
81
100
` SqlScript.caching ` 会缓存拼接 SQL 的 lambda 方法,并且返回方法的 id。
82
101
83
- > ** 特别注意,这里返回的不是 sql,而且缓存 SQL 后的 key**
102
+ > ** 特别注意,这里返回的不是 sql,而且缓存 SQL 后的 key**
84
103
> key值形式如:` io.mybatis.mapper.UserMapper.deleteByPrimaryKey ` 。
85
104
86
105
上面方法在执行时,最终拼接的 SQL 示例如下:
87
106
88
107
``` xml
89
-
90
108
<script >
91
109
DELETE FROM user WHERE id = #{id}
92
110
</script >
@@ -230,4 +248,4 @@ class DemoMapper<T> {
230
248
@SelectProvider (type = EntityProvider . class, method = " selectByPrimaryKey" )
231
249
Optional<T > selectByPrimaryKey (I id );
232
250
}
233
- ```
251
+ ```
Original file line number Diff line number Diff line change 22
22
23
23
<groupId >io.mybatis</groupId >
24
24
<artifactId >mybatis-provider</artifactId >
25
- <version >2.2.5-SNAPSHOT </version >
25
+ <version >2.2.5</version >
26
26
27
27
<name >MyBatis Provider</name >
28
28
<description >MyBatis Provider 扩展</description >
You can’t perform that action at this time.
0 commit comments