3030import java .util .List ;
3131import java .util .concurrent .TimeUnit ;
3232
33- import static apijson .framework .APIJSONConstant .PRIVACY_ ;
34- import static apijson .framework .APIJSONConstant .USER_ ;
33+ import static apijson .framework .javax . APIJSONConstant .PRIVACY_ ;
34+ import static apijson .framework .javax . APIJSONConstant .USER_ ;
3535
3636
3737/**
@@ -46,8 +46,13 @@ public class DemoSQLExecutor extends APIJSONSQLExecutor<Long> {
4646 // Redis 缓存 <<<<<<<<<<<<<<<<<<<<<<<
4747 public static final RedisTemplate <String , String > REDIS_TEMPLATE ;
4848 static {
49+ RedisStandaloneConfiguration config = new RedisStandaloneConfiguration ("127.0.0.1" , 6379 ); // TODO 改成你自己的
50+ // 如果需要账号及密码则按以下方式设置
51+ // config.setUsername("root"); // TODO 改成你自己的
52+ // config.setPassword("apijson"); // TODO 改成你自己的
53+
4954 REDIS_TEMPLATE = new RedisTemplate <>();
50- REDIS_TEMPLATE .setConnectionFactory (new JedisConnectionFactory (new RedisStandaloneConfiguration ( "127.0.0.1" , 6379 ) ));
55+ REDIS_TEMPLATE .setConnectionFactory (new JedisConnectionFactory (config ));
5156 REDIS_TEMPLATE .setKeySerializer (new StringRedisSerializer ());
5257 REDIS_TEMPLATE .setHashValueSerializer (new GenericToStringSerializer <>(Serializable .class ));
5358 REDIS_TEMPLATE .setValueSerializer (new GenericToStringSerializer <>(Serializable .class ));
@@ -57,7 +62,7 @@ public class DemoSQLExecutor extends APIJSONSQLExecutor<Long> {
5762
5863 // 可重写以下方法,支持 Redis 等单机全局缓存或分布式缓存
5964 @ Override
60- public List <JSONObject > getCache (String sql , SQLConfig config ) {
65+ public List <JSONObject > getCache (String sql , SQLConfig < Long > config ) {
6166 List <JSONObject > list = super .getCache (sql , config );
6267 if (list == null ) {
6368 list = JSON .parseArray (REDIS_TEMPLATE .opsForValue ().get (sql ), JSONObject .class );
@@ -66,7 +71,7 @@ public List<JSONObject> getCache(String sql, SQLConfig config) {
6671 }
6772
6873 @ Override
69- public synchronized void putCache (String sql , List <JSONObject > list , SQLConfig config ) {
74+ public synchronized void putCache (String sql , List <JSONObject > list , SQLConfig < Long > config ) {
7075 super .putCache (sql , list , config );
7176
7277 String table = config != null && config .isMain () ? config .getTable () : null ;
@@ -80,7 +85,7 @@ public synchronized void putCache(String sql, List<JSONObject> list, SQLConfig c
8085 }
8186
8287 @ Override
83- public synchronized void removeCache (String sql , SQLConfig config ) {
88+ public synchronized void removeCache (String sql , SQLConfig < Long > config ) {
8489 super .removeCache (sql , config );
8590 if (config .getMethod () == RequestMethod .DELETE ) { // 避免缓存击穿
8691 REDIS_TEMPLATE .expire (sql , 60 , TimeUnit .SECONDS );
0 commit comments