Skip to content

Commit b21bccc

Browse files
committed
完善驼峰和Example等
1 parent 70be827 commit b21bccc

File tree

9 files changed

+89
-22
lines changed

9 files changed

+89
-22
lines changed

src/main/java/tk/mybatis/mapper/entity/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class Config {
3333
*
3434
* @return
3535
*/
36-
public boolean getBEFORE() {
36+
public boolean isBEFORE() {
3737
return BEFORE;
3838
}
3939

src/main/java/tk/mybatis/mapper/entity/Example.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ public Criteria andLessThanOrEqualTo(String property, Object value) {
276276
return (Criteria) this;
277277
}
278278

279-
public Criteria andIn(String property, List<Object> values) {
279+
public Criteria andIn(String property, List<?> values) {
280280
addCriterion(column(property) + " in", values, property(property));
281281
return (Criteria) this;
282282
}
283283

284-
public Criteria andNotIn(String property, List<Object> values) {
284+
public Criteria andNotIn(String property, List<?> values) {
285285
addCriterion(column(property) + " not in", values, property(property));
286286
return (Criteria) this;
287287
}
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
package tk.mybatis.mapper.entity;
22

33
/**
4-
* 实现动态表名时,实体类实现该接口
4+
* 实现动态表名时,实体类需要实现该接口
55
*
66
* @author liuzh
77
* @since 2015-10-28 22:20
88
*/
99
public interface IDynamicTableName {
1010

1111
/**
12-
* 获取动态表名 - 这个方法是关键,只要有返回值,不是null和'',就会用返回值作为表名
12+
* 获取动态表名 - 只要有返回值,不是null和'',就会用返回值作为表名
1313
*
1414
* @return
1515
*/
1616
String getDynamicTableName();
17-
18-
/**
19-
* 设置动态表名 - 这个方法没有绝对的作用,仅仅是为了和上面的get方法配套
20-
*
21-
* @param dynamicTableName
22-
*/
23-
void setDynamicTableName(String dynamicTableName);
2417
}

src/main/java/tk/mybatis/mapper/util/StringUtil.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static String camelhumpToUnderline(String str) {
6868
for (int i = 0; i < size; i++) {
6969
c = chars[i];
7070
if (isUppercaseAlpha(c)) {
71-
sb.append('_').append(c);
71+
sb.append('_').append(toLowerAscii(c));
7272
} else {
7373
sb.append(toUpperAscii(c));
7474
}
@@ -95,10 +95,21 @@ public static boolean isUppercaseAlpha(char c) {
9595
return (c >= 'A') && (c <= 'Z');
9696
}
9797

98+
public static boolean isLowercaseAlpha(char c) {
99+
return (c >= 'a') && (c <= 'z');
100+
}
101+
98102
public static char toUpperAscii(char c) {
99103
if (isUppercaseAlpha(c)) {
100104
c -= (char) 0x20;
101105
}
102106
return c;
103107
}
108+
109+
public static char toLowerAscii(char c) {
110+
if (isUppercaseAlpha(c)) {
111+
c += (char) 0x20;
112+
}
113+
return c;
114+
}
104115
}

src/test/java/tk/mybatis/mapper/model/Country.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public String getDynamicTableName() {
6969
return dynamicTableName123;
7070
}
7171

72-
@Override
73-
public void setDynamicTableName(String dynamicTableName) {
72+
public void setDynamicTableName123(String dynamicTableName) {
7473
this.dynamicTableName123 = dynamicTableName;
7574
}
7675
}

src/test/java/tk/mybatis/mapper/test/country/TestSelect.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public void testDynamicSelectAll() {
2626
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
2727
Country country = new Country();
2828
List<Country> countryList;
29-
// country.setDynamicTableName("country_123");
30-
// countryList = mapper.select(country);
31-
// //查询总数
32-
// Assert.assertEquals(2, countryList.size());
29+
//country.setDynamicTableName123("country_123");
30+
//countryList = mapper.select(country);
31+
//查询总数
32+
//Assert.assertEquals(2, countryList.size());
3333

34-
country.setDynamicTableName(null);
34+
country.setDynamicTableName123(null);
3535
countryList = mapper.select(country);
3636
//查询总数
3737
Assert.assertEquals(183, countryList.size());

src/test/java/tk/mybatis/mapper/test/example/TestSelectByExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void testSelectByExampleInNotIn() {
5858
try {
5959
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
6060
Example example = new Example(Country.class);
61-
example.createCriteria().andIn("id", Arrays.asList(new Object[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}))
61+
example.createCriteria().andIn("id", Arrays.asList(new Integer[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}))
6262
.andNotIn("id", Arrays.asList(new Object[]{11}));
6363
List<Country> countries = mapper.selectByExample(example);
6464
//查询总数

src/test/java/tk/mybatis/mapper/test/example/TestUpdateByExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void testUpdateByExample() {
2424
Example example = new Example(Country.class);
2525
example.createCriteria().andEqualTo("id", 35);
2626
Country country = new Country();
27-
country.setDynamicTableName("country");
27+
//country.setDynamicTableName123("country_123");
2828
country.setCountryname("天朝");
2929
country.setId(1000);
3030
int count = mapper.updateByExample(country, example);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package tk.mybatis.mapper.test.othres;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
import tk.mybatis.mapper.code.Style;
6+
import tk.mybatis.mapper.util.StringUtil;
7+
8+
/**
9+
* @author liuzh
10+
* @since 2015-10-31 09:41
11+
*/
12+
public class StyleTest {
13+
private String[] fields = new String[]{
14+
"hello",
15+
"hello_world",
16+
//"hello_World",
17+
"helloWorld",
18+
"hello1",
19+
"hello_1"
20+
};
21+
22+
@Test
23+
public void testNormal() {
24+
for (String field : fields) {
25+
Assert.assertEquals(field, StringUtil.convertByStyle(field, Style.normal));
26+
}
27+
}
28+
29+
@Test
30+
public void testUppercase() {
31+
for (String field : fields) {
32+
Assert.assertEquals(field.toUpperCase(), StringUtil.convertByStyle(field, Style.uppercase));
33+
}
34+
}
35+
36+
@Test
37+
public void testLowercase() {
38+
for (String field : fields) {
39+
Assert.assertEquals(field.toLowerCase(), StringUtil.convertByStyle(field, Style.lowercase));
40+
}
41+
}
42+
43+
@Test
44+
public void testCamelhump() {
45+
for (String field : fields) {
46+
System.out.println(field + " - " + StringUtil.convertByStyle(field, Style.camelhump));
47+
}
48+
}
49+
50+
@Test
51+
public void testCamelhumpUppercase() {
52+
for (String field : fields) {
53+
System.out.println(field + " - " + StringUtil.convertByStyle(field, Style.camelhumpAndUppercase));
54+
}
55+
}
56+
57+
@Test
58+
public void testCamelhumpLowercase() {
59+
for (String field : fields) {
60+
System.out.println(field + " - " + StringUtil.convertByStyle(field, Style.camelhumpAndLowercase));
61+
}
62+
}
63+
64+
}

0 commit comments

Comments
 (0)