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 77当前项目没有直接提供可用的通用方法,方法在 ** mybatis-mapper/mapper** ( [ gitee] ( https://gitee.com/mybatis-mapper/mapper )
88| [ GitHub] ( https://github.com/mybatis-mapper/mapper ) )中提供。
99
10+ 注解详细使用文档: [ https://mapper.mybatis.io/docs/v2.x/3.1.entity.html ] ( https://mapper.mybatis.io/docs/v2.x/3.1.entity.html )
11+
1012## 注解
1113
1214核心提供了一套实体类的注解,简单示例如下:
1315
1416``` java
1517
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
1635@Entity.Table (value = " user" )
1736public class User {
1837 @Entity.Column (id = true )
@@ -80,13 +99,12 @@ class DemoProvider {
8099
81100` SqlScript.caching ` 会缓存拼接 SQL 的 lambda 方法,并且返回方法的 id。
82101
83- > ** 特别注意,这里返回的不是 sql,而且缓存 SQL 后的 key**
102+ > ** 特别注意,这里返回的不是 sql,而且缓存 SQL 后的 key**
84103> key值形式如:` io.mybatis.mapper.UserMapper.deleteByPrimaryKey ` 。
85104
86105上面方法在执行时,最终拼接的 SQL 示例如下:
87106
88107``` xml
89-
90108<script >
91109 DELETE FROM user WHERE id = #{id}
92110</script >
@@ -230,4 +248,4 @@ class DemoMapper<T> {
230248 @SelectProvider (type = EntityProvider . class, method = " selectByPrimaryKey" )
231249 Optional<T > selectByPrimaryKey (I id );
232250}
233- ```
251+ ```
Original file line number Diff line number Diff line change 2222
2323 <groupId >io.mybatis</groupId >
2424 <artifactId >mybatis-provider</artifactId >
25- <version >2.2.5-SNAPSHOT </version >
25+ <version >2.2.5</version >
2626
2727 <name >MyBatis Provider</name >
2828 <description >MyBatis Provider 扩展</description >
You can’t perform that action at this time.
0 commit comments