Skip to content

Commit adad0fc

Browse files
committed
Add common mappers with reusable methods for MyBatis
1 parent 881ac46 commit adad0fc

File tree

13 files changed

+131
-194
lines changed

13 files changed

+131
-194
lines changed

src/main/java/org/mybatis/dynamic/sql/util/mybatis3/GeneralMapper.java renamed to src/main/java/org/mybatis/dynamic/sql/util/mybatis3/CommonSelectMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
*
4747
* @author Jeff Butler
4848
*/
49-
public interface GeneralMapper {
49+
public interface CommonSelectMapper {
5050
/**
5151
* Select a single row as a Map of values. The row may have any number of columns.
5252
* The Map key will be the column name as returned from the
@@ -67,7 +67,7 @@ public interface GeneralMapper {
6767
* the row values into a Map, and then a row mapper can retrieve values from the Map and use them
6868
* to construct a custom object.
6969
*
70-
* <p>See {@link GeneralMapper#selectOneMappedRow(SelectStatementProvider)} for details about
70+
* <p>See {@link CommonSelectMapper#selectOneMappedRow(SelectStatementProvider)} for details about
7171
* how MyBatis will construct the Map of values.
7272
*
7373
* @param selectStatement the select statement

src/site/markdown/docs/mybatis3.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ MyBatis is very good at mapping result sets to objects - this is one of its prim
1010
that you predefine the mappings for every possibility. This presents a challenge if you want very dynamic column lists
1111
in a query. This library provides a generalized MyBatis mapper that can assist with that problem.
1212

13-
The general mapper is `org.mybatis.dynamic.sql.util.mybatis3.GeneralMapper`. This mapper can be injected into a MyBatis configuration
13+
The general mapper is `org.mybatis.dynamic.sql.util.mybatis3.CommonSelectMapper`. This mapper can be injected into a MyBatis configuration
1414
as is, or it can be extended by an existing mapper. If you are using MyBatis Spring support and auto scanning for mappers,
1515
you can create an extension in your application's mapper package as follows:
1616

1717
```java
1818
package foo.mapper;
1919

2020
import org.apache.ibatis.annotations.Mapper;
21-
import org.mybatis.dynamic.sql.util.mybatis3.GeneralMapper;
21+
import org.mybatis.dynamic.sql.util.mybatis3.CommonSelectMapper;
2222

2323
@Mapper
24-
public interface MyGeneralMapper extends GeneralMapper {
24+
public interface MyGeneralMapper extends CommonSelectMapper {
2525
}
2626
```
2727

@@ -45,11 +45,11 @@ import java.util.List;
4545
import java.util.Map;
4646
import org.mybatis.dynamic.sql.render.RenderingStrategies;
4747
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
48-
import org.mybatis.dynamic.sql.util.mybatis3.GeneralMapper;
48+
import org.mybatis.dynamic.sql.util.mybatis3.CommonSelectMapper;
4949

5050
public class MyService {
5151
public List<Map<String,Object>> generalSearch() {
52-
GeneralMapper mapper = getGeneralMapper(); // not shown
52+
CommonSelectMapper mapper = getGeneralMapper(); // not shown
5353

5454
SelectStatementProvider selectStatement = select(id, description)
5555
.from(foo)
@@ -76,11 +76,11 @@ import static org.mybatis.dynamic.sql.SqlBuilder.*;
7676
import java.util.List;
7777
import org.mybatis.dynamic.sql.render.RenderingStrategies;
7878
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
79-
import org.mybatis.dynamic.sql.util.mybatis3.GeneralMapper;
79+
import org.mybatis.dynamic.sql.util.mybatis3.CommonSelectMapper;
8080

8181
public class MyService {
8282
public List<TableCode> generalSearch() {
83-
GeneralMapper mapper = getGeneralMapper(); // not shown
83+
CommonSelectMapper mapper = getGeneralMapper(); // not shown
8484

8585
SelectStatementProvider selectStatement = select(id, description)
8686
.from(foo)
@@ -108,11 +108,11 @@ import static org.mybatis.dynamic.sql.SqlBuilder.*;
108108

109109
import org.mybatis.dynamic.sql.render.RenderingStrategies;
110110
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
111-
import org.mybatis.dynamic.sql.util.mybatis3.GeneralMapper;
111+
import org.mybatis.dynamic.sql.util.mybatis3.CommonSelectMapper;
112112

113113
public class MyService {
114114
public Long getCount() {
115-
GeneralMapper mapper = getGeneralMapper(); // not shown
115+
CommonSelectMapper mapper = getGeneralMapper(); // not shown
116116

117117
SelectStatementProvider selectStatement = countFrom(foo)
118118
.where(description. isLike("%bar%"))

src/test/java/examples/animal/data/AnimalDataMapper.java

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,20 @@
1717

1818
import java.util.List;
1919

20-
import org.apache.ibatis.annotations.DeleteProvider;
21-
import org.apache.ibatis.annotations.InsertProvider;
2220
import org.apache.ibatis.annotations.Param;
2321
import org.apache.ibatis.annotations.Result;
2422
import org.apache.ibatis.annotations.ResultMap;
2523
import org.apache.ibatis.annotations.Results;
2624
import org.apache.ibatis.annotations.Select;
2725
import org.apache.ibatis.annotations.SelectProvider;
28-
import org.apache.ibatis.annotations.UpdateProvider;
29-
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
30-
import org.mybatis.dynamic.sql.insert.render.GeneralInsertStatementProvider;
31-
import org.mybatis.dynamic.sql.insert.render.InsertSelectStatementProvider;
32-
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
3326
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
34-
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
3527
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
28+
import org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper;
29+
import org.mybatis.dynamic.sql.util.mybatis3.CommonInsertMapper;
30+
import org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper;
3631
import org.mybatis.dynamic.sql.where.render.WhereClauseProvider;
3732

38-
public interface AnimalDataMapper {
33+
public interface AnimalDataMapper extends CommonDeleteMapper, CommonInsertMapper<AnimalData>, CommonUpdateMapper {
3934

4035
@SelectProvider(type=SqlProviderAdapter.class, method="select")
4136
@Results(id="AnimalDataResult", value={
@@ -50,21 +45,6 @@ public interface AnimalDataMapper {
5045
@ResultMap("AnimalDataResult")
5146
AnimalData selectOne(SelectStatementProvider selectStatement);
5247

53-
@DeleteProvider(type=SqlProviderAdapter.class, method="delete")
54-
int delete(DeleteStatementProvider deleteStatement);
55-
56-
@UpdateProvider(type=SqlProviderAdapter.class, method="update")
57-
int update(UpdateStatementProvider updateStatement);
58-
59-
@InsertProvider(type=SqlProviderAdapter.class, method="insert")
60-
int insert(InsertStatementProvider<AnimalData> insertStatement);
61-
62-
@InsertProvider(type=SqlProviderAdapter.class, method="generalInsert")
63-
int generalInsert(GeneralInsertStatementProvider insertStatement);
64-
65-
@InsertProvider(type=SqlProviderAdapter.class, method="insertSelect")
66-
int insertSelect(InsertSelectStatementProvider insertSelectStatement);
67-
6848
@Select({
6949
"select id, animal_name, brain_weight, body_weight",
7050
"from AnimalData",

0 commit comments

Comments
 (0)