Skip to content

Commit 993faf9

Browse files
committed
更新测试和文档,版本号变更为0.2.0
1 parent 3a2d4d6 commit 993faf9

File tree

7 files changed

+59
-34
lines changed

7 files changed

+59
-34
lines changed

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ Mybatis工具群: 211286137 (Mybatis相关工具插件等等)
2424

2525
推荐使用Mybatis分页插件:[PageHelper分页插件](https://github.com/pagehelper/Mybatis-PageHelper)
2626

27+
##v0.2.0版本说明
28+
29+
该版本做了大量的重构,在原有基础上增加了两个类,分别为`MapperTemplate``MapperProvider`,其他几个类都有相当大的改动。
30+
31+
**但是**,这次重构并不影响原有的业务代码。
32+
33+
这次重构的目的是为了方便开发者自行扩展,增加自己需要的通用Mapper。这次重构后,扩展变的更容易。稍后会写一篇**如何进行扩展**的文档。
34+
35+
这次更新还修复Oracle序列的BUG。
36+
2737
##如何使用?
2838

2939
下面是通用Mapper的配置方法,还会提到Spring中的配置方法.还有和[PageHelper分页插件](https://github.com/pagehelper/Mybatis-PageHelper)集成的配置方式.
@@ -54,11 +64,17 @@ Mybatis工具群: 211286137 (Mybatis相关工具插件等等)
5464
<!--配置UUID生成策略需要使用OGNL表达式-->
5565
<!--默认值32位长度:@java.util.UUID@randomUUID().toString().replace("-", "")-->
5666
<!--<property name="UUID" value="@java.util.UUID@randomUUID().toString()"/>-->
57-
<!--主键自增回写方法,默认值MYSQL,详细说明看下面的INENTITY参数配置-->
58-
<!--<property name="IDENTITY" value="MYSQL"/>-->
67+
<!--主键自增回写方法,默认值MYSQL,详细说明请看文档-->
68+
<property name="IDENTITY" value="HSQLDB"/>
69+
<!--序列的获取规则,使用{num}格式化参数,默认值为{0}.nextval,针对Oracle-->
70+
<!--可选参数一共3个,对应0,1,2,分别为SequenceName,ColumnName,PropertyName-->
71+
<property name="seqFormat" value="{0}.nextval"/>
5972
<!--主键自增回写方法执行顺序,默认AFTER,可选值为(BEFORE|AFTER)-->
6073
<!--<property name="ORDER" value="AFTER"/>-->
61-
<!--通用Mapper接口,多个用逗号隔开-->
74+
<!--支持Map类型的实体类,自动将大写下划线的Key转换为驼峰式-->
75+
<!--这个处理使得通用Mapper可以支持Map类型的实体(实体中的字段必须按常规方式定义,否则无法反射获得列)-->
76+
<property name="cameHumpMap" value="true"/>
77+
<!--通用Mapper接口,多个通用接口用逗号隔开-->
6278
<property name="mappers" value="com.github.abel533.mapper.Mapper"/>
6379
</plugin>
6480
</plugins>
@@ -232,21 +248,24 @@ int updateByPrimaryKeySelective(T record);
232248
@Id
233249
private Integer id;
234250
```
251+
该字段不会回写。
235252

236253
2. 使用UUID时:
237254
```java
238255
//可以用于任意字符串类型长度超过32位的字段
239256
@GeneratedValue(generator = "UUID")
240257
private String countryname;
241258
```
259+
该字段不会回写。
242260

243261
3. 使用主键自增:
244262
```java
245263
//不限于@Id注解的字段,但是一个实体类中只能存在一个(继承关系中也只能存在一个)
246264
@Id
247265
@GeneratedValue(strategy = GenerationType.IDENTITY)
248266
private Integer id;
249-
```
267+
```
268+
首先该字段必须是一个自增的字段,增加这个注解后,**会回写ID**
250269

251270

252271
###5. 将继承的Mapper接口添加到Mybatis配置中
@@ -325,7 +344,7 @@ try {
325344

326345
直接在需要的地方注入Mapper继承的接口即可,和一般情况下的使用没有区别.
327346

328-
##当前版本v0.1.0
347+
##当前版本v0.2.0
329348

330349
##这是一个新生的开源项目
331350

pom.xml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.github.abel533</groupId>
66
<artifactId>mapper</artifactId>
7-
<version>0.1.0</version>
7+
<version>0.2.0</version>
88
<packaging>jar</packaging>
99

1010
<name>mapper</name>
@@ -15,35 +15,36 @@
1515
</properties>
1616

1717
<dependencies>
18+
<dependency>
19+
<groupId>javax.persistence</groupId>
20+
<artifactId>persistence-api</artifactId>
21+
<version>1.0</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.mybatis</groupId>
25+
<artifactId>mybatis</artifactId>
26+
<version>3.2.6</version>
27+
<optional>true</optional>
28+
</dependency>
29+
30+
<!--测试-->
1831
<dependency>
1932
<groupId>junit</groupId>
2033
<artifactId>junit</artifactId>
2134
<version>4.11</version>
2235
<scope>test</scope>
2336
</dependency>
24-
2537
<dependency>
2638
<groupId>log4j</groupId>
2739
<artifactId>log4j</artifactId>
2840
<version>1.2.17</version>
2941
<scope>test</scope>
3042
</dependency>
31-
32-
<dependency>
33-
<groupId>org.mybatis</groupId>
34-
<artifactId>mybatis</artifactId>
35-
<version>3.2.6</version>
36-
</dependency>
3743
<dependency>
3844
<groupId>org.hsqldb</groupId>
3945
<artifactId>hsqldb</artifactId>
4046
<version>2.2.9</version>
41-
</dependency>
42-
43-
<dependency>
44-
<groupId>javax.persistence</groupId>
45-
<artifactId>persistence-api</artifactId>
46-
<version>1.0</version>
47+
<scope>test</scope>
4748
</dependency>
4849
</dependencies>
4950
<build>

src/test/java/com/github/abel533/test/country/TestSelect.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.junit.Assert;
88
import org.junit.Test;
99

10+
import java.text.MessageFormat;
1011
import java.util.List;
1112

1213
/**
@@ -33,17 +34,18 @@ public void testDynamicSelectAll() {
3334
}
3435

3536
/**
36-
* 除了通过主键的方法,其他的方法入参不能为null
37+
* 入参为null时查询全部
3738
*/
38-
@Test(expected = RuntimeException.class)
39+
@Test
3940
public void testDynamicSelectAllByNull() {
40-
SqlSession sqlSession = MybatisHelper.getSqlSession();
41-
try {
42-
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
43-
mapper.select(null);
44-
} finally {
45-
sqlSession.close();
46-
}
41+
// SqlSession sqlSession = MybatisHelper.getSqlSession();
42+
// try {
43+
// CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
44+
// mapper.select(null);
45+
// } finally {
46+
// sqlSession.close();
47+
// }
48+
System.out.println(MessageFormat.format("{2}-{0}.nextval ","SEQ_ID","HEHE","XIXI"));
4749
}
4850

4951
/**

src/test/java/com/github/abel533/test/country/TestSelectCount.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public void testDynamicSelectCount() {
3030
}
3131

3232
/**
33-
* 除了通过主键的方法,其他的方法入参不能为null
33+
* 入参为null时查询全部
3434
*/
35-
@Test(expected = RuntimeException.class)
35+
@Test
3636
public void testDynamicSelectAllByNull() {
3737
SqlSession sqlSession = MybatisHelper.getSqlSession();
3838
try {

src/test/java/com/github/abel533/test/country/TestUpdateByPrimaryKey.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public void testDynamicUpdateByPrimaryKeyAll() {
2929
}
3030

3131
/**
32-
* 除了通过主键的方法,其他的方法入参不能为null
32+
* 入参为null时更新全部
3333
*/
34-
@Test(expected = RuntimeException.class)
34+
@Test
3535
public void testDynamicUpdateByPrimaryKeyAllByNull() {
3636
SqlSession sqlSession = MybatisHelper.getSqlSession();
3737
try {

src/test/java/com/github/abel533/test/country2/TestInsert.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.github.abel533.mapper.Country2Mapper;
44
import com.github.abel533.mapper.MybatisHelper;
55
import com.github.abel533.model.Country2;
6-
import org.apache.ibatis.exceptions.PersistenceException;
76
import org.apache.ibatis.session.SqlSession;
87
import org.junit.Assert;
98
import org.junit.Test;
@@ -42,7 +41,7 @@ public void testDynamicInsertAll() {
4241
/**
4342
* 不能插入null
4443
*/
45-
@Test(expected = PersistenceException.class)
44+
@Test
4645
public void testDynamicInsertAllByNull() {
4746
SqlSession sqlSession = MybatisHelper.getSqlSession();
4847
try {

src/test/resources/mybatis-config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@
2626
<!--<property name="UUID" value="@java.util.UUID@randomUUID().toString()"/>-->
2727
<!--主键自增回写方法,默认值MYSQL,详细说明请看文档-->
2828
<property name="IDENTITY" value="HSQLDB"/>
29+
<!--序列的获取规则,使用{num}格式化参数,默认值为{0}.nextval,针对Oracle-->
30+
<!--可选参数一共3个,对应0,1,2,分别为SequenceName,ColumnName,PropertyName-->
31+
<property name="seqFormat" value="{0}.nextval"/>
2932
<!--主键自增回写方法执行顺序,默认AFTER,可选值为(BEFORE|AFTER)-->
3033
<!--<property name="ORDER" value="AFTER"/>-->
3134
<!--支持Map类型的实体类,自动将大写下划线的Key转换为驼峰式-->
35+
<!--这个处理使得通用Mapper可以支持Map类型的实体(实体中的字段必须按常规方式定义,否则无法反射获得列)-->
3236
<property name="cameHumpMap" value="true"/>
3337
<!--通用Mapper接口,多个用逗号隔开-->
3438
<property name="mappers" value="com.github.abel533.mapper.Mapper"/>

0 commit comments

Comments
 (0)