Skip to content

Commit e12be21

Browse files
committed
完善参数类型,改为强类型后,参数类型不会在自动转换,例如"100"不会转换为100,类型不一致的时候会报错。
1 parent e76e254 commit e12be21

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

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

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import tk.mybatis.mapper.typehandler.StringType2Handler;
77

88
import javax.persistence.Column;
9-
import javax.persistence.Id;
10-
import javax.persistence.OrderBy;
119
import javax.persistence.Transient;
1210
import java.io.Serializable;
1311

@@ -16,13 +14,9 @@
1614
* Author: liuzh
1715
* Update: liuzh(2014-06-06 13:38)
1816
*/
19-
public class Country implements Serializable, IDynamicTableName {
17+
public class Country extends Entity<Integer, String> implements Serializable, IDynamicTableName {
2018
private static final long serialVersionUID = -1626761012846137805L;
2119

22-
@Id
23-
@OrderBy("desc")
24-
private Integer id;
25-
2620
@Column
2721
@ColumnType(jdbcType = JdbcType.VARCHAR, typeHandler = StringType2Handler.class)
2822
private String countryname;
@@ -31,14 +25,6 @@ public class Country implements Serializable, IDynamicTableName {
3125
@Transient
3226
private String dynamicTableName123;
3327

34-
public Integer getId() {
35-
return id;
36-
}
37-
38-
public void setId(Integer id) {
39-
this.id = id;
40-
}
41-
4228
public String getCountryname() {
4329
return countryname;
4430
}
@@ -55,15 +41,6 @@ public void setCountrycode(String countrycode) {
5541
this.countrycode = countrycode;
5642
}
5743

58-
@Override
59-
public String toString() {
60-
return "Country{" +
61-
"id=" + id +
62-
", countryname='" + countryname + '\'' +
63-
", countrycode='" + countrycode + '\'' +
64-
'}';
65-
}
66-
6744
@Override
6845
public String getDynamicTableName() {
6946
return dynamicTableName123;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package tk.mybatis.mapper.model;
2+
3+
import javax.persistence.Id;
4+
import javax.persistence.OrderBy;
5+
import javax.persistence.Transient;
6+
import java.io.Serializable;
7+
8+
/**
9+
* @author liuzh_3nofxnp
10+
* @since 2015-12-06 10:31
11+
*/
12+
public class Entity<ID extends Serializable, NAME extends Serializable> {
13+
14+
@Id
15+
@OrderBy("desc")
16+
private ID id;
17+
18+
@Transient
19+
private NAME name;
20+
21+
public ID getId() {
22+
return id;
23+
}
24+
25+
public void setId(ID id) {
26+
this.id = id;
27+
}
28+
29+
public NAME getName() {
30+
return name;
31+
}
32+
33+
public void setName(NAME name) {
34+
this.name = name;
35+
}
36+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void testDynamicDeleteException() {
120120
try {
121121
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
122122
//根据主键删除
123-
Assert.assertEquals(1, mapper.deleteByPrimaryKey("100"));
123+
Assert.assertEquals(1, mapper.deleteByPrimaryKey(100));
124124
} finally {
125125
sqlSession.rollback();
126126
sqlSession.close();

0 commit comments

Comments
 (0)