From 1a69d2feee86908e66b835617018601c9a127ae3 Mon Sep 17 00:00:00 2001 From: wangbing Date: Tue, 24 Dec 2019 16:32:41 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81wadmin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 7e6bc5a486e6bb238863613c64e78857e4d2e387 --- .../manger/callable/SpringBootCallable.java | 1 + .../modules/SpringBoot/java/Application.ftl | 2 + .../SpringBoot/java/config/CacheConfig.java | 28 +++++++++ .../system/mpr/MySQL_DictItemMapper.xml | 59 ++++++++++--------- .../system/mpr/Oracle_DictItemMapper.xml | 3 + .../system/mpr/SQLite_DictItemMapper.xml | 3 + src/main/resources/modules/SpringBoot/pom.ftl | 9 +-- 7 files changed, 73 insertions(+), 32 deletions(-) create mode 100644 src/main/resources/modules/SpringBoot/java/config/CacheConfig.java diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java index a827d25e..9a714520 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java @@ -247,6 +247,7 @@ public class SpringBootCallable implements Callable { //config freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "ActionConfig.java"), option + "/java/config/ActionConfig.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "CacheConfig.java"), option + "/java/config/CacheConfig.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "FreeMarkerConfig.java"), option + "/java/config/FreeMarkerConfig.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "SecurityConfig.java"), option + "/java/config/SecurityConfig.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "TaskConfig.java"), option + "/java/config/TaskConfig.java", ctx); diff --git a/src/main/resources/modules/SpringBoot/java/Application.ftl b/src/main/resources/modules/SpringBoot/java/Application.ftl index dcc81d81..969bb3b5 100644 --- a/src/main/resources/modules/SpringBoot/java/Application.ftl +++ b/src/main/resources/modules/SpringBoot/java/Application.ftl @@ -8,6 +8,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.cache.annotation.EnableCaching; @SpringBootApplication <#if multiDB> @@ -15,6 +16,7 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer <#else> @EnableAutoConfiguration +@EnableCaching public class Application extends SpringBootServletInitializer { @Override diff --git a/src/main/resources/modules/SpringBoot/java/config/CacheConfig.java b/src/main/resources/modules/SpringBoot/java/config/CacheConfig.java new file mode 100644 index 00000000..a425f4c3 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/java/config/CacheConfig.java @@ -0,0 +1,28 @@ +package ${basePackage}.config; + +import net.sf.ehcache.CacheManager; +import net.sf.ehcache.config.CacheConfiguration; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.cache.ehcache.EhCacheCacheManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableCaching +public class CacheConfig { + + @Bean(name = "tokenCacheManager") + public EhCacheCacheManager tokenCacheManager() { + EhCacheCacheManager ehCacheCacheManager = new EhCacheCacheManager(); + net.sf.ehcache.config.Configuration configuration = new net.sf.ehcache.config.Configuration(); + configuration.setMaxBytesLocalHeap("2G"); + configuration.setUpdateCheck(false);//设置不检查更新 + CacheConfiguration cacheConfiguration = new CacheConfiguration(); + cacheConfiguration.setTimeToLiveSeconds(60 * 60);//一个小时有效缓存时间 + cacheConfiguration.setTimeToIdleSeconds(30 * 60);//30分钟不使用eternal为true会失效 + configuration.addDefaultCache(cacheConfiguration); + CacheManager cacheManager = CacheManager.create(configuration); + ehCacheCacheManager.setCacheManager(cacheManager); + return ehCacheCacheManager; + } +} diff --git a/src/main/resources/modules/SpringBoot/java/module/system/mpr/MySQL_DictItemMapper.xml b/src/main/resources/modules/SpringBoot/java/module/system/mpr/MySQL_DictItemMapper.xml index 3285ed92..96d101b2 100644 --- a/src/main/resources/modules/SpringBoot/java/module/system/mpr/MySQL_DictItemMapper.xml +++ b/src/main/resources/modules/SpringBoot/java/module/system/mpr/MySQL_DictItemMapper.xml @@ -4,6 +4,9 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + + + `SYS_DICT_ITEM` @@ -11,18 +14,18 @@ - - - - - - - - - - - - + + + + + + + + + + + +