Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 253aeee

Browse files
committed
去掉cached,这个属性不能使用。
1 parent 130427d commit 253aeee

File tree

2 files changed

+2
-35
lines changed

2 files changed

+2
-35
lines changed

src/main/java/com/github/abel533/sql/SqlMapper.java

+2-25
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,17 @@
2020
public class SqlMapper {
2121
private final MSUtils msUtils;
2222
private final SqlSession sqlSession;
23-
private boolean cached;
2423

2524
/**
2625
* 构造方法,默认缓存MappedStatement
2726
*
28-
* <br>当通过前台实现执行任意SQL时,建议关闭缓存,否则每一个SQL缓存一次,最终的缓存数量会很大
29-
* <br>如果是业务代码中拼的sql,建议缓存提高效率
30-
*
3127
* @param sqlSession
3228
*/
3329
public SqlMapper(SqlSession sqlSession) {
34-
this(sqlSession, true);
35-
}
36-
37-
/**
38-
* 构造方法,可以控制是否缓存MappedStatement
39-
*
40-
* @param sqlSession
41-
* @param cached 是否缓存MappedStatement
42-
*/
43-
public SqlMapper(SqlSession sqlSession, boolean cached) {
4430
this.sqlSession = sqlSession;
45-
this.cached = cached;
4631
this.msUtils = new MSUtils(sqlSession.getConfiguration());
4732
}
4833

49-
public void setCached(boolean cached) {
50-
this.cached = cached;
51-
}
52-
5334
/**
5435
* 获取List中最多只有一个的数据
5536
*
@@ -299,9 +280,7 @@ private void newSelectMappedStatement(String msId, SqlSource sqlSource, final Cl
299280
})
300281
.build();
301282
//缓存
302-
if (cached) {
303-
configuration.addMappedStatement(ms);
304-
}
283+
configuration.addMappedStatement(ms);
305284
}
306285

307286
/**
@@ -320,9 +299,7 @@ private void newUpdateMappedStatement(String msId, SqlSource sqlSource, SqlComma
320299
})
321300
.build();
322301
//缓存
323-
if (cached) {
324-
configuration.addMappedStatement(ms);
325-
}
302+
configuration.addMappedStatement(ms);
326303
}
327304

328305
private String select(String sql) {

wiki/UseSqlMapper.md

-10
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,6 @@ SqlMapper sqlMapper = new SqlMapper(sqlSession);
7070

7171
在Service中使用的时候可以直接使用`@Autowired`注入。
7272

73-
<b>注意:</b>`SqlMapper`增加了一个构造方法`public SqlMapper(SqlSession sqlSession, boolean cached)`,可以通过`cache`控制是否缓存动态创建的`MappedStatement`
74-
75-
使用`public SqlMapper(SqlSession sqlSession)`时,`cached`默认为`true`,会缓存。
76-
77-
###如何选择是否缓存动态创建的`MappedStatement`?
78-
79-
1. 当通过前台实现执行任意SQL时,建议关闭缓存,否则每一个SQL缓存一次,最终的缓存数量会很大
80-
81-
2. 如果是业务代码中拼的sql,建议缓存提高效率
82-
8373
##简单例子
8474

8575
`src/test/java`目录的`com.github.abel533.sql`包中包含这些方法的测试。

0 commit comments

Comments
 (0)