diff --git a/README b/README
new file mode 100644
index 0000000..5efbbf3
--- /dev/null
+++ b/README
@@ -0,0 +1,20 @@
+# SpringBootDemo
+本代码集成了SpringBoot+MyBatis+Redis+MySql。
+最新的部分经网友指正已经把冗余的代码去掉了,大家clone到本地后直接转成maven项目应该就可以运行了,项目中使用到的数据库表如下
+
+-- ----------------------------
+-- Table structure for `user_info`
+-- ----------------------------
+DROP TABLE IF EXISTS `user_info`;
+CREATE TABLE `user_info` (
+ `id` int(8) NOT NULL AUTO_INCREMENT,
+ `name` varchar(20) NOT NULL,
+ `age` int(2) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
+
+-- ----------------------------
+-- Records of user_info
+-- ----------------------------
+INSERT INTO `user_info` VALUES ('1', 'xiaour', '1231');
+
diff --git a/README.md b/README.md
deleted file mode 100644
index ae7616d..0000000
--- a/README.md
+++ /dev/null
@@ -1,56 +0,0 @@
-## 相关文章
-
-1.[SpringMVC配置太多?试试SpringBoot](https://xiaour.github.io/2018/05/02/The_SpringMVC_configuration_is_too_much_Try_SpringBoot/)
-
-2.[Springboot集成Kafka](https://xiaour.github.io/2018/05/23/Springboot_integrated_Kafka/)
-
-3.[Springboot集成RocketMQ](https://xiaour.github.io/2018/08/16/SpringbootRocketMQ/)
-
-4.Webflux Spring异步编程,你将发现新大陆(代码已经部分上传,blog完善中...)
-
-5.[利用EasyExcel,两行代码开发一个和API结果一致的生成Excel功能](https://github.com/xiaour/EasyExport#readme)
-
-## 代码部分
-
-⭐️ SpringBootDemo
-本代码集成了SpringBoot+MyBatis+Redis+MySql。
-最新的部分经网友指正已经把冗余的代码去掉了,代码部分和配置文件部分都有相关的注释;
-git clone 到本地后就可以运行了,项目中使用到的数据库表如下
-
-```sql
--- ----------------------------
--- Table structure for `user_info`
--- ----------------------------
-DROP TABLE IF EXISTS `user_info`;
-CREATE TABLE `user_info` (
- `id` int(8) NOT NULL AUTO_INCREMENT,
- `name` varchar(20) NOT NULL,
- `age` int(2) DEFAULT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
-
--- ----------------------------
--- Records of user_info
--- ----------------------------
-INSERT INTO `user_info` VALUES ('1', 'xiaour', '18');
-```
-
-⭐️ SpringBootDemoV2
-代码主要和SpringBootDemo的区别是使用了Springboot2.0
-
-2018.08.22 添加了Twitter ID生成算法的工具,每秒支持12万ID生成。
-
-⭐️ SpringBootKafkaDemo
-Springboot2.0继承了Kafka消息中间件
-
-⭐️ SpringBootRocketMqDemo
-Springboot2.0继承了RocketMQ4.3消息中间件
-
-⭐️ SpringWebfluxDemo
-Webflux Spring异步编程。
-
-
----------------------------------
-有兴趣的朋友可以关注一下最新开源的
-[spring.boot.sapi.starter](https://github.com/xiaour/spring.boot.sapi.starter)
-
diff --git a/SpringBootDemo/pom.xml b/SpringBootDemo/pom.xml
index 3280d80..1c831f9 100644
--- a/SpringBootDemo/pom.xml
+++ b/SpringBootDemo/pom.xml
@@ -4,20 +4,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- com.github.xiaour
- springbootv1
- 0.0.1-SNAPSHOT
- SpringBootDemo
- Demo project for Spring Boot
- jar
-
-
+ com.tony
+ com.tony.spring.boot
+ 1.0-SNAPSHOT
org.springframework.boot
spring-boot-starter-parent
1.5.2.RELEASE
-
@@ -85,11 +79,6 @@
javax.servlet
javax.servlet-api
-
-
- com.google.code.gson
- gson
-
commons-codec
@@ -99,13 +88,13 @@
com.alibaba
fastjson
- 1.2.83
+ 1.2.31
commons-io
commons-io
- 2.7
+ 2.5
@@ -116,25 +105,8 @@
org.apache.httpcomponents
httpmime
-
-
-
-
- org.apache.poi
- poi
- 4.1.1
-
-
- org.apache.poi
- poi-ooxml
- 3.13
-
-
- org.apache.poi
- ooxml-schemas
- 1.1
-
-
+
+
diff --git a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/Application.java b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/Application.java
index ba66900..db70642 100644
--- a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/Application.java
+++ b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/Application.java
@@ -1,45 +1,46 @@
-package com.xiaour.spring.boot;
-
-import org.mybatis.spring.annotation.MapperScan;
-import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
-import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
-import org.springframework.boot.web.servlet.ServletComponentScan;
-import org.springframework.boot.web.support.SpringBootServletInitializer;
-
-/**
- *
- * @ClassName Application
- * @author Zhang.Tao
- * @Date 2017年4月27日 下午5:30:34
- * @version V2.0.0
- */
-
-@SpringBootApplication(exclude = MybatisAutoConfiguration.class)
-@ServletComponentScan
-@MapperScan("com.xiaour.spring.boot.mapper")
-public class Application extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer {
-
- @Value("${server.port}")
- private int port;//应用的端口
- /**
- * 启动入口
- * @param args
- */
- public static void main(String ... args){
- SpringApplication.run(Application.class, args);
- }
-
- /**
- * 自定义端口
- */
- @Override
- public void customize(ConfigurableEmbeddedServletContainer container) {
- container.setPort(port);
- }
-
-}
+package com.xiaour.spring.boot;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
+import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
+import org.springframework.boot.web.servlet.ServletComponentScan;
+import org.springframework.boot.web.support.SpringBootServletInitializer;
+
+/**
+ *
+ * @ClassName Application
+ * @author Zhang.Tao
+ * @Date 2017年4月27日 下午5:30:34
+ * @version V2.0.0
+ */
+
+@SpringBootApplication(exclude = MybatisAutoConfiguration.class)
+@ServletComponentScan
+@EnableAutoConfiguration
+@MapperScan("com.xiaour.spring.boot.mapper")
+public class Application extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer {
+
+ @Value("${server.port}")
+ private int port;//应用的端口
+ /**
+ * 启动入口
+ * @param args
+ */
+ public static void main(String ... args){
+ SpringApplication.run(Application.class, args);
+ }
+
+ /**
+ * 自定义端口
+ */
+ @Override
+ public void customize(ConfigurableEmbeddedServletContainer container) {
+ container.setPort(port);
+ }
+
+}
diff --git a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/config/DataBaseConfiguration.java b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/config/DataBaseConfiguration.java
new file mode 100644
index 0000000..ab8d982
--- /dev/null
+++ b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/config/DataBaseConfiguration.java
@@ -0,0 +1,69 @@
+package com.xiaour.spring.boot.config;
+
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.bind.RelaxedPropertyResolver;
+import org.springframework.context.EnvironmentAware;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import com.alibaba.druid.pool.DruidDataSource;
+
+@Configuration
+@EnableTransactionManagement
+public class DataBaseConfiguration implements EnvironmentAware {
+
+ private RelaxedPropertyResolver propertyResolver;
+
+ private static Logger log = LoggerFactory.getLogger(DataBaseConfiguration.class);
+
+
+ /**
+ * 初始化yml配置
+ */
+ @Override
+ public void setEnvironment(Environment env) {
+ this.propertyResolver = new RelaxedPropertyResolver(env, "jdbc.datasource.");
+ }
+
+ /**
+ * 配置数据源
+ * @return
+ */
+ @Bean(name = "dataSource",destroyMethod = "close")
+ public DataSource dataSource() {
+
+ DruidDataSource dataSource = new DruidDataSource();
+ dataSource.setUrl(propertyResolver.getProperty("url"));
+ dataSource.setUsername(propertyResolver.getProperty("username"));//用户名
+ dataSource.setPassword(propertyResolver.getProperty("password"));//密码
+ dataSource.setDriverClassName(propertyResolver.getProperty("driver-class-name"));
+ dataSource.setInitialSize(Integer.parseInt(propertyResolver.getProperty("initialSize")));
+ dataSource.setMaxActive(Integer.parseInt(propertyResolver.getProperty("maxActive")));
+ dataSource.setMinIdle(Integer.parseInt(propertyResolver.getProperty("minIdle")));
+ dataSource.setMaxWait(Integer.parseInt(propertyResolver.getProperty("maxWait")));
+ dataSource.setTimeBetweenEvictionRunsMillis(Integer.parseInt(propertyResolver.getProperty("timeBetweenEvictionRunsMillis")));
+ dataSource.setMinEvictableIdleTimeMillis(Integer.parseInt(propertyResolver.getProperty("minEvictableIdleTimeMillis")));
+ dataSource.setValidationQuery(propertyResolver.getProperty("validationQuery"));
+ dataSource.setTestOnBorrow(Boolean.getBoolean(propertyResolver.getProperty("testOnBorrow")));
+ dataSource.setTestWhileIdle(Boolean.getBoolean(propertyResolver.getProperty("testWhileIdle")));
+ dataSource.setTestOnReturn(Boolean.getBoolean(propertyResolver.getProperty("testOnReturn")));
+ dataSource.setPoolPreparedStatements(Boolean.getBoolean(propertyResolver.getProperty("poolPreparedStatements")));
+ dataSource.setMaxPoolPreparedStatementPerConnectionSize(Integer.parseInt(propertyResolver.getProperty("maxOpenPreparedStatements")));
+ try {
+ //开启druid监控
+ dataSource.setFilters("stat,wall");
+ dataSource.init();
+ } catch (SQLException e) {
+ log.error(e.getMessage());
+ }
+ return dataSource;
+ }
+
+}
diff --git a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/config/MyBatisConfig.java b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/config/MyBatisConfig.java
deleted file mode 100644
index 5b1f78d..0000000
--- a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/config/MyBatisConfig.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.xiaour.spring.boot.config;
-
-import com.alibaba.druid.pool.DruidDataSource;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.mybatis.spring.SqlSessionFactoryBean;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-
-
-/**
- * @Date: 2018-12-26 12:05
- * @version: v1.0
- * @Description: mybatis stater从某个版本后去掉了自动配置,需要用config配置
- */
-@Configuration
-public class MyBatisConfig {
-
- @Autowired
- private DataSourceProperties dataSourceProperties;
-
-
- @Bean(name = "dataSource")
- public DruidDataSource dataSource() {
- DruidDataSource dataSource = new DruidDataSource();
- dataSource.setUrl(dataSourceProperties.getUrl());
-
- dataSource.setDriverClassName(dataSourceProperties.getDriverClassName());
- dataSource.setUsername(dataSourceProperties.getUsername());
- dataSource.setPassword(dataSourceProperties.getPassword());
-
- return dataSource;
-
- }
-
- @Bean
- public SqlSessionFactory sqlSessionFactory() throws Exception {
- SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
- sqlSessionFactoryBean.setDataSource(dataSource());
- sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
- .getResources(("classpath*:mapper/*.xml")));
- return sqlSessionFactoryBean.getObject();
- }
-}
diff --git a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/config/MybatisConfiguration.java b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/config/MybatisConfiguration.java
new file mode 100644
index 0000000..fee3549
--- /dev/null
+++ b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/config/MybatisConfiguration.java
@@ -0,0 +1,75 @@
+package com.xiaour.spring.boot.config;
+
+import javax.annotation.Resource;
+import javax.persistence.EntityManager;
+import javax.sql.DataSource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.mybatis.spring.SqlSessionFactoryBean;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.bind.RelaxedPropertyResolver;
+import org.springframework.context.EnvironmentAware;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+/**
+ * 初始化SqlSessionFactory
+ * @ClassName MybatisConfiguration
+ * @author Zhang.Tao
+ * @Date 2017年4月24日 下午5:24:56
+ * @version V2.0.0
+ */
+@Configuration
+@ConditionalOnClass({ EnableTransactionManagement.class, EntityManager.class })
+@AutoConfigureAfter({ DataBaseConfiguration.class })
+public class MybatisConfiguration implements EnvironmentAware {
+
+ private static Log logger = LogFactory.getLog(MybatisConfiguration.class);
+
+ private RelaxedPropertyResolver propertyResolver;
+
+ @Resource(name = "dataSource")
+ DataSource dataSource;
+
+ @Override
+ public void setEnvironment(Environment environment) {
+ this.propertyResolver = new RelaxedPropertyResolver(environment,"mybatis.");
+ }
+
+ /**
+ * 初始化SessionFactory
+ * @return
+ */
+ @Bean
+ @ConditionalOnMissingBean
+ public SqlSessionFactory sqlSessionFactory() {
+ try {
+
+ SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
+ sessionFactory.setDataSource(dataSource);
+ sessionFactory.setTypeAliasesPackage(propertyResolver.getProperty("typeAliasesPackage"));
+ sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(propertyResolver.getProperty("mapperLocations")));
+ sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(propertyResolver.getProperty("configLocation")));
+
+ return sessionFactory.getObject();
+ } catch (Exception e) {
+ logger.warn("Could not confiure mybatis session factory");
+ return null;
+ }
+ }
+
+ @Bean
+ @ConditionalOnMissingBean
+ public DataSourceTransactionManager transactionManager() {
+ return new DataSourceTransactionManager(dataSource);
+ }
+}
diff --git a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/config/RedisConfig.java b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/config/RedisConfig.java
new file mode 100644
index 0000000..5333733
--- /dev/null
+++ b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/config/RedisConfig.java
@@ -0,0 +1,51 @@
+package com.xiaour.spring.boot.config;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.JedisPoolConfig;
+
+/**
+ * 配置redis数据源
+ * Java Lib For OIS, Powered By xiaour.
+ * @ClassName RedisConfig
+ * @author Zhang.Tao
+ * @Date 2017年4月24日 下午5:25:30
+ * @version V2.0.0
+ */
+@Configuration
+public class RedisConfig {
+ private static Logger log = LoggerFactory.getLogger(RedisConfig.class);
+
+
+ @Bean(name= "jedis.pool")
+ @Autowired
+ public JedisPool jedisPool(@Qualifier("jedis.pool.config") JedisPoolConfig config,
+ @Value("${jedis.pool.host}")String host,
+ @Value("${jedis.pool.port}")int port) {
+ return new JedisPool(config, host, port);
+ }
+
+ @Bean(name= "jedis.pool.config")
+ public JedisPoolConfig jedisPoolConfig (@Value("${jedis.pool.config.maxTotal}")int maxTotal,
+ @Value("${jedis.pool.config.maxIdle}")int maxIdle,
+ @Value("${jedis.pool.config.maxWaitMillis}")int maxWaitMillis) {
+ try {
+ JedisPoolConfig config = new JedisPoolConfig();
+ config.setMaxTotal(maxTotal);
+ config.setMaxIdle(maxIdle);
+ config.setMaxWaitMillis(maxWaitMillis);
+ return config;
+ } catch (Exception e) {
+ log.error(e.getMessage());
+ }
+ return null;
+ }
+
+}
diff --git a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/controller/TestCtrl.java b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/controller/TestCtrl.java
index d7d1807..8526e54 100644
--- a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/controller/TestCtrl.java
+++ b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/controller/TestCtrl.java
@@ -1,10 +1,7 @@
package com.xiaour.spring.boot.controller;
-import com.xiaour.spring.boot.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
-import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -12,11 +9,7 @@
import com.xiaour.spring.boot.entity.UserInfo;
import com.xiaour.spring.boot.mapper.UserInfoMapper;
import com.xiaour.spring.boot.utils.JsonUtil;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import com.xiaour.spring.boot.utils.RedisUtil;
/**
@@ -27,7 +20,7 @@
public class TestCtrl {
@Autowired
- private RedisService redisService;
+ private RedisUtil redisUtil;
@Autowired
private UserInfoMapper userInfoMapper;
@@ -45,9 +38,8 @@ public String index(){
* @throws Exception
*/
@RequestMapping("/set")
- public String set(String key, String value) throws Exception{
-
- redisService.set(key, value);
+ public String set(String key, String value) throws Exception{
+ redisUtil.set(key, value);
return "success";
}
@@ -59,7 +51,7 @@ public String set(String key, String value) throws Exception{
@RequestMapping("/get")
public String get(String key){
try {
- return redisService.get(key);
+ return redisUtil.get(key);
} catch (Exception e) {
e.printStackTrace();
}
@@ -80,63 +72,7 @@ public String get(@PathVariable("id")int id){
e.printStackTrace();
}
return "";
- }
-
-
- public static void main(String[] args) {
- Map keyMap= new HashMap<>();
- keyMap.put("id","编号");
- keyMap.put("name","名称");
-
- String [] cnCloumn={"编号","名称"};
-
- System.out.println(Arrays.asList(convertMap(keyMap, cnCloumn)));
-
- }
-
- public static String[] convertMap(Map keyMap,String [] dataList){
-
- for(int i=0;i m:keyMap.entrySet()){
- if(m.getValue().equals(dataList[i])){
- dataList[i]=m.getKey();
- }
- }
- }
-
- return dataList;
- }
-
-
- public static String getName(String name,String add){
- return null;
- }
-
- public static void testGetClassName() {
- // 方法1:通过SecurityManager的保护方法getClassContext()
- String clazzName = new SecurityManager() {
- public String getClassName() {
- return getClassContext()[1].getName();
- }
- }.getClassName();
- System.out.println(clazzName);
- // 方法2:通过Throwable的方法getStackTrace()
- String clazzName2 = new Throwable().getStackTrace()[1].getClassName();
- System.out.println(clazzName2);
- // 方法3:通过分析匿名类名称()
- String clazzName3 = new Object() {
- public String getClassName() {
- String clazzName = this.getClass().getName();
- return clazzName.substring(0, clazzName.lastIndexOf('$'));
- }
- }.getClassName();
- System.out.println(clazzName3);
- //方法4:通过Thread的方法getStackTrace()
- String clazzName4 = Thread.currentThread().getStackTrace()[2].getClassName();
- System.out.println(clazzName4);
- }
-
-
+ }
+
}
diff --git a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/exception/DingTalkEncryptException.java b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/exception/DingTalkEncryptException.java
new file mode 100644
index 0000000..f279b8e
--- /dev/null
+++ b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/exception/DingTalkEncryptException.java
@@ -0,0 +1,53 @@
+package com.xiaour.spring.boot.exception;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 钉钉开放平台加解密异常类
+ */
+public class DingTalkEncryptException extends Exception {
+ /**成功**/
+ public static final int SUCCESS = 0;
+ /**加密明文文本非法**/
+ public final static int ENCRYPTION_PLAINTEXT_ILLEGAL = 900001;
+ /**加密时间戳参数非法**/
+ public final static int ENCRYPTION_TIMESTAMP_ILLEGAL = 900002;
+ /**加密随机字符串参数非法**/
+ public final static int ENCRYPTION_NONCE_ILLEGAL = 900003;
+ /**不合法的aeskey**/
+ public final static int AES_KEY_ILLEGAL = 900004;
+ /**签名不匹配**/
+ public final static int SIGNATURE_NOT_MATCH = 900005;
+ /**计算签名错误**/
+ public final static int COMPUTE_SIGNATURE_ERROR = 900006;
+ /**计算加密文字错误**/
+ public final static int COMPUTE_ENCRYPT_TEXT_ERROR = 900007;
+ /**计算解密文字错误**/
+ public final static int COMPUTE_DECRYPT_TEXT_ERROR = 900008;
+ /**计算解密文字长度不匹配**/
+ public final static int COMPUTE_DECRYPT_TEXT_LENGTH_ERROR = 900009;
+ /**计算解密文字corpid不匹配**/
+ public final static int COMPUTE_DECRYPT_TEXT_CORPID_ERROR = 900010;
+
+ private static Map msgMap = new HashMap();
+ static{
+ msgMap.put(SUCCESS,"成功");
+ msgMap.put(ENCRYPTION_PLAINTEXT_ILLEGAL,"加密明文文本非法");
+ msgMap.put(ENCRYPTION_TIMESTAMP_ILLEGAL,"加密时间戳参数非法");
+ msgMap.put(ENCRYPTION_NONCE_ILLEGAL,"加密随机字符串参数非法");
+ msgMap.put(SIGNATURE_NOT_MATCH,"签名不匹配");
+ msgMap.put(COMPUTE_SIGNATURE_ERROR,"签名计算失败");
+ msgMap.put(AES_KEY_ILLEGAL,"不合法的aes key");
+ msgMap.put(COMPUTE_ENCRYPT_TEXT_ERROR,"计算加密文字错误");
+ msgMap.put(COMPUTE_DECRYPT_TEXT_ERROR,"计算解密文字错误");
+ msgMap.put(COMPUTE_DECRYPT_TEXT_LENGTH_ERROR,"计算解密文字长度不匹配");
+ msgMap.put(COMPUTE_DECRYPT_TEXT_CORPID_ERROR,"计算解密文字corpid或者suiteKey不匹配");
+ }
+
+ public Integer code;
+ public DingTalkEncryptException(Integer exceptionCode){
+ super(msgMap.get(exceptionCode));
+ this.code = exceptionCode;
+ }
+}
diff --git a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/mapper/UserInfoMapper.java b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/mapper/UserInfoMapper.java
index 50cb43f..9850a58 100644
--- a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/mapper/UserInfoMapper.java
+++ b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/mapper/UserInfoMapper.java
@@ -1,13 +1,9 @@
-package com.xiaour.spring.boot.mapper;
-
-import com.xiaour.spring.boot.entity.UserInfo;
-import org.apache.ibatis.annotations.Mapper;
-import org.springframework.stereotype.Component;
-
-@Component
-@Mapper
-public interface UserInfoMapper {
-
- UserInfo selectByPrimaryKey(Integer id);
-
+package com.xiaour.spring.boot.mapper;
+
+import com.xiaour.spring.boot.entity.UserInfo;
+
+public interface UserInfoMapper {
+
+ UserInfo selectByPrimaryKey(Integer id);
+
}
\ No newline at end of file
diff --git a/SpringBootDemo/src/main/resources/mapper/UserInfoMapper.xml b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/mapper/UserInfoMapper.xml
similarity index 100%
rename from SpringBootDemo/src/main/resources/mapper/UserInfoMapper.xml
rename to SpringBootDemo/src/main/java/com/xiaour/spring/boot/mapper/UserInfoMapper.xml
diff --git a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/service/RedisService.java b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/service/RedisService.java
deleted file mode 100644
index e08e182..0000000
--- a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/service/RedisService.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.xiaour.spring.boot.service;
-
-import java.util.List;
-
-/**
- * Created by zhangtao on 2017/11/8.
- */
-
-public interface RedisService {
-
- boolean set(String key, String value) throws Exception;
-
- String get(String key) throws Exception;
-
- boolean expire(String key, long expire) throws Exception;
-
- boolean setList(String key, List list) throws Exception;
-
- List getList(String key, Class clz) throws Exception;
-
- long lpush(String key, Object obj) throws Exception;
-
- long rpush(String key, Object obj) throws Exception;
-
- void hmset(String key, Object obj) throws Exception;
-
- T hget(String key, Class clz) throws Exception;
-
-
- void del(String key) throws Exception;
-
- List hmGetAll(String key, Class clz) throws Exception;
-
- String lpop(String key) throws Exception;
-}
diff --git a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/service/impl/RedisServiceImpl.java b/SpringBootDemo/src/main/java/com/xiaour/spring/boot/service/impl/RedisServiceImpl.java
deleted file mode 100644
index 3f451d2..0000000
--- a/SpringBootDemo/src/main/java/com/xiaour/spring/boot/service/impl/RedisServiceImpl.java
+++ /dev/null
@@ -1,208 +0,0 @@
-package com.xiaour.spring.boot.service.impl;
-
-
-import com.xiaour.spring.boot.service.RedisService;
-import com.xiaour.spring.boot.utils.JsonUtil;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.dao.DataAccessException;
-import org.springframework.data.redis.connection.RedisConnection;
-import org.springframework.data.redis.core.RedisCallback;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.serializer.RedisSerializer;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.Assert;
-
-import java.util.*;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Created by xiaour.github.com on 2017/11/8.
- */
-@Service("redisService")
-@Transactional(rollbackFor = Exception.class)
-public class RedisServiceImpl implements RedisService {
-
- private static int seconds=3600*24;
-
- @Autowired
- private RedisTemplate redisTemplate;
-
- @Override
- public boolean set(final String key, final String value) throws Exception {
- Assert.hasText(key,"Key is not empty.");
- boolean result = redisTemplate.execute(new RedisCallback() {
- @Override
- public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
- RedisSerializer serializer = redisTemplate.getStringSerializer();
- connection.set(serializer.serialize(key), serializer.serialize(value));
- return true;
- }
- });
- return result;
- }
-
- public String get(final String key) throws Exception {
- Assert.hasText(key,"Key is not empty.");
- String result = redisTemplate.execute(new RedisCallback() {
- @Override
- public String doInRedis(RedisConnection connection) throws DataAccessException {
- RedisSerializer serializer = redisTemplate.getStringSerializer();
- byte[] value = connection.get(serializer.serialize(key));
- return serializer.deserialize(value);
- }
- });
- return result;
- }
-
- public void del(final String key) throws Exception {
- Assert.hasText(key,"Key is not empty.");
-
- redisTemplate.execute(new RedisCallback() {
- @Override
- public Long doInRedis(RedisConnection conn) throws DataAccessException {
- RedisSerializer serializer = redisTemplate.getStringSerializer();
- return conn.del(serializer.serialize(key));
- }
- });
- }
-
-
-
- @Override
- public boolean expire(final String key, long expire) {
- return redisTemplate.expire(key, expire, TimeUnit.SECONDS);
- }
-
- @Override
- public boolean setList(String key, List list) throws Exception {
- Assert.hasText(key,"Key is not empty.");
-
- String value = JsonUtil.getJsonString(list);
- return set(key,value);
- }
-
- @Override
- public List getList(String key,Class clz) throws Exception{
-
- Assert.hasText(key,"Key is not empty.");
-
- String json = get(key);
- if(json!=null){
- List list = JsonUtil.readJson2Array(json,clz);
- return list;
- }
- return null;
- }
-
- @Override
- public long lpush(final String key, Object obj)throws Exception {
- Assert.hasText(key,"Key is not empty.");
-
- final String value = JsonUtil.getJsonString(obj);
- long result = redisTemplate.execute(new RedisCallback() {
- @Override
- public Long doInRedis(RedisConnection connection) throws DataAccessException {
- RedisSerializer serializer = redisTemplate.getStringSerializer();
- long count = connection.lPush(serializer.serialize(key), serializer.serialize(value));
- return count;
- }
- });
- return result;
- }
-
- @Override
- public long rpush(final String key, Object obj) throws Exception{
- Assert.hasText(key,"Key is not empty.");
-
- final String value = JsonUtil.getJsonString(obj);
- long result = redisTemplate.execute(new RedisCallback() {
- @Override
- public Long doInRedis(RedisConnection connection) throws DataAccessException {
- RedisSerializer serializer = redisTemplate.getStringSerializer();
- long count = connection.rPush(serializer.serialize(key), serializer.serialize(value));
- return count;
- }
- });
- return result;
- }
-
- @Override
- public void hmset(String key, Object obj) throws Exception{
- Assert.hasText(key,"Key is not empty.");
-
- Map data=JsonUtil.readJsonByteMap(JsonUtil.getJsonString(obj));
- redisTemplate.execute(new RedisCallback() {
- @Override
- public String doInRedis(RedisConnection connection) throws DataAccessException {
- RedisSerializer serializer = redisTemplate.getStringSerializer();
- connection.hMSet(serializer.serialize(key),data);
- return "";
- }
- });
- }
-
- @Override
- public T hget(String key, Class clz) throws Exception{
- Assert.hasText(key,"Key is not empty.");
-
- return redisTemplate.execute(new RedisCallback() {
-
- @Override
- public T doInRedis(RedisConnection connection) throws DataAccessException {
- RedisSerializer serializer = redisTemplate.getStringSerializer();
-
- Map result;
-
- Map data=connection.hGetAll(serializer.serialize(key));
- result= new HashMap<>();
- for (Map.Entry entry: data.entrySet()) {
- result.put(serializer.deserialize(entry.getKey()),serializer.deserialize(entry.getValue()));
- }
-
- return JsonUtil.json2Obj(JsonUtil.getJsonString(result),clz);
- }
- });
- }
-
- @Override
- public List hmGetAll(String key,Class clz) throws Exception{
- Assert.hasText(key,"Key is not empty.");
-
- List