diff --git a/spring-boot-demo-actuator/README.md b/spring-boot-demo-actuator/README.md deleted file mode 100644 index b622e14..0000000 --- a/spring-boot-demo-actuator/README.md +++ /dev/null @@ -1,106 +0,0 @@ -# spring-boot-demo-actuator - -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent)、spring-boot-starter-actuator - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-actuator - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-actuator - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - org.springframework.boot - spring-boot-starter-actuator - - - - - spring-boot-demo-actuator - - - -``` - -### application.yml - -```yml -server: - port: 8080 - context-path: /demo -# actuator 配置 -management: - security: - # 关闭 actuator 的身份验证 - enabled: false - # 配置 actuator 的访问路径前缀 - context-path: /sys - # actuator暴露接口使用的端口,为了和api接口使用的端口进行分离 - port: 1111 -``` - -### actuator 提供的端点信息 - -| 端点 | 描述 | HTTP 方法 | -| ----------- | ---------------------------------------- | ------- | -| autoconfig | 显示自动配置的信息 | GET | -| beans | 显示应用程序上下文所有的Spring bean | GET | -| configprops | 显示所有 `@ConfigurationProperties` 的配置属性列表 | GET | -| dump | 显示线程活动的快照 | GET | -| env | 显示应用的环境变量 | GET | -| health | 显示应用程序的健康指标,这些值由HealthIndicator的实现类提供。常见取值:`UP` / `DOWN` / `UNKNOWN` / `OUT_OF_SERVICE` | GET | -| info | 显示应用的信息,可使用 `info.*` 属性自定义info端点公开的数据 | GET | -| mappings | 显示所有的URL路径 | GET | -| metrics | 显示应用的度量标准信息 | GET | -| shutdown | 关闭应用(默认情况下不启用,如需启用,需设置`endpoints.shutdown.enabled=true`) | POST | -| trace | 显示跟踪信息(默认情况下为最近100个HTTP请求) | GET | - -### actuator 的访问权限 - -#### 方法一:(本 demo 中使用的是这种) - -```yaml -management: - security: - enabled: false -``` - -#### 方法二: - -pom.xml 中添加以下 `spring-boot-starter-security` 依赖: - -```xml - - org.springframework.boot - spring-boot-starter-security - -``` - -并在 `application.yml` 文件中设置访问的密码 - -```yaml -security: - basic: - enabled: true - user: - name: user - password: 123 -``` - -如果不设置,则用户名是 user,密码是一个随机值,在启动时会在控制台打印。 \ No newline at end of file diff --git a/spring-boot-demo-actuator/pom.xml b/spring-boot-demo-actuator/pom.xml deleted file mode 100644 index 07e98fe..0000000 --- a/spring-boot-demo-actuator/pom.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-actuator - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-actuator - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - org.springframework.boot - spring-boot-starter-actuator - - - - - spring-boot-demo-actuator - - - diff --git a/spring-boot-demo-actuator/src/main/java/com/xkcoding/springbootdemoactuator/SpringBootDemoActuatorApplication.java b/spring-boot-demo-actuator/src/main/java/com/xkcoding/springbootdemoactuator/SpringBootDemoActuatorApplication.java deleted file mode 100644 index 71b9fcf..0000000 --- a/spring-boot-demo-actuator/src/main/java/com/xkcoding/springbootdemoactuator/SpringBootDemoActuatorApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.xkcoding.springbootdemoactuator; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringBootDemoActuatorApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoActuatorApplication.class, args); - } -} diff --git a/spring-boot-demo-actuator/src/main/resources/application.yml b/spring-boot-demo-actuator/src/main/resources/application.yml deleted file mode 100644 index 46e977e..0000000 --- a/spring-boot-demo-actuator/src/main/resources/application.yml +++ /dev/null @@ -1,12 +0,0 @@ -server: - port: 8080 - context-path: /demo -# actuator 配置 -management: - security: - # 关闭 actuator 的身份验证 - enabled: false - # 配置 actuator 的访问路径前缀 - context-path: /sys - # actuator暴露接口使用的端口,为了和api接口使用的端口进行分离 - port: 1111 \ No newline at end of file diff --git a/spring-boot-demo-actuator/src/test/java/com/xkcoding/springbootdemoactuator/SpringBootDemoActuatorApplicationTests.java b/spring-boot-demo-actuator/src/test/java/com/xkcoding/springbootdemoactuator/SpringBootDemoActuatorApplicationTests.java deleted file mode 100644 index 752f6fe..0000000 --- a/spring-boot-demo-actuator/src/test/java/com/xkcoding/springbootdemoactuator/SpringBootDemoActuatorApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemoactuator; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoActuatorApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-admin/README.md b/spring-boot-demo-admin/README.md deleted file mode 100644 index 310e020..0000000 --- a/spring-boot-demo-admin/README.md +++ /dev/null @@ -1,103 +0,0 @@ -# spring-boot-demo-admin - -依赖[spring-boot-demo-parent](../spring-boot-demo-parent)、服务端依赖 `spring-boot-demo-admin` 和 `spring-boot-admin-server-ui`、客户端依赖 `spring-boot-admin-starter-client` - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-admin - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-admin - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - 1.5.2 - 1.5.2 - 1.5.2 - - - - - de.codecentric - spring-boot-admin-server - ${admin.server.version} - - - de.codecentric - spring-boot-admin-server-ui - ${admin.server.ui.version} - - - de.codecentric - spring-boot-admin-starter-client - ${admin.client.version} - - - - - spring-boot-demo-admin - - - -``` - -### application.yml - -```yaml -server: - port: 8080 - context-path: /demo -spring: - application: - # 可视化管控台展示的监控项目名,不设置,会使用自动生成的名字 - name: Spring Boot Admin - boot: - admin: - # 可视化管控台界面的 context-path - context-path: /spa - url: http://localhost:${server.port}/${server.context-path} - jackson: - serialization: true -# 去除权限校验 -endpoints: - sensitive: false -``` - -### SpringBootDemoAdminApplication.java - -```java -@SpringBootApplication -@EnableAdminServer // 开启管控台 -@RestController -public class SpringBootDemoAdminApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoAdminApplication.class, args); - } - - @GetMapping("/") - public Map index() { - ConcurrentMap ret = Maps.newConcurrentMap(); - ret.put("msg", "Hello Spring Boot Admin"); - return ret; - } -} -``` - -### 访问 - -http://localhost:8080/demo/spa 即可查看管控台主页,点击项目的 `Detail` 即可查看详细信息,但是比起 `actuator` 提供的端点监控,看起来确实美观不少,但是都各有优缺点。 \ No newline at end of file diff --git a/spring-boot-demo-admin/pom.xml b/spring-boot-demo-admin/pom.xml deleted file mode 100644 index 8d083d9..0000000 --- a/spring-boot-demo-admin/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-admin - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-admin - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - 1.5.2 - 1.5.2 - 1.5.2 - - - - - de.codecentric - spring-boot-admin-server - ${admin.server.version} - - - de.codecentric - spring-boot-admin-server-ui - ${admin.server.ui.version} - - - de.codecentric - spring-boot-admin-starter-client - ${admin.client.version} - - - - - spring-boot-demo-admin - - - \ No newline at end of file diff --git a/spring-boot-demo-admin/src/main/java/com/xkcoding/springbootdemoadmin/SpringBootDemoAdminApplication.java b/spring-boot-demo-admin/src/main/java/com/xkcoding/springbootdemoadmin/SpringBootDemoAdminApplication.java deleted file mode 100644 index 1200964..0000000 --- a/spring-boot-demo-admin/src/main/java/com/xkcoding/springbootdemoadmin/SpringBootDemoAdminApplication.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.xkcoding.springbootdemoadmin; - -import com.google.common.collect.Maps; -import de.codecentric.boot.admin.config.EnableAdminServer; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Map; -import java.util.concurrent.ConcurrentMap; - -@SpringBootApplication -@EnableAdminServer // 开启管控台 -@RestController -public class SpringBootDemoAdminApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoAdminApplication.class, args); - } - - @GetMapping("/") - public Map index() { - ConcurrentMap ret = Maps.newConcurrentMap(); - ret.put("msg", "Hello Spring Boot Admin"); - return ret; - } -} diff --git a/spring-boot-demo-admin/src/main/resources/application.yml b/spring-boot-demo-admin/src/main/resources/application.yml deleted file mode 100644 index 20bc0a9..0000000 --- a/spring-boot-demo-admin/src/main/resources/application.yml +++ /dev/null @@ -1,17 +0,0 @@ -server: - port: 8080 - context-path: /demo -spring: - application: - # 可视化管控台展示的监控项目名,不设置,会使用自动生成的名字 - name: Spring Boot Admin - boot: - admin: - # 可视化管控台界面的 context-path - context-path: /spa - url: http://localhost:${server.port}/${server.context-path} - jackson: - serialization: true -# 去除权限校验 -endpoints: - sensitive: false \ No newline at end of file diff --git a/spring-boot-demo-admin/src/test/java/com/xkcoding/springbootdemoadmin/SpringBootDemoAdminApplicationTests.java b/spring-boot-demo-admin/src/test/java/com/xkcoding/springbootdemoadmin/SpringBootDemoAdminApplicationTests.java deleted file mode 100644 index 053981a..0000000 --- a/spring-boot-demo-admin/src/test/java/com/xkcoding/springbootdemoadmin/SpringBootDemoAdminApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemoadmin; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoAdminApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-aoplog/README.md b/spring-boot-demo-aoplog/README.md deleted file mode 100644 index 42af1b0..0000000 --- a/spring-boot-demo-aoplog/README.md +++ /dev/null @@ -1,168 +0,0 @@ -# spring-boot-demo-aoplog - -依赖[spring-boot-demo-parent](../spring-boot-demo-parent)、`spring-boot-starter-aop` - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-aoplog - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-aoplog - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - 1.20 - - - - - org.springframework.boot - spring-boot-starter-aop - - - - eu.bitwalker - UserAgentUtils - ${useragent.version} - - - - - spring-boot-demo-aoplog - - - -``` - -### AopLog.java - -```java -/** - * aop 切面记录请求日志 - * - * @package: com.xkcoding.springbootdemoaoplog.aspectj - * @description:aop 切面记录请求日志 - * @author: yangkai.shen - * @date: Created in 2017/11/24 上午9:43 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Aspect -@Component -@Slf4j -public class AopLog { - private static final String START_TIME = "start-request"; - - @Pointcut("execution(public * com.xkcoding.springbootdemoaoplog.controller.*Controller.*(..))") - public void log() { - } - - @Before("log()") - public void beforeLog(JoinPoint joinPoint) { - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = attributes.getRequest(); - - log.info("【请求 URL】:{}", request.getRequestURL()); - log.info("【请求 IP】:{}", request.getRemoteAddr()); - log.info("【请求类名】:{},【请求方法名】:{}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName()); - Map parameterMap = request.getParameterMap(); - log.info("【请求参数】:{},", JsonMapper.obj2Str(parameterMap)); - Long start = System.currentTimeMillis(); - request.setAttribute(START_TIME, start); - } - - @Around("log()") - public Object arroundLog(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { - Object result = proceedingJoinPoint.proceed(); - log.info("【返回值】:{}", JsonMapper.obj2Str(result)); - return result; - } - - @AfterReturning("log()") - public void afterReturning(JoinPoint joinPoint) { - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = attributes.getRequest(); - Long start = (Long) request.getAttribute(START_TIME); - Long end = System.currentTimeMillis(); - log.info("【请求耗时】:{}毫秒", end - start); - String header = request.getHeader("User-Agent"); - UserAgent userAgent = UserAgent.parseUserAgentString(header); - log.info("【浏览器类型】:{},【操作系统】:{},【原始User-Agent】:{}", userAgent.getBrowser().toString(), userAgent.getOperatingSystem().toString(), header); - } -} -``` - -### JsonMapper.java - -```java -/** - * Json 转化工具类 - * - * @package: com.xkcoding.springbootdemoaoplog.util - * @description:Json 转化工具类 - * @author: yangkai.shen - * @date: Created in 2017/11/24 上午9:36 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Slf4j -public class JsonMapper { - private static ObjectMapper objectMapper = new ObjectMapper(); - - /** - * 对象转 json 字符串 - * - * @param src 元对象 - * @param 类型 - * @return json 字符串 - */ - public static String obj2Str(T src) { - if (src == null) { - return null; - } - try { - return src instanceof String ? (String) src : objectMapper.writeValueAsString(src); - } catch (IOException e) { - log.error("【JSON 转换:对象 --> 字符串】,异常堆栈:{}", e); - return null; - } - } - - /** - * json 字符串转化为对象 - * - * @param src 源 json 字符串 - * @param typeReference 转化后的类型 - * @param 类型 - * @return 返回转化后的对象 - */ - public static T str2Obj(String src, TypeReference typeReference) { - if (src == null || typeReference == null) { - return null; - } - try { - return (T) (typeReference.getType().equals(String.class) ? src : objectMapper.readValue(src, typeReference)); - } catch (Exception e) { - log.error("【JSON 转换:字符串 --> 对象】,异常堆栈:{}", e); - return null; - } - } -} -``` - diff --git a/spring-boot-demo-aoplog/pom.xml b/spring-boot-demo-aoplog/pom.xml deleted file mode 100644 index cc363f9..0000000 --- a/spring-boot-demo-aoplog/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-aoplog - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-aoplog - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - 1.20 - - - - - org.springframework.boot - spring-boot-starter-aop - - - - eu.bitwalker - UserAgentUtils - ${useragent.version} - - - - - spring-boot-demo-aoplog - - - \ No newline at end of file diff --git a/spring-boot-demo-aoplog/src/main/java/com/xkcoding/springbootdemoaoplog/SpringBootDemoAoplogApplication.java b/spring-boot-demo-aoplog/src/main/java/com/xkcoding/springbootdemoaoplog/SpringBootDemoAoplogApplication.java deleted file mode 100644 index 3be9089..0000000 --- a/spring-boot-demo-aoplog/src/main/java/com/xkcoding/springbootdemoaoplog/SpringBootDemoAoplogApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.xkcoding.springbootdemoaoplog; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringBootDemoAoplogApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoAoplogApplication.class, args); - } -} diff --git a/spring-boot-demo-aoplog/src/main/java/com/xkcoding/springbootdemoaoplog/aspectj/AopLog.java b/spring-boot-demo-aoplog/src/main/java/com/xkcoding/springbootdemoaoplog/aspectj/AopLog.java deleted file mode 100644 index 41b7551..0000000 --- a/spring-boot-demo-aoplog/src/main/java/com/xkcoding/springbootdemoaoplog/aspectj/AopLog.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.xkcoding.springbootdemoaoplog.aspectj; - -import com.xkcoding.springbootdemoaoplog.util.JsonMapper; -import eu.bitwalker.useragentutils.UserAgent; -import lombok.extern.slf4j.Slf4j; -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.*; -import org.springframework.stereotype.Component; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -import javax.servlet.http.HttpServletRequest; -import java.util.Map; - -/** - * aop 切面记录请求日志 - * - * @package: com.xkcoding.springbootdemoaoplog.aspectj - * @description:aop 切面记录请求日志 - * @author: yangkai.shen - * @date: Created in 2017/11/24 上午9:43 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Aspect -@Component -@Slf4j -public class AopLog { - private static final String START_TIME = "start-request"; - - @Pointcut("execution(public * com.xkcoding.springbootdemoaoplog.controller.*Controller.*(..))") - public void log() { - } - - @Before("log()") - public void beforeLog(JoinPoint joinPoint) { - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = attributes.getRequest(); - - log.info("【请求 URL】:{}", request.getRequestURL()); - log.info("【请求 IP】:{}", request.getRemoteAddr()); - log.info("【请求类名】:{},【请求方法名】:{}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName()); - Map parameterMap = request.getParameterMap(); - log.info("【请求参数】:{},", JsonMapper.obj2Str(parameterMap)); - Long start = System.currentTimeMillis(); - request.setAttribute(START_TIME, start); - } - - @Around("log()") - public Object arroundLog(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { - Object result = proceedingJoinPoint.proceed(); - log.info("【返回值】:{}", JsonMapper.obj2Str(result)); - return result; - } - - @AfterReturning("log()") - public void afterReturning(JoinPoint joinPoint) { - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = attributes.getRequest(); - Long start = (Long) request.getAttribute(START_TIME); - Long end = System.currentTimeMillis(); - log.info("【请求耗时】:{}毫秒", end - start); - String header = request.getHeader("User-Agent"); - UserAgent userAgent = UserAgent.parseUserAgentString(header); - log.info("【浏览器类型】:{},【操作系统】:{},【原始User-Agent】:{}", userAgent.getBrowser().toString(), userAgent.getOperatingSystem().toString(), header); - } -} diff --git a/spring-boot-demo-aoplog/src/main/java/com/xkcoding/springbootdemoaoplog/controller/IndexController.java b/spring-boot-demo-aoplog/src/main/java/com/xkcoding/springbootdemoaoplog/controller/IndexController.java deleted file mode 100644 index 70a0dc8..0000000 --- a/spring-boot-demo-aoplog/src/main/java/com/xkcoding/springbootdemoaoplog/controller/IndexController.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.xkcoding.springbootdemoaoplog.controller; - -import com.google.common.collect.Maps; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Map; -import java.util.concurrent.ConcurrentMap; - -/** - * IndexController - * - * @package: com.xkcoding.springbootdemoaoplog.controller - * @description:IndexController - * @author: yangkai.shen - * @date: Created in 2017/11/24 上午9:36 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Slf4j -@RestController -public class IndexController { - - @GetMapping({"", ""}) - public String index() { - return "index"; - } - - @GetMapping({"/test"}) - public Map test(@RequestParam String name) { - ConcurrentMap ret = Maps.newConcurrentMap(); - ret.put("name", name); - return ret; - } -} diff --git a/spring-boot-demo-aoplog/src/main/java/com/xkcoding/springbootdemoaoplog/util/JsonMapper.java b/spring-boot-demo-aoplog/src/main/java/com/xkcoding/springbootdemoaoplog/util/JsonMapper.java deleted file mode 100644 index a4f12c8..0000000 --- a/spring-boot-demo-aoplog/src/main/java/com/xkcoding/springbootdemoaoplog/util/JsonMapper.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.xkcoding.springbootdemoaoplog.util; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; - -import java.io.IOException; - -/** - * Json 转化工具类 - * - * @package: com.xkcoding.springbootdemoaoplog.util - * @description:Json 转化工具类 - * @author: yangkai.shen - * @date: Created in 2017/11/24 上午9:36 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Slf4j -public class JsonMapper { - private static ObjectMapper objectMapper = new ObjectMapper(); - - /** - * 对象转 json 字符串 - * - * @param src 元对象 - * @param 类型 - * @return json 字符串 - */ - public static String obj2Str(T src) { - if (src == null) { - return null; - } - try { - return src instanceof String ? (String) src : objectMapper.writeValueAsString(src); - } catch (IOException e) { - log.error("【JSON 转换:对象 --> 字符串】,异常堆栈:{}", e); - return null; - } - } - - /** - * json 字符串转化为对象 - * - * @param src 源 json 字符串 - * @param typeReference 转化后的类型 - * @param 类型 - * @return 返回转化后的对象 - */ - public static T str2Obj(String src, TypeReference typeReference) { - if (src == null || typeReference == null) { - return null; - } - try { - return (T) (typeReference.getType().equals(String.class) ? src : objectMapper.readValue(src, typeReference)); - } catch (Exception e) { - log.error("【JSON 转换:字符串 --> 对象】,异常堆栈:{}", e); - return null; - } - } -} diff --git a/spring-boot-demo-aoplog/src/main/resources/application.yml b/spring-boot-demo-aoplog/src/main/resources/application.yml deleted file mode 100644 index 3cae10b..0000000 --- a/spring-boot-demo-aoplog/src/main/resources/application.yml +++ /dev/null @@ -1,3 +0,0 @@ -server: - port: 8080 - context-path: /demo \ No newline at end of file diff --git a/spring-boot-demo-aoplog/src/test/java/com/xkcoding/springbootdemoaoplog/SpringBootDemoAoplogApplicationTests.java b/spring-boot-demo-aoplog/src/test/java/com/xkcoding/springbootdemoaoplog/SpringBootDemoAoplogApplicationTests.java deleted file mode 100644 index 56b91a5..0000000 --- a/spring-boot-demo-aoplog/src/test/java/com/xkcoding/springbootdemoaoplog/SpringBootDemoAoplogApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemoaoplog; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoAoplogApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-cache-redis/README.md b/spring-boot-demo-cache-redis/README.md deleted file mode 100644 index 00b8106..0000000 --- a/spring-boot-demo-cache-redis/README.md +++ /dev/null @@ -1,172 +0,0 @@ -# spring-boot-demo-cache-redis - -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent)、`spring-boot-starter-data-redis` - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-cache-redis - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-cache-redis - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - org.springframework.boot - spring-boot-starter-data-redis - - - - - spring-boot-demo-cache-redis - - - -``` - -### application.yml - -```yaml -server: - port: 8080 - context-path: /demo -spring: - redis: - host: localhost - port: 6379 -``` - -### SpringBootDemoCacheRedisApplication.java (开启使用缓存注解) - -```java -@SpringBootApplication -@EnableCaching -public class SpringBootDemoCacheRedisApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoCacheRedisApplication.class, args); - } -} -``` - -### User.java (一定要序列化!) - -```java -@Data -public class User implements Serializable { - private static final long serialVersionUID = 1442134563392432775L; - private Long id; - private String name; - private Date birthDay; -} -``` - -### UserController.java - -```java -@RestController -@RequestMapping("/user") -@CacheConfig(cacheNames = "users") // 整体配置缓存的名称 -public class UserController { - - @Autowired - private UserService userService; - - @GetMapping({"", "/"}) - @Cacheable - public List index() { - return userService.find(); - } - - @GetMapping("/find/{id}") - @Cacheable(key = "#id", condition = "#id != null") // #id 以及 condition 里的语法是 SpEL 语法 - public User find(@PathVariable Long id) { - return userService.find(id); - } - - @GetMapping("/find") - @Cacheable(key = "#name", condition = "#name != null") - public User find(@RequestParam String name) { - return userService.find(name); - } - - @GetMapping("/save") - @CacheEvict(allEntries = true, beforeInvocation = true) //@CacheEvict 清空缓存 - public User save() { - return userService.save(); - } - - @GetMapping("/update/{id}") - @CacheEvict(allEntries = true, beforeInvocation = true) - public User update(@PathVariable Long id) { - return userService.update(id); - } - - @GetMapping("/delete/{id}") - @CacheEvict(allEntries = true, beforeInvocation = true) - public String delete(@PathVariable Long id) { - User user = userService.delete(id); - if (user == null) { - return "用户不存在"; - } else { - return user.getName() + "删除成功"; - } - } -} -``` - -### 其余 Service、Dao 代码(采用 List 存储,只为了演示启用 cache 后,是否仍会进入对应的 method) - -详情请参见本demo。 - -### 缓存 @Annotation 详解 - -#### @CacheConfig - -用于统一配置缓存的基本信息 - -#### @Cacheable - -将返回的结果缓存,该注解里的参数如下 - -| 参数 | 作用 | 示例 | -| --------- | ---------------------------------------- | ---------------------------------------- | -| value | 缓存的名称,在 spring 配置文件中定义,必须指定至少一个 | 例如:@Cacheable(value=”mycache”) 或者 @Cacheable(value={”cache1”,”cache2”} | -| key | 缓存的 key,可以为空,如果指定要按照 SpEL 表达式编写,如果不指定,则缺省按照方法的所有参数进行组合 | 例如:@Cacheable(value=”testcache”,key=”#userName”) | -| condition | 缓存的条件,可以为空,使用 SpEL 编写,返回 true 或者 false,只有为 true 才进行缓存 | 例如:@Cacheable(value=”testcache”,condition=”#userName.length()>2”) | - -#### @CacheEvict - -能够根据一定的条件对缓存进行清空,该注解里的参数如下 - -| 参数 | 作用 | 示例 | -| ---------------- | ---------------------------------------- | ---------------------------------------- | -| value | 缓存的名称,在 spring 配置文件中定义,必须指定至少一个 | 例如:@CachEvict(value=”mycache”) 或者 @CachEvict(value={”cache1”,”cache2”} | -| key | 缓存的 key,可以为空,如果指定要按照 SpEL 表达式编写,如果不指定,则缺省按照方法的所有参数进行组合 | 例如:@CachEvict(value=”testcache”,key=”#userName”) | -| condition | 缓存的条件,可以为空,使用 SpEL 编写,返回 true 或者 false,只有为 true 才清空缓存 | 例如:@CachEvict(value=”testcache”,condition=”#userName.length()>2”) | -| allEntries | 是否清空所有缓存内容,缺省为 false,如果指定为 true,则方法调用后将立即清空所有缓存 | 例如:@CachEvict(value=”testcache”,allEntries=true) | -| beforeInvocation | 是否在方法执行前就清空,缺省为 false,如果指定为 true,则在方法还没有执行的时候就清空缓存,缺省情况下,如果方法执行抛出异常,则不会清空缓存 | 例如:@CachEvict(value=”testcache”,beforeInvocation=true) | - -#### @CachePut - -能够根据方法的请求参数对其结果进行缓存,和 `@Cacheable` 不同的是,它每次都会触发真实方法的调用 - -| 参数 | 作用 | 示例 | -| --------- | ---------------------------------------- | ---------------------------------------- | -| value | 缓存的名称,在 spring 配置文件中定义,必须指定至少一个 | 例如:@Cacheable(value=”mycache”) 或者 @Cacheable(value={”cache1”,”cache2”} | -| key | 缓存的 key,可以为空,如果指定要按照 SpEL 表达式编写,如果不指定,则缺省按照方法的所有参数进行组合 | 例如:@Cacheable(value=”testcache”,key=”#userName”) | -| condition | 缓存的条件,可以为空,使用 SpEL 编写,返回 true 或者 false,只有为 true 才进行缓存 | 例如:@Cacheable(value=”testcache”,condition=”#userName.length()>2”) | \ No newline at end of file diff --git a/spring-boot-demo-cache-redis/pom.xml b/spring-boot-demo-cache-redis/pom.xml deleted file mode 100644 index 2cd2846..0000000 --- a/spring-boot-demo-cache-redis/pom.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-cache-redis - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-cache-redis - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - org.springframework.boot - spring-boot-starter-data-redis - - - - - spring-boot-demo-cache-redis - - - diff --git a/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/SpringBootDemoCacheRedisApplication.java b/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/SpringBootDemoCacheRedisApplication.java deleted file mode 100644 index 5658cd2..0000000 --- a/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/SpringBootDemoCacheRedisApplication.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.xkcoding.springbootdemocacheredis; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cache.annotation.EnableCaching; - -@SpringBootApplication -@EnableCaching -public class SpringBootDemoCacheRedisApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoCacheRedisApplication.class, args); - } -} diff --git a/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/controller/UserController.java b/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/controller/UserController.java deleted file mode 100644 index 2c69df4..0000000 --- a/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/controller/UserController.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.xkcoding.springbootdemocacheredis.controller; - -import com.xkcoding.springbootdemocacheredis.entity.User; -import com.xkcoding.springbootdemocacheredis.service.UserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.CacheConfig; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequestMapping("/user") -@CacheConfig(cacheNames = "users") // 整体配置缓存的名称 -public class UserController { - - @Autowired - private UserService userService; - - @GetMapping({"", "/"}) - @Cacheable - public List index() { - return userService.find(); - } - - @GetMapping("/find/{id}") - @Cacheable(key = "#id", condition = "#id != null") // #id 以及 condition 里的语法是 SpEL 语法 - public User find(@PathVariable Long id) { - return userService.find(id); - } - - @GetMapping("/find") - @Cacheable(key = "#name", condition = "#name != null") - public User find(@RequestParam String name) { - return userService.find(name); - } - - @GetMapping("/save") - @CacheEvict(allEntries = true, beforeInvocation = true) //@CacheEvict 清空缓存 - public User save() { - return userService.save(); - } - - @GetMapping("/update/{id}") - @CacheEvict(allEntries = true, beforeInvocation = true) - public User update(@PathVariable Long id) { - return userService.update(id); - } - - @GetMapping("/delete/{id}") - @CacheEvict(allEntries = true, beforeInvocation = true) - public String delete(@PathVariable Long id) { - User user = userService.delete(id); - if (user == null) { - return "用户不存在"; - } else { - return user.getName() + "删除成功"; - } - } -} diff --git a/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/dao/UserDao.java b/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/dao/UserDao.java deleted file mode 100644 index cf8a02c..0000000 --- a/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/dao/UserDao.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.xkcoding.springbootdemocacheredis.dao; - -import com.google.common.collect.Lists; -import com.xkcoding.springbootdemocacheredis.entity.User; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -import java.util.Date; -import java.util.List; -import java.util.concurrent.atomic.AtomicLong; - -@Slf4j -@Component -public class UserDao { - private static List users = Lists.newArrayList(); - private static AtomicLong SEQ = new AtomicLong(0L); - - public User save() { - log.info("save....."); - User user = new User(); - user.setId(SEQ.get()); - user.setName("xkcoding" + SEQ.get()); - user.setBirthDay(new Date()); - users.add(user); - SEQ.getAndIncrement(); - return user; - } - - public User update(Long id) { - log.info("update....."); - for (User user1 : users) { - if (user1.getId().equals(id)) { - user1.setName("修改后的名字"); - return user1; - } - } - return null; - } - - public User delete(Long id) { - log.info("delete....."); - User user = find(id); - users.remove(user); - return user; - } - - public List find() { - log.info("findAll....."); - return users; - } - - public User find(String name) { - log.info("findByName....."); - for (User user : users) { - if (user.getName().equals(name)) { - return user; - } - } - return null; - } - - public User find(Long id) { - log.info("findById....."); - for (User user : users) { - if (user.getId().equals(id)) { - return user; - } - } - return null; - } -} diff --git a/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/entity/User.java b/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/entity/User.java deleted file mode 100644 index ca8f46f..0000000 --- a/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/entity/User.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.xkcoding.springbootdemocacheredis.entity; - -import lombok.Data; - -import java.io.Serializable; -import java.util.Date; - -@Data -public class User implements Serializable { - private static final long serialVersionUID = 1442134563392432775L; - private Long id; - private String name; - private Date birthDay; -} diff --git a/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/service/UserService.java b/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/service/UserService.java deleted file mode 100644 index 7565d9e..0000000 --- a/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/service/UserService.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.xkcoding.springbootdemocacheredis.service; - -import com.xkcoding.springbootdemocacheredis.entity.User; - -import java.util.List; - -public interface UserService { - User save(); - - User update(Long id); - - User delete(Long id); - - List find(); - - User find(Long id); - - User find(String name); -} diff --git a/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/service/impl/UserServiceImpl.java b/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/service/impl/UserServiceImpl.java deleted file mode 100644 index 5e1121c..0000000 --- a/spring-boot-demo-cache-redis/src/main/java/com/xkcoding/springbootdemocacheredis/service/impl/UserServiceImpl.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.xkcoding.springbootdemocacheredis.service.impl; - -import com.xkcoding.springbootdemocacheredis.dao.UserDao; -import com.xkcoding.springbootdemocacheredis.entity.User; -import com.xkcoding.springbootdemocacheredis.service.UserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.CacheConfig; -import org.springframework.cache.annotation.CachePut; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -public class UserServiceImpl implements UserService { - @Autowired - private UserDao userDao; - - @Override - public User save() { - return userDao.save(); - } - - @Override - public User update(Long id) { - return userDao.update(id); - } - - @Override - public User delete(Long id) { - return userDao.delete(id); - } - - @Override - public List find() { - return userDao.find(); - } - - @Override - public User find(Long id) { - return userDao.find(id); - } - - @Override - public User find(String name) { - return userDao.find(name); - } -} diff --git a/spring-boot-demo-cache-redis/src/main/resources/application.yml b/spring-boot-demo-cache-redis/src/main/resources/application.yml deleted file mode 100644 index a3e2c1c..0000000 --- a/spring-boot-demo-cache-redis/src/main/resources/application.yml +++ /dev/null @@ -1,7 +0,0 @@ -server: - port: 8080 - context-path: /demo -spring: - redis: - host: localhost - port: 6379 \ No newline at end of file diff --git a/spring-boot-demo-cache-redis/src/test/java/com/xkcoding/springbootdemocacheredis/SpringBootDemoCacheRedisApplicationTests.java b/spring-boot-demo-cache-redis/src/test/java/com/xkcoding/springbootdemocacheredis/SpringBootDemoCacheRedisApplicationTests.java deleted file mode 100644 index 98915c9..0000000 --- a/spring-boot-demo-cache-redis/src/test/java/com/xkcoding/springbootdemocacheredis/SpringBootDemoCacheRedisApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemocacheredis; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoCacheRedisApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-dubbo-parent/.gitignore b/spring-boot-demo-dubbo-parent/.gitignore deleted file mode 100644 index 82eca33..0000000 --- a/spring-boot-demo-dubbo-parent/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/build/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ \ No newline at end of file diff --git a/spring-boot-demo-dubbo-parent/README.md b/spring-boot-demo-dubbo-parent/README.md deleted file mode 100644 index 89a218b..0000000 --- a/spring-boot-demo-dubbo-parent/README.md +++ /dev/null @@ -1,118 +0,0 @@ -# spring-boot-demo-dubbo-parent - -依赖 [非官方的spring-boot-starter-dubbo](https://gitee.com/reger/spring-boot-starter-dubbo) - -更新 springboot 版本为 2.0.1.RELEASE - -本身是个父依赖,包含了3个 module - -### 各 Module 介绍 - -| 名称 | 作用 | -| :----------------------------------------------------------- | :-------------------------------------- | -| [spring-boot-demo-dubbo-api](./spring-boot-demo-dubbo-api/pom.xml) | Spring Boot 与 Dubbo 整合抽取的服务接口 | -| [spring-boot-demo-dubbo-provider](./spring-boot-demo-dubbo-provider/pom.xml) | Spring Boot 与 Dubbo 整合服务的提供方 | -| [spring-boot-demo-dubbo-consumer](./spring-boot-demo-dubbo-consumer/pom.xml) | Spring Boot 与 Dubbo 整合服务的消费方 | - -### pom.xml - -```xml - - - 4.0.0 - - com.xkcoding - spring-boot-demo-dubbo-parent - 0.0.1-SNAPSHOT - pom - - spring-boot-demo-dubbo-parent - Spring Boot 与 Dubbo 整合的父依赖 - - - org.springframework.boot - spring-boot-starter-parent - 2.0.1.RELEASE - - - - - spring-boot-demo-dubbo-api - spring-boot-demo-dubbo-provider - spring-boot-demo-dubbo-consumer - - - - UTF-8 - UTF-8 - 1.8 - 1.1.1 - - - - - org.springframework.boot - spring-boot-starter - - - - com.gitee.reger - spring-boot-starter-dubbo - ${spring-boot-starter-dubbo.version} - - - - org.projectlombok - lombok - 1.16.20 - - - - org.springframework.boot - spring-boot-starter-test - test - - - - com.xkcoding - spring-boot-demo-dubbo-api - 0.0.1-SNAPSHOT - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - -``` - -### 步骤 - -1. 启动本地的 `Zookeeper` 服务,端口号为 **2181** - - > 这里 `Zookeeper` 可以直接使用单机版,如果需要配置集群版的,可以参考 http://xkcoding.com/2017/11/01/zookeeper-cluster.html - -2. 启动两个 `spring-boot-demo-dubbo-provider` 程序,端口号分别使用 **8082**、**8083** - -3. 启动 `spring-boot-demo-dubbo-consumer` 程序,端口号为 **9090** - -4. 浏览器输入 http://localhost:9090/greet?name=test - - 可以看到,**8082**和**8083**端口随机打印 - - > Hello, test, from port: 8082 - - 或 - - > Hello, test, from port: 8083 - -5. 本地启动 `dubbo-admin` 可以查看服务提供方和消费方,也可以配置负载均衡策略等等 - - > 关于 `dubbo-admin` 的安装和配置等,可以参考 http://xkcoding.com/2017/11/08/dubbo-admin-install.html \ No newline at end of file diff --git a/spring-boot-demo-dubbo-parent/pom.xml b/spring-boot-demo-dubbo-parent/pom.xml deleted file mode 100644 index 4fbba8c..0000000 --- a/spring-boot-demo-dubbo-parent/pom.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - 4.0.0 - - com.xkcoding - spring-boot-demo-dubbo-parent - 0.0.1-SNAPSHOT - pom - - spring-boot-demo-dubbo-parent - Spring Boot 与 Dubbo 整合的父依赖 - - - org.springframework.boot - spring-boot-starter-parent - 2.0.1.RELEASE - - - - - spring-boot-demo-dubbo-api - spring-boot-demo-dubbo-provider - spring-boot-demo-dubbo-consumer - - - - UTF-8 - UTF-8 - 1.8 - 1.1.1 - - - - - org.springframework.boot - spring-boot-starter - - - - com.gitee.reger - spring-boot-starter-dubbo - ${spring-boot-starter-dubbo.version} - - - - org.projectlombok - lombok - 1.16.20 - - - - org.springframework.boot - spring-boot-starter-test - test - - - - com.xkcoding - spring-boot-demo-dubbo-api - 0.0.1-SNAPSHOT - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - \ No newline at end of file diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-api/README.md b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-api/README.md deleted file mode 100644 index fdb7c7a..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-api/README.md +++ /dev/null @@ -1,61 +0,0 @@ -# spring-boot-demo-dubbo-api - -Spring Boot 与 Dubbo 整合抽取的服务接口 - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-dubbo-api - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-dubbo-api - Spring Boot 与 Dubbo 整合抽取的服务接口 - - - com.xkcoding - spring-boot-demo-dubbo-parent - 0.0.1-SNAPSHOT - ../pom.xml - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - -``` - -### HelloService.java - -```java -package com.xkcoding.springbootdemodubboapi.service; - -/** - *

- * HelloService - *

- * - * @package: com.xkcoding.springbootdemodubboapi.service - * @description: HelloService - * @author: yangkai.shen - * @date: Created in 2018/4/17 下午5:13 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -public interface HelloService { - String hello(String name); -} -``` - diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-api/pom.xml b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-api/pom.xml deleted file mode 100644 index 2ccd87b..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-api/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-dubbo-api - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-dubbo-api - Spring Boot 与 Dubbo 整合抽取的服务接口 - - - com.xkcoding - spring-boot-demo-dubbo-parent - 0.0.1-SNAPSHOT - ../pom.xml - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - \ No newline at end of file diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-api/src/main/java/com/xkcoding/springbootdemodubboapi/service/HelloService.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-api/src/main/java/com/xkcoding/springbootdemodubboapi/service/HelloService.java deleted file mode 100644 index 5527895..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-api/src/main/java/com/xkcoding/springbootdemodubboapi/service/HelloService.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.xkcoding.springbootdemodubboapi.service; - -/** - *

- * HelloService - *

- * - * @package: com.xkcoding.springbootdemodubboapi.service - * @description: HelloService - * @author: yangkai.shen - * @date: Created in 2018/4/17 下午5:13 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -public interface HelloService { - String hello(String name); -} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-api/src/main/resources/application.yml b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-api/src/main/resources/application.yml deleted file mode 100644 index e69de29..0000000 diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/README.md b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/README.md deleted file mode 100644 index fa27a8e..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/README.md +++ /dev/null @@ -1,165 +0,0 @@ -# spring-boot-demo-dubbo-consumer - -Spring Boot 与 Dubbo 整合服务的消费方 - -依赖 [spring-boot-demo-dubbo-api](../spring-boot-demo-dubbo-api/pom.xml) - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-dubbo-consumer - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-dubbo-consumer - Spring Boot 与 Dubbo 整合服务的消费方 - - com.xkcoding - spring-boot-demo-dubbo-parent - 0.0.1-SNAPSHOT - ../pom.xml - - - - - org.springframework.boot - spring-boot-starter-web - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - -``` - -### application.yml - -```yaml -server: - port: 9090 -spring: - dubbo: - application: - name: dubbo-consumer - base-package: com.xkcoding.springbootdemodubboconsumer.service # dubbo服务调用者所在的包 - registry: - address: 127.0.0.1 # zookeeper注册中心的地址 - port: 2181 # zookeeper注册中心的端口 - consumer: - timeout: 1000 - check: true # 服务启动时检查被调用服务是否可用 - retries: 2 -``` - -### GreetController.java - -```java -package com.xkcoding.springbootdemodubboconsumer.controller; - -import com.xkcoding.springbootdemodubboconsumer.service.GreetService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -/** - *

- * GreetController - *

- * - * @package: com.xkcoding.springbootdemodubboconsumer.controller - * @description: GreetController - * @author: yangkai.shen - * @date: Created in 2018/4/17 下午5:29 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@RestController -@RequestMapping("/greet") -public class GreetController { - @Autowired - private GreetService greetService; - - @GetMapping("") - public String hello(@RequestParam String name) { - return greetService.greeting(name); - } -} -``` - -### GreetService.java - -```java -package com.xkcoding.springbootdemodubboconsumer.service; - -/** - *

- * GreetService - *

- * - * @package: com.xkcoding.springbootdemodubboconsumer.service - * @description: GreetService - * @author: yangkai.shen - * @date: Created in 2018/4/17 下午5:30 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -public interface GreetService { - String greeting(String name); -} -``` - -### GreetServiceImpl.java - -代码中的 `@Service` 使用的是 `Spring` 的注解,而不是 `Dubbo` 的注解 - -代码中的 `@Inject` 可以替换成 `Dubbo` 提供的 `@Reference`,效果相同 - -```java -package com.xkcoding.springbootdemodubboconsumer.service.impl; - -import com.reger.dubbo.annotation.Inject; -import com.xkcoding.springbootdemodubboapi.service.HelloService; -import com.xkcoding.springbootdemodubboconsumer.service.GreetService; -import org.springframework.stereotype.Service; - -/** - *

- * GreetServiceImpl - *

- * - * @package: com.xkcoding.springbootdemodubboconsumer.service.impl - * @description: GreetServiceImpl - * @author: yangkai.shen - * @date: Created in 2018/4/17 下午5:31 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Service -public class GreetServiceImpl implements GreetService { - @Inject - private HelloService helloService; - - @Override - public String greeting(String name) { - return helloService.hello(name); - } -} -``` - diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/pom.xml b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/pom.xml deleted file mode 100644 index 94bc2fb..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/pom.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-dubbo-consumer - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-dubbo-consumer - Spring Boot 与 Dubbo 整合服务的消费方 - - com.xkcoding - spring-boot-demo-dubbo-parent - 0.0.1-SNAPSHOT - ../pom.xml - - - - - org.springframework.boot - spring-boot-starter-web - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - \ No newline at end of file diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplication.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplication.java deleted file mode 100644 index 08889a0..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.xkcoding.springbootdemodubboconsumer; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringBootDemoDubboConsumerApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoDubboConsumerApplication.class, args); - } -} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/controller/GreetController.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/controller/GreetController.java deleted file mode 100644 index 431e343..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/controller/GreetController.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.xkcoding.springbootdemodubboconsumer.controller; - -import com.xkcoding.springbootdemodubboconsumer.service.GreetService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -/** - *

- * GreetController - *

- * - * @package: com.xkcoding.springbootdemodubboconsumer.controller - * @description: GreetController - * @author: yangkai.shen - * @date: Created in 2018/4/17 下午5:29 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@RestController -@RequestMapping("/greet") -public class GreetController { - @Autowired - private GreetService greetService; - - @GetMapping("") - public String hello(@RequestParam String name) { - return greetService.greeting(name); - } -} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/GreetService.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/GreetService.java deleted file mode 100644 index bf1300f..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/GreetService.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.xkcoding.springbootdemodubboconsumer.service; - -/** - *

- * GreetService - *

- * - * @package: com.xkcoding.springbootdemodubboconsumer.service - * @description: GreetService - * @author: yangkai.shen - * @date: Created in 2018/4/17 下午5:30 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -public interface GreetService { - String greeting(String name); -} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/impl/GreetServiceImpl.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/impl/GreetServiceImpl.java deleted file mode 100644 index d7599c0..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/java/com/xkcoding/springbootdemodubboconsumer/service/impl/GreetServiceImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.xkcoding.springbootdemodubboconsumer.service.impl; - -import com.reger.dubbo.annotation.Inject; -import com.xkcoding.springbootdemodubboapi.service.HelloService; -import com.xkcoding.springbootdemodubboconsumer.service.GreetService; -import org.springframework.stereotype.Service; - -/** - *

- * GreetServiceImpl - *

- * - * @package: com.xkcoding.springbootdemodubboconsumer.service.impl - * @description: GreetServiceImpl - * @author: yangkai.shen - * @date: Created in 2018/4/17 下午5:31 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Service -public class GreetServiceImpl implements GreetService { - @Inject - private HelloService helloService; - - @Override - public String greeting(String name) { - return helloService.hello(name); - } -} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/resources/application.yml b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/resources/application.yml deleted file mode 100644 index 35642dd..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/main/resources/application.yml +++ /dev/null @@ -1,14 +0,0 @@ -server: - port: 9090 -spring: - dubbo: - application: - name: dubbo-consumer - base-package: com.xkcoding.springbootdemodubboconsumer.service # dubbo服务调用者所在的包 - registry: - address: 127.0.0.1 # zookeeper注册中心的地址 - port: 2181 # zookeeper注册中心的端口 - consumer: - timeout: 1000 - check: true # 服务启动时检查被调用服务是否可用 - retries: 2 \ No newline at end of file diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/test/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplicationTests.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/test/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplicationTests.java deleted file mode 100644 index cbd6b54..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-consumer/src/test/java/com/xkcoding/springbootdemodubboconsumer/SpringBootDemoDubboConsumerApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemodubboconsumer; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoDubboConsumerApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/README.md b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/README.md deleted file mode 100644 index 0106a81..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/README.md +++ /dev/null @@ -1,106 +0,0 @@ -# spring-boot-demo-dubbo-provider - -Spring Boot 与 Dubbo 整合服务的提供方 - -依赖 [spring-boot-demo-dubbo-api](../spring-boot-demo-dubbo-api/pom.xml) - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-dubbo-provider - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-dubbo-provider - Spring Boot 与 Dubbo 整合服务的提供方 - - - com.xkcoding - spring-boot-demo-dubbo-parent - 0.0.1-SNAPSHOT - ../pom.xml - - - - - org.springframework.boot - spring-boot-starter-web - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - -``` - -### application.yml - -```yaml -server: - port: 8082 -spring: - dubbo: - application: - name: dubbo-provider - base-package: com.xkcoding.springbootdemodubboprovider.service # dubbo服务发布者所在的包 - registry: - address: 127.0.0.1 # zookeeper注册中心的地址 - port: 2181 # zookeeper注册中心的端口 - protocol: - name: dubbo - serialization: hessian2 - provider: - retries: 0 -``` - -### HelloServiceImpl.java - -代码中的 `@Service` 使用的是 `Dubbo` 的注解,而不是 `Spring` 的注解 - -```java -package com.xkcoding.springbootdemodubboprovider.service.impl; - -import com.alibaba.dubbo.config.annotation.Service; -import com.xkcoding.springbootdemodubboapi.service.HelloService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; - -/** - *

- * HelloServiceImpl - *

- * - * @package: com.xkcoding.springbootdemodubboprovider.service.impl - * @description: HelloServiceImpl - * @author: yangkai.shen - * @date: Created in 2018/4/17 下午5:24 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Service -@Slf4j -public class HelloServiceImpl implements HelloService { - @Value("${server.port}") - private Integer port; - - @Override - public String hello(String name) { - log.info("Hello, {}, from port: {}",name, port); - return "Hello, " + name + ", from port: " + port; - } -} -``` - diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/pom.xml b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/pom.xml deleted file mode 100644 index 0ac60de..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-dubbo-provider - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-dubbo-provider - Spring Boot 与 Dubbo 整合服务的提供方 - - - com.xkcoding - spring-boot-demo-dubbo-parent - 0.0.1-SNAPSHOT - ../pom.xml - - - - - org.springframework.boot - spring-boot-starter-web - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - \ No newline at end of file diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplication.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplication.java deleted file mode 100644 index 2b5bfcd..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.xkcoding.springbootdemodubboprovider; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringBootDemoDubboProviderApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoDubboProviderApplication.class, args); - } -} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/service/impl/HelloServiceImpl.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/service/impl/HelloServiceImpl.java deleted file mode 100644 index fe7e6da..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/java/com/xkcoding/springbootdemodubboprovider/service/impl/HelloServiceImpl.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.xkcoding.springbootdemodubboprovider.service.impl; - -import com.alibaba.dubbo.config.annotation.Service; -import com.xkcoding.springbootdemodubboapi.service.HelloService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; - -/** - *

- * HelloServiceImpl - *

- * - * @package: com.xkcoding.springbootdemodubboprovider.service.impl - * @description: HelloServiceImpl - * @author: yangkai.shen - * @date: Created in 2018/4/17 下午5:24 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Service -@Slf4j -public class HelloServiceImpl implements HelloService { - @Value("${server.port}") - private Integer port; - - @Override - public String hello(String name) { - log.info("Hello, {}, from port: {}",name, port); - return "Hello, " + name + ", from port: " + port; - } -} diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/resources/application.yml b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/resources/application.yml deleted file mode 100644 index 350e696..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/main/resources/application.yml +++ /dev/null @@ -1,15 +0,0 @@ -server: - port: 8082 -spring: - dubbo: - application: - name: dubbo-provider - base-package: com.xkcoding.springbootdemodubboprovider.service # dubbo服务发布者所在的包 - registry: - address: 127.0.0.1 # zookeeper注册中心的地址 - port: 2181 # zookeeper注册中心的端口 - protocol: - name: dubbo - serialization: hessian2 - provider: - retries: 0 \ No newline at end of file diff --git a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/test/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplicationTests.java b/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/test/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplicationTests.java deleted file mode 100644 index 298b474..0000000 --- a/spring-boot-demo-dubbo-parent/spring-boot-demo-dubbo-provider/src/test/java/com/xkcoding/springbootdemodubboprovider/SpringBootDemoDubboProviderApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemodubboprovider; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoDubboProviderApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-elasticsearch/.gitignore b/spring-boot-demo-elasticsearch/.gitignore deleted file mode 100644 index 2af7cef..0000000 --- a/spring-boot-demo-elasticsearch/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -.nb-gradle/ \ No newline at end of file diff --git a/spring-boot-demo-elasticsearch/README.md b/spring-boot-demo-elasticsearch/README.md deleted file mode 100644 index 10be277..0000000 --- a/spring-boot-demo-elasticsearch/README.md +++ /dev/null @@ -1,284 +0,0 @@ -# spring-boot-demo-elasticsearch - -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent) - -> 关于 ES 的更多内容,可以参考[官方文档](https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started.html) -> -> 本例对应博客文章地址,http://xkcoding.com/2018/01/12/elasticsearch_note.html - -ElasticSearch 的 demo 我这里没有使用 spring-data-elasticsearch,我使用的是原生的方式 - -操作 ElasticSearch 由很多种方式: - -1. ES 官方提供的原生方式,**本例子使用这种方式**,这种方式的好处是高度自定义,并且可以使用最新的 ES 版本,缺点就是所有操作都得自己写。 -2. 使用 Spring 官方提供的 spring-data-elasticsearch,这里给出地址 https://projects.spring.io/spring-data-elasticsearch/ ,采用的方式类似 JPA,并且为 SpringBoot 提供了一个 `spring-boot-starter-data-elasticsearch`,优点是操作 ES 的方式采用了 JPA 的方式,都已经封装好了,缺点是版本得随着官方慢慢迭代,不能使用 ES 的最新特性。 - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-elasticsearch - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-elasticsearch - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - 6.1.1 - - - - - - org.elasticsearch.client - transport - ${elasticsearch.version} - - - - org.apache.logging.log4j - log4j-core - 2.7 - - - - - spring-boot-demo-elasticsearch - - - -``` - -### application.yml - -```yaml -server: - port: 8080 - context-path: /demo -elasticsearch: - host: 127.0.0.1 - port: 9300 - cluster: - name: xkcoding -``` - -ElasticSearchConfig.java - -```java -/** - *

- * ES 的配置类 - *

- * - * @package: com.xkcoding.springbootdemoelasticsearch.config - * @description: ES 的配置类 - * @author: yangkai.shen - * @date: Created in 2018/1/18 下午4:41 - * @copyright: Copyright (c) 2018 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Configuration -public class ElasticSearchConfig { - @Value("${elasticsearch.host}") - private String host; - - @Value("${elasticsearch.port}") - private int port; - - @Value("${elasticsearch.cluster.name}") - private String clusterName; - - @Bean - public TransportClient esClient() throws UnknownHostException { - Settings settings = Settings.builder().put("cluster.name", this.clusterName).put("client.transport.sniff", true).build(); - - TransportAddress master = new TransportAddress(InetAddress.getByName(host), port); - TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(master); - return client; - } -} -``` - -PersonController.java - -```java -/** - *

- * Person Controller - *

- * - * @package: com.xkcoding.springbootdemoelasticsearch.web.controller - * @description: Person Controller - * @author: yangkai.shen - * @date: Created in 2018/1/18 下午5:06 - * @copyright: Copyright (c) 2018 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@RestController -@Slf4j -public class PersonController { - public static final String INDEX = "people"; - public static final String TYPE = "person"; - - @Autowired - private TransportClient esClient; - - /** - * 插入一条数据到 ES 中,id 由 ES 生成 - * - * @param name 名称 - * @param country 国籍 - * @param age 年龄 - * @param birthday 生日 - * @return 插入数据的主键 - */ - @PostMapping("/person") - public ApiResponse add(@RequestParam String name, @RequestParam String country, @RequestParam Integer age, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date birthday) { - try { - XContentBuilder content = XContentFactory.jsonBuilder().startObject().field("name", name).field("country", country).field("age", age).field("birthday", birthday.getTime()).endObject(); - - IndexResponse response = esClient.prepareIndex(INDEX, TYPE).setSource(content).get(); - return ApiResponse.ofSuccess(response.getId()); - } catch (IOException e) { - e.printStackTrace(); - return ApiResponse.ofStatus(Status.INTERNAL_SERVER_ERROR); - } - } - - /** - * 根据 id 删除 ES 的一条记录 - * - * @param id ES 中的 id - * @return DELETED 代表删除 - */ - @DeleteMapping("/person/{id}") - public ApiResponse delete(@PathVariable String id) { - DeleteResponse response = esClient.prepareDelete(INDEX, TYPE, id).get(); - return ApiResponse.ofSuccess(response.getResult()); - } - - /** - * 根据主键,修改传递字段对应的值 - * - * @param id ES 中的 id - * @param name 姓名 - * @param country 国籍 - * @param age 年龄 - * @param birthday 生日 - * @return UPDATED 代表文档修改成功 - */ - @PutMapping("/person/{id}") - public ApiResponse update(@PathVariable String id, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "country", required = false) String country, @RequestParam(value = "age", required = false) Integer age, @RequestParam(value = "birthday", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date birthday) { - UpdateRequest request = new UpdateRequest(INDEX, TYPE, id); - try { - XContentBuilder builder = XContentFactory.jsonBuilder().startObject(); - if (!Strings.isNullOrEmpty(name)) { - builder.field("name", name); - } - if (!Strings.isNullOrEmpty(country)) { - builder.field("country", country); - } - if (age != null && age > 0) { - builder.field("age", age); - } - if (birthday != null) { - builder.field("birthday", birthday.getTime()); - } - builder.endObject(); - request.doc(builder); - } catch (IOException e) { - e.printStackTrace(); - return ApiResponse.ofStatus(Status.INTERNAL_SERVER_ERROR); - } - try { - UpdateResponse response = esClient.update(request).get(); - return ApiResponse.ofSuccess(response); - } catch (Exception e) { - e.printStackTrace(); - return ApiResponse.ofStatus(Status.INTERNAL_SERVER_ERROR); - } - } - - /** - * 简单查询 根据 id 查 ES 中的文档内容 - * - * @param id ES 中存储的 id - * @return 对应 id 的文档内容 - */ - @GetMapping("/person/{id}") - public ApiResponse get(@PathVariable String id) { - GetResponse response = esClient.prepareGet(INDEX, TYPE, id).get(); - if (!response.isExists() || response.isSourceEmpty()) { - return ApiResponse.ofStatus(Status.NOT_FOUND); - } - return ApiResponse.ofSuccess(response.getSource()); - } - - /** - * 复合查询,根据传进来的条件,查询具体内容 - * - * @param name 根据姓名匹配 - * @param country 根据国籍匹配 - * @param gtAge 大于年龄 - * @param ltAge 小于年龄 - * @return 满足条件的文档内容 - */ - @PostMapping("/person/query") - public ApiResponse query(@RequestParam(value = "name", required = false) String name, - @RequestParam(value = "country", required = false) String country, - @RequestParam(value = "gt_age", defaultValue = "0") int gtAge, - @RequestParam(value = "lt_age", required = false) Integer ltAge) { - BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); - - if (!Strings.isNullOrEmpty(name)) { - boolQueryBuilder.must(QueryBuilders.matchQuery("name", name)); - } - - if (!Strings.isNullOrEmpty(country)) { - boolQueryBuilder.must(QueryBuilders.matchQuery("country", country)); - } - - RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery("age").from(gtAge); - - if (ltAge != null && ltAge > 0) { - rangeQueryBuilder.to(ltAge); - } - - boolQueryBuilder.filter(rangeQueryBuilder); - - SearchRequestBuilder searchRequestBuilder = esClient.prepareSearch(INDEX) - .setTypes(TYPE) - .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) - .setQuery(boolQueryBuilder) - .setFrom(0) - .setSize(20); - - log.info("【query】:{}", searchRequestBuilder); - - SearchResponse searchResponse = searchRequestBuilder.get(); - List> result = Lists.newArrayList(); - searchResponse.getHits().forEach(hit -> { - result.add(hit.getSourceAsMap()); - }); - - return ApiResponse.ofSuccess(result); - } - -} -``` - diff --git a/spring-boot-demo-elasticsearch/pom.xml b/spring-boot-demo-elasticsearch/pom.xml deleted file mode 100644 index 6e4938c..0000000 --- a/spring-boot-demo-elasticsearch/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-elasticsearch - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-elasticsearch - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - 6.1.1 - - - - - - org.elasticsearch.client - transport - ${elasticsearch.version} - - - - org.apache.logging.log4j - log4j-core - 2.7 - - - - - spring-boot-demo-elasticsearch - - - \ No newline at end of file diff --git a/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/SpringBootDemoElasticsearchApplication.java b/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/SpringBootDemoElasticsearchApplication.java deleted file mode 100644 index 1c4154b..0000000 --- a/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/SpringBootDemoElasticsearchApplication.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.xkcoding.springbootdemoelasticsearch; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - *

- * 应用启动类 - *

- * - * @package: com.xkcoding.springbootdemoelasticsearch.web.controller - * @description: 应用启动类 - * @author: yangkai.shen - * @date: Created in 2018/1/18 下午5:06 - * @copyright: Copyright (c) 2018 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@SpringBootApplication -public class SpringBootDemoElasticsearchApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoElasticsearchApplication.class, args); - } - -} diff --git a/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/config/ElasticSearchConfig.java b/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/config/ElasticSearchConfig.java deleted file mode 100644 index 471fd07..0000000 --- a/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/config/ElasticSearchConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.xkcoding.springbootdemoelasticsearch.config; - -import org.elasticsearch.client.transport.TransportClient; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.transport.client.PreBuiltTransportClient; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.net.InetAddress; -import java.net.UnknownHostException; - -/** - *

- * ES 的配置类 - *

- * - * @package: com.xkcoding.springbootdemoelasticsearch.config - * @description: ES 的配置类 - * @author: yangkai.shen - * @date: Created in 2018/1/18 下午4:41 - * @copyright: Copyright (c) 2018 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Configuration -public class ElasticSearchConfig { - @Value("${elasticsearch.host}") - private String host; - - @Value("${elasticsearch.port}") - private int port; - - @Value("${elasticsearch.cluster.name}") - private String clusterName; - - @Bean - public TransportClient esClient() throws UnknownHostException { - Settings settings = Settings.builder().put("cluster.name", this.clusterName).put("client.transport.sniff", true).build(); - - TransportAddress master = new TransportAddress(InetAddress.getByName(host), port); - TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(master); - return client; - } -} diff --git a/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/web/base/ApiResponse.java b/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/web/base/ApiResponse.java deleted file mode 100644 index 6808aa9..0000000 --- a/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/web/base/ApiResponse.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.xkcoding.springbootdemoelasticsearch.web.base; - -import lombok.Data; - -/** - *

- * 统一接口返回类型 - *

- * - * @package: com.xkcoding.springbootdemoelasticsearch - * @description: 统一接口返回类型 - * @author: yangkai.shen - * @date: Created in 2018/1/18 下午5:34 - * @copyright: Copyright (c) 2018 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Data -public class ApiResponse { - private int code; - private String message; - private Object data; - private boolean more; - - public ApiResponse(int code, String message, Object data) { - this.code = code; - this.message = message; - this.data = data; - } - - public ApiResponse() { - this.code = Status.SUCCESS.getCode(); - this.message = Status.SUCCESS.getMsg(); - } - - public static ApiResponse ofMessage(int code, String message) { - return new ApiResponse(code, message, null); - } - - public static ApiResponse ofSuccess(Object data) { - return new ApiResponse(Status.SUCCESS.getCode(), Status.SUCCESS.getMsg(), data); - } - - public static ApiResponse ofStatus(Status status) { - return new ApiResponse(status.getCode(), status.getMsg(), null); - } - -} \ No newline at end of file diff --git a/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/web/base/Status.java b/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/web/base/Status.java deleted file mode 100644 index 0200643..0000000 --- a/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/web/base/Status.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.xkcoding.springbootdemoelasticsearch.web.base; - -import lombok.Getter; - -/** - *

- * 通用状态码 - *

- * - * @package: com.xkcoding.springbootdemoelasticsearch.web.base - * @description: 通用状态码 - * @author: yangkai.shen - * @date: Created in 2018/1/18 下午5:35 - * @copyright: Copyright (c) 2018 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Getter -public enum Status { - SUCCESS(200, "OK"), BAD_REQUEST(400, "Bad Request"), NOT_FOUND(404, "Not Found"), INTERNAL_SERVER_ERROR(500, "Unknown Internal Error"); - - private int code; - private String msg; - - Status(int code, String msg) { - this.code = code; - this.msg = msg; - } -} diff --git a/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/web/controller/PersonController.java b/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/web/controller/PersonController.java deleted file mode 100644 index b2aa508..0000000 --- a/spring-boot-demo-elasticsearch/src/main/java/com/xkcoding/springbootdemoelasticsearch/web/controller/PersonController.java +++ /dev/null @@ -1,194 +0,0 @@ -package com.xkcoding.springbootdemoelasticsearch.web.controller; - -import com.google.common.base.Strings; -import com.google.common.collect.Lists; -import com.xkcoding.springbootdemoelasticsearch.web.base.ApiResponse; -import com.xkcoding.springbootdemoelasticsearch.web.base.Status; -import lombok.extern.slf4j.Slf4j; -import org.elasticsearch.action.delete.DeleteResponse; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.action.search.SearchRequestBuilder; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.action.update.UpdateRequest; -import org.elasticsearch.action.update.UpdateResponse; -import org.elasticsearch.client.transport.TransportClient; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.index.query.BoolQueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.query.RangeQueryBuilder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.format.annotation.DateTimeFormat; -import org.springframework.web.bind.annotation.*; - -import java.io.IOException; -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - *

- * Person Controller - *

- * - * @package: com.xkcoding.springbootdemoelasticsearch.web.controller - * @description: Person Controller - * @author: yangkai.shen - * @date: Created in 2018/1/18 下午5:06 - * @copyright: Copyright (c) 2018 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@RestController -@Slf4j -public class PersonController { - public static final String INDEX = "people"; - public static final String TYPE = "person"; - - @Autowired - private TransportClient esClient; - - /** - * 插入一条数据到 ES 中,id 由 ES 生成 - * - * @param name 名称 - * @param country 国籍 - * @param age 年龄 - * @param birthday 生日 - * @return 插入数据的主键 - */ - @PostMapping("/person") - public ApiResponse add(@RequestParam String name, @RequestParam String country, @RequestParam Integer age, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date birthday) { - try { - XContentBuilder content = XContentFactory.jsonBuilder().startObject().field("name", name).field("country", country).field("age", age).field("birthday", birthday.getTime()).endObject(); - - IndexResponse response = esClient.prepareIndex(INDEX, TYPE).setSource(content).get(); - return ApiResponse.ofSuccess(response.getId()); - } catch (IOException e) { - e.printStackTrace(); - return ApiResponse.ofStatus(Status.INTERNAL_SERVER_ERROR); - } - } - - /** - * 根据 id 删除 ES 的一条记录 - * - * @param id ES 中的 id - * @return DELETED 代表删除 - */ - @DeleteMapping("/person/{id}") - public ApiResponse delete(@PathVariable String id) { - DeleteResponse response = esClient.prepareDelete(INDEX, TYPE, id).get(); - return ApiResponse.ofSuccess(response.getResult()); - } - - /** - * 根据主键,修改传递字段对应的值 - * - * @param id ES 中的 id - * @param name 姓名 - * @param country 国籍 - * @param age 年龄 - * @param birthday 生日 - * @return UPDATED 代表文档修改成功 - */ - @PutMapping("/person/{id}") - public ApiResponse update(@PathVariable String id, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "country", required = false) String country, @RequestParam(value = "age", required = false) Integer age, @RequestParam(value = "birthday", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date birthday) { - UpdateRequest request = new UpdateRequest(INDEX, TYPE, id); - try { - XContentBuilder builder = XContentFactory.jsonBuilder().startObject(); - if (!Strings.isNullOrEmpty(name)) { - builder.field("name", name); - } - if (!Strings.isNullOrEmpty(country)) { - builder.field("country", country); - } - if (age != null && age > 0) { - builder.field("age", age); - } - if (birthday != null) { - builder.field("birthday", birthday.getTime()); - } - builder.endObject(); - request.doc(builder); - } catch (IOException e) { - e.printStackTrace(); - return ApiResponse.ofStatus(Status.INTERNAL_SERVER_ERROR); - } - try { - UpdateResponse response = esClient.update(request).get(); - return ApiResponse.ofSuccess(response); - } catch (Exception e) { - e.printStackTrace(); - return ApiResponse.ofStatus(Status.INTERNAL_SERVER_ERROR); - } - } - - /** - * 简单查询 根据 id 查 ES 中的文档内容 - * - * @param id ES 中存储的 id - * @return 对应 id 的文档内容 - */ - @GetMapping("/person/{id}") - public ApiResponse get(@PathVariable String id) { - GetResponse response = esClient.prepareGet(INDEX, TYPE, id).get(); - if (!response.isExists() || response.isSourceEmpty()) { - return ApiResponse.ofStatus(Status.NOT_FOUND); - } - return ApiResponse.ofSuccess(response.getSource()); - } - - /** - * 复合查询,根据传进来的条件,查询具体内容 - * - * @param name 根据姓名匹配 - * @param country 根据国籍匹配 - * @param gtAge 大于年龄 - * @param ltAge 小于年龄 - * @return 满足条件的文档内容 - */ - @PostMapping("/person/query") - public ApiResponse query(@RequestParam(value = "name", required = false) String name, - @RequestParam(value = "country", required = false) String country, - @RequestParam(value = "gt_age", defaultValue = "0") int gtAge, - @RequestParam(value = "lt_age", required = false) Integer ltAge) { - BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); - - if (!Strings.isNullOrEmpty(name)) { - boolQueryBuilder.must(QueryBuilders.matchQuery("name", name)); - } - - if (!Strings.isNullOrEmpty(country)) { - boolQueryBuilder.must(QueryBuilders.matchQuery("country", country)); - } - - RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery("age").from(gtAge); - - if (ltAge != null && ltAge > 0) { - rangeQueryBuilder.to(ltAge); - } - - boolQueryBuilder.filter(rangeQueryBuilder); - - SearchRequestBuilder searchRequestBuilder = esClient.prepareSearch(INDEX) - .setTypes(TYPE) - .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) - .setQuery(boolQueryBuilder) - .setFrom(0) - .setSize(20); - - log.info("【query】:{}", searchRequestBuilder); - - SearchResponse searchResponse = searchRequestBuilder.get(); - List> result = Lists.newArrayList(); - searchResponse.getHits().forEach(hit -> { - result.add(hit.getSourceAsMap()); - }); - - return ApiResponse.ofSuccess(result); - } - -} diff --git a/spring-boot-demo-elasticsearch/src/main/resources/application.yml b/spring-boot-demo-elasticsearch/src/main/resources/application.yml deleted file mode 100644 index 2784476..0000000 --- a/spring-boot-demo-elasticsearch/src/main/resources/application.yml +++ /dev/null @@ -1,8 +0,0 @@ -server: - port: 8080 - context-path: /demo -elasticsearch: - host: 127.0.0.1 - port: 9300 - cluster: - name: xkcoding diff --git a/spring-boot-demo-elasticsearch/src/test/java/com/xkcoding/springbootdemoelasticsearch/SpringBootDemoElasticsearchApplicationTests.java b/spring-boot-demo-elasticsearch/src/test/java/com/xkcoding/springbootdemoelasticsearch/SpringBootDemoElasticsearchApplicationTests.java deleted file mode 100644 index 7317c62..0000000 --- a/spring-boot-demo-elasticsearch/src/test/java/com/xkcoding/springbootdemoelasticsearch/SpringBootDemoElasticsearchApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemoelasticsearch; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoElasticsearchApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-exceptionhandler/README.md b/spring-boot-demo-exceptionhandler/README.md deleted file mode 100644 index 26a8c76..0000000 --- a/spring-boot-demo-exceptionhandler/README.md +++ /dev/null @@ -1,180 +0,0 @@ -# spring-boot-demo-exceptionhandler - -依赖[spring-boot-demo-parent](../spring-boot-demo-parent)、`spring-boot-starter-thymeleaf`(关于 thymeleaf 的会在后面的模板引擎专门有demo) - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-exceptionhandler - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-exceptionhandler - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - - - spring-boot-demo-exceptionhandler - - - -``` - -### application.yml - -```yaml -server: - port: 8080 - context-path: /demo -spring: - thymeleaf: - mode: HTML5 - encoding: UTF-8 - content-type: text/html - cache: false -``` - -### DemoExceptionHandler.java - -```java -/** - * 自定义异常统一处理 - * - * @package: com.xkcoding.springbootdemoexceptionhandler.handler - * @description: 自定义异常统一处理 - * @author: yangkai.shen - * @date: Created in 2017/11/24 下午1:37 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@ControllerAdvice -@Slf4j -public class DemoExceptionHandler { - public static final String DEFAULT_ERROR_VIEW = "error"; - - /** - * 统一 json 异常处理 - * - * @param exception DemoJsonException - * @return 统一返回 json 格式 - */ - @ExceptionHandler(value = DemoJsonException.class) - @ResponseBody - public R jsonErrorHandler(DemoJsonException exception) { - log.error("【DemoJsonException】:{}", exception.getMessage()); - return R.error(exception); - } - - /** - * 统一 页面 异常处理 - * - * @param exception DemoPageException - * @return 统一跳转到异常页面 - */ - @ExceptionHandler(value = DemoPageException.class) - public ModelAndView pageErrorHandler(DemoPageException exception) { - log.error("【DemoPageException】:{}", exception.getMessage()); - ModelAndView view = new ModelAndView(); - view.addObject("message", exception.getMessage()); - view.setViewName(DEFAULT_ERROR_VIEW); - return view; - } -} -``` - -### R.java - -```java -/** - * 统一返回的 json 对象 - * - * @package: com.xkcoding.springbootdemoexceptionhandler - * @description: 统一返回的 json 对象 - * @author: yangkai.shen - * @date: Created in 2017/11/24 下午1:42 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class R { - private Integer code; - private String message; - private T data; - - public R(Status status) { - this.code = status.getCode(); - this.message = status.getMessage(); - } - - public static R success(Integer code, String message, Object data) { - return new R(code, message, data); - } - - public static R success() { - return new R(Status.OK); - } - - public static R success(String message) { - return success(message, null); - } - - public static R success(String message, Object data) { - return success(Code.SUCCESS.getCode(), message, data); - } - - public static R error(Integer code, String message, Object data) { - return new R(code, message, data); - } - - public static R error(Integer code, String message) { - return error(code, message, null); - } - - public static R error(DemoJsonException exception) { - return error(exception.getCode(), exception.getMessage()); - } -} -``` - -### error.html (在目录 `resources/templates` 下) - -```html - - - - - 统一页面异常处理 - - -

统一页面异常处理

-
- - -``` - -### 其余代码 - -详情请参见本demo。 \ No newline at end of file diff --git a/spring-boot-demo-exceptionhandler/pom.xml b/spring-boot-demo-exceptionhandler/pom.xml deleted file mode 100644 index 777d1ab..0000000 --- a/spring-boot-demo-exceptionhandler/pom.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-exceptionhandler - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-exceptionhandler - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - - - spring-boot-demo-exceptionhandler - - - \ No newline at end of file diff --git a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/SpringBootDemoExceptionhandlerApplication.java b/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/SpringBootDemoExceptionhandlerApplication.java deleted file mode 100644 index 9477068..0000000 --- a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/SpringBootDemoExceptionhandlerApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.xkcoding.springbootdemoexceptionhandler; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringBootDemoExceptionhandlerApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoExceptionhandlerApplication.class, args); - } -} diff --git a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/controller/JsonController.java b/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/controller/JsonController.java deleted file mode 100644 index 6b3a4b4..0000000 --- a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/controller/JsonController.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.xkcoding.springbootdemoexceptionhandler.controller; - -import com.xkcoding.springbootdemoexceptionhandler.domain.R; -import com.xkcoding.springbootdemoexceptionhandler.exception.DemoJsonException; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * 测试 json 异常处理 - * - * @package: com.xkcoding.springbootdemoexceptionhandler.controller - * @description: 测试 json 异常处理 - * @author: yangkai.shen - * @date: Created in 2017/11/24 下午2:08 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@RestController -@RequestMapping("/json") -public class JsonController { - - @GetMapping({"", "/"}) - public R index() { - throw new DemoJsonException(501, "DemoJsonException"); - } -} diff --git a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/controller/PageController.java b/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/controller/PageController.java deleted file mode 100644 index b53544d..0000000 --- a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/controller/PageController.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.xkcoding.springbootdemoexceptionhandler.controller; - -import com.xkcoding.springbootdemoexceptionhandler.exception.DemoPageException; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -/** - * 测试 page 异常处理 - * - * @package: com.xkcoding.springbootdemoexceptionhandler.controller - * @description: 测试 page 异常处理 - * @author: yangkai.shen - * @date: Created in 2017/11/24 下午2:29 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Controller -@RequestMapping("/page") -public class PageController { - - @GetMapping({"", "/"}) - public ModelAndView index() { - throw new DemoPageException(600, "DemoPageException"); - } -} diff --git a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/domain/R.java b/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/domain/R.java deleted file mode 100644 index 8619e1b..0000000 --- a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/domain/R.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.xkcoding.springbootdemoexceptionhandler.domain; - -import com.xkcoding.springbootdemoexceptionhandler.enums.Code; -import com.xkcoding.springbootdemoexceptionhandler.enums.Status; -import com.xkcoding.springbootdemoexceptionhandler.exception.DemoJsonException; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * 统一返回的 json 对象 - * - * @package: com.xkcoding.springbootdemoexceptionhandler - * @description: 统一返回的 json 对象 - * @author: yangkai.shen - * @date: Created in 2017/11/24 下午1:42 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class R { - private Integer code; - private String message; - private T data; - - public R(Status status) { - this.code = status.getCode(); - this.message = status.getMessage(); - } - - public static R success(Integer code, String message, Object data) { - return new R(code, message, data); - } - - public static R success() { - return new R(Status.OK); - } - - public static R success(String message) { - return success(message, null); - } - - public static R success(String message, Object data) { - return success(Code.SUCCESS.getCode(), message, data); - } - - public static R error(Integer code, String message, Object data) { - return new R(code, message, data); - } - - public static R error(Integer code, String message) { - return error(code, message, null); - } - - public static R error(DemoJsonException exception) { - return error(exception.getCode(), exception.getMessage()); - } -} diff --git a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/enums/Code.java b/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/enums/Code.java deleted file mode 100644 index b6b9289..0000000 --- a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/enums/Code.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.xkcoding.springbootdemoexceptionhandler.enums; - -import lombok.Getter; - -/** - * 状态码 - * - * @package: com.xkcoding.springbootdemoexceptionhandler.enums - * @description: 状态码 - * @author: yangkai.shen - * @date: Created in 2017/11/24 下午1:56 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Getter -public enum Code { - SUCCESS(200); - private Integer code; - - Code(Integer code) { - this.code = code; - } - -} diff --git a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/enums/Status.java b/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/enums/Status.java deleted file mode 100644 index 2733ecf..0000000 --- a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/enums/Status.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.xkcoding.springbootdemoexceptionhandler.enums; - -import lombok.Getter; - -/** - * 返回状态 - * - * @package: com.xkcoding.springbootdemoexceptionhandler.enums - * @description: 返回状态 - * @author: yangkai.shen - * @date: Created in 2017/11/24 下午1:47 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Getter -public enum Status { - OK(200, "成功"), UNKNOW_ERROR(-1, "未知错误"); - private Integer code; - private String message; - - Status(Integer code, String message) { - this.code = code; - this.message = message; - } -} diff --git a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/exception/DemoJsonException.java b/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/exception/DemoJsonException.java deleted file mode 100644 index 5dc3c46..0000000 --- a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/exception/DemoJsonException.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.xkcoding.springbootdemoexceptionhandler.exception; - -import lombok.Getter; - -/** - * 统一的 json 异常处理 - *

- * 要继承 RuntimeException - *

- * - * @package: com.xkcoding.springbootdemoexceptionhandler.exception - * @description: 统一的 json 异常处理 - * @author: yangkai.shen - * @date: Created in 2017/11/24 下午1:32 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Getter -public class DemoJsonException extends RuntimeException { - public Integer code; - - public DemoJsonException(Integer code, String message) { - super(message); - this.code = code; - } -} diff --git a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/exception/DemoPageException.java b/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/exception/DemoPageException.java deleted file mode 100644 index 3e5d053..0000000 --- a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/exception/DemoPageException.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.xkcoding.springbootdemoexceptionhandler.exception; - -import lombok.Getter; - -/** - * 统一的页面异常处理 - *

- * 要继承 RuntimeException - *

- * - * @package: com.xkcoding.springbootdemoexceptionhandler.exception - * @description: 统一的页面异常处理 - * @author: yangkai.shen - * @date: Created in 2017/11/24 下午1:32 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Getter -public class DemoPageException extends RuntimeException { - public Integer code; - - public DemoPageException(Integer code, String message) { - super(message); - this.code = code; - } -} diff --git a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/handler/DemoExceptionHandler.java b/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/handler/DemoExceptionHandler.java deleted file mode 100644 index 62a3824..0000000 --- a/spring-boot-demo-exceptionhandler/src/main/java/com/xkcoding/springbootdemoexceptionhandler/handler/DemoExceptionHandler.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.xkcoding.springbootdemoexceptionhandler.handler; - -import com.xkcoding.springbootdemoexceptionhandler.domain.R; -import com.xkcoding.springbootdemoexceptionhandler.exception.DemoJsonException; -import com.xkcoding.springbootdemoexceptionhandler.exception.DemoPageException; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; - -/** - * 自定义异常统一处理 - * - * @package: com.xkcoding.springbootdemoexceptionhandler.handler - * @description: 自定义异常统一处理 - * @author: yangkai.shen - * @date: Created in 2017/11/24 下午1:37 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@ControllerAdvice -@Slf4j -public class DemoExceptionHandler { - public static final String DEFAULT_ERROR_VIEW = "error"; - - /** - * 统一 json 异常处理 - * - * @param exception DemoJsonException - * @return 统一返回 json 格式 - */ - @ExceptionHandler(value = DemoJsonException.class) - @ResponseBody - public R jsonErrorHandler(DemoJsonException exception) { - log.error("【DemoJsonException】:{}", exception.getMessage()); - return R.error(exception); - } - - /** - * 统一 页面 异常处理 - * - * @param exception DemoPageException - * @return 统一跳转到异常页面 - */ - @ExceptionHandler(value = DemoPageException.class) - public ModelAndView pageErrorHandler(DemoPageException exception) { - log.error("【DemoPageException】:{}", exception.getMessage()); - ModelAndView view = new ModelAndView(); - view.addObject("message", exception.getMessage()); - view.setViewName(DEFAULT_ERROR_VIEW); - return view; - } -} diff --git a/spring-boot-demo-exceptionhandler/src/main/resources/application.yml b/spring-boot-demo-exceptionhandler/src/main/resources/application.yml deleted file mode 100644 index 9b72a64..0000000 --- a/spring-boot-demo-exceptionhandler/src/main/resources/application.yml +++ /dev/null @@ -1,9 +0,0 @@ -server: - port: 8080 - context-path: /demo -spring: - thymeleaf: - mode: HTML5 - encoding: UTF-8 - content-type: text/html - cache: false \ No newline at end of file diff --git a/spring-boot-demo-exceptionhandler/src/main/resources/templates/error.html b/spring-boot-demo-exceptionhandler/src/main/resources/templates/error.html deleted file mode 100644 index 0b8c802..0000000 --- a/spring-boot-demo-exceptionhandler/src/main/resources/templates/error.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - 统一页面异常处理 - - -

统一页面异常处理

-
- - \ No newline at end of file diff --git a/spring-boot-demo-exceptionhandler/src/test/java/com/xkcoding/springbootdemoexceptionhandler/SpringBootDemoExceptionhandlerApplicationTests.java b/spring-boot-demo-exceptionhandler/src/test/java/com/xkcoding/springbootdemoexceptionhandler/SpringBootDemoExceptionhandlerApplicationTests.java deleted file mode 100644 index 9cea0ee..0000000 --- a/spring-boot-demo-exceptionhandler/src/test/java/com/xkcoding/springbootdemoexceptionhandler/SpringBootDemoExceptionhandlerApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemoexceptionhandler; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoExceptionhandlerApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-helloworld/README.md b/spring-boot-demo-helloworld/README.md deleted file mode 100644 index 075d12d..0000000 --- a/spring-boot-demo-helloworld/README.md +++ /dev/null @@ -1,84 +0,0 @@ -# spring-boot-demo-helloworld - -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent) - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-helloworld - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-helloworld - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - spring-boot-demo-helloworld - - - -``` - -### SpringBootDemoHelloworldApplication.java - -```java -@RestController -@SpringBootApplication -@Configuration -public class SpringBootDemoHelloworldApplication { - @Value("${spring.boot.demo.helloworld.data.version}") - private String version; - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoHelloworldApplication.class, args); - } - - @GetMapping("/hello") - public Map sayHello(@Value("${author}") String author, @Value("${exclusions}") String exclusions, @Value("${connectionProperties}") String connectionProperties) { - Map result = Maps.newHashMap(); - result.put("ret", true); - result.put("msg", StrUtil.format("hello,world,{}", author)); - Map data = Maps.newHashMap(); - data.put("version", version); - data.put("exclusions", exclusions.split(",")); - Map connectionProperty = Maps.newHashMap(); - for (String connection : connectionProperties.split(";")) { - String[] conn = connection.split("="); - connectionProperty.put(conn[0], conn[1]); - } - data.put("connectionProperties", connectionProperty); - result.put("data", data); - return result; - } -} -``` - -### application.yml - -```yaml -server: - port: 8080 - context-path: /demo -spring: - boot: - demo: - helloworld: - data: - version: 1.0.0 -author: xkcoding -exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" -connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 -``` - diff --git a/spring-boot-demo-helloworld/pom.xml b/spring-boot-demo-helloworld/pom.xml deleted file mode 100644 index adda975..0000000 --- a/spring-boot-demo-helloworld/pom.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-helloworld - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-helloworld - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - spring-boot-demo-helloworld - - - diff --git a/spring-boot-demo-helloworld/src/main/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplication.java b/spring-boot-demo-helloworld/src/main/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplication.java deleted file mode 100644 index b309446..0000000 --- a/spring-boot-demo-helloworld/src/main/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplication.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.xkcoding.springbootdemohelloworld; - -import com.google.common.collect.*; -import com.xiaoleilu.hutool.util.StrUtil; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.HashMap; -import java.util.Map; - -@RestController -@SpringBootApplication -@Configuration -public class SpringBootDemoHelloworldApplication { - @Value("${spring.boot.demo.helloworld.data.version}") - private String version; - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoHelloworldApplication.class, args); - } - - @GetMapping("/hello") - public Map sayHello(@Value("${author}") String author, @Value("${exclusions}") String exclusions, @Value("${connectionProperties}") String connectionProperties) { - Map result = Maps.newHashMap(); - result.put("ret", true); - result.put("msg", StrUtil.format("hello,world,{}", author)); - Map data = Maps.newHashMap(); - data.put("version", version); - data.put("exclusions", exclusions.split(",")); - Map connectionProperty = Maps.newHashMap(); - for (String connection : connectionProperties.split(";")) { - String[] conn = connection.split("="); - connectionProperty.put(conn[0], conn[1]); - } - data.put("connectionProperties", connectionProperty); - result.put("data", data); - return result; - } -} diff --git a/spring-boot-demo-helloworld/src/main/resources/application.yml b/spring-boot-demo-helloworld/src/main/resources/application.yml deleted file mode 100644 index 1905f0c..0000000 --- a/spring-boot-demo-helloworld/src/main/resources/application.yml +++ /dev/null @@ -1,12 +0,0 @@ -server: - port: 8080 - context-path: /demo -spring: - boot: - demo: - helloworld: - data: - version: 1.0.0 -author: xkcoding -exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" -connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 \ No newline at end of file diff --git a/spring-boot-demo-helloworld/src/test/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplicationTests.java b/spring-boot-demo-helloworld/src/test/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplicationTests.java deleted file mode 100644 index 9d3de5c..0000000 --- a/spring-boot-demo-helloworld/src/test/java/com/xkcoding/springbootdemohelloworld/SpringBootDemoHelloworldApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemohelloworld; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoHelloworldApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-logback/README.md b/spring-boot-demo-logback/README.md deleted file mode 100644 index 0cb30f4..0000000 --- a/spring-boot-demo-logback/README.md +++ /dev/null @@ -1,122 +0,0 @@ -# spring-boot-demo-logback - -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent) - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-logback - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-logback - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - spring-boot-demo-logback - - - -``` - -### SpringBootDemoLogbackApplication.java - -```java -@SpringBootApplication -@Slf4j -public class SpringBootDemoLogbackApplication { - - public static void main(String[] args) { - ConfigurableApplicationContext context = SpringApplication.run(SpringBootDemoLogbackApplication.class, args); - int length = context.getBeanDefinitionNames().length; - log.trace("Spring boot启动初始化了 {} 个 Bean", length); - log.debug("Spring boot启动初始化了 {} 个 Bean", length); - log.info("Spring boot启动初始化了 {} 个 Bean", length); - log.warn("Spring boot启动初始化了 {} 个 Bean", length); - log.error("Spring boot启动初始化了 {} 个 Bean", length); - try { - int i = 0; - int j = 1 / i; - } catch (Exception e) { - log.error("【SpringBootDemoLogbackApplication】启动异常:", e); - } - } -} -``` - -### application.yml - -```yaml -server: - port: 8080 - context-path: /demo -spring: - application: - name: logback-demo -``` - -### logback-spring.xml - -```xml - - - - - - - - - 【xkcoding】%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx} - - - - - - - - - ${user.dir}/logs/log/logback-demo.%d.log - - - 【xkcoding】%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n - - - - - - ERROR - ACCEPT - DENY - - - - - ${user.dir}/logs/error/logback-demo.%d.error - - - 【xkcoding】%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n - - - - - - - - - -``` \ No newline at end of file diff --git a/spring-boot-demo-logback/pom.xml b/spring-boot-demo-logback/pom.xml deleted file mode 100644 index ed9b172..0000000 --- a/spring-boot-demo-logback/pom.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-logback - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-logback - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - spring-boot-demo-logback - - - diff --git a/spring-boot-demo-logback/src/main/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplication.java b/spring-boot-demo-logback/src/main/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplication.java deleted file mode 100644 index 887b847..0000000 --- a/spring-boot-demo-logback/src/main/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplication.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.xkcoding.springbootdemologback; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.ConfigurableApplicationContext; - -@SpringBootApplication -@Slf4j -public class SpringBootDemoLogbackApplication { - - public static void main(String[] args) { - ConfigurableApplicationContext context = SpringApplication.run(SpringBootDemoLogbackApplication.class, args); - int length = context.getBeanDefinitionNames().length; - log.trace("Spring boot启动初始化了 {} 个 Bean", length); - log.debug("Spring boot启动初始化了 {} 个 Bean", length); - log.info("Spring boot启动初始化了 {} 个 Bean", length); - log.warn("Spring boot启动初始化了 {} 个 Bean", length); - log.error("Spring boot启动初始化了 {} 个 Bean", length); - try { - int i = 0; - int j = 1 / i; - } catch (Exception e) { - log.error("【SpringBootDemoLogbackApplication】启动异常:", e); - } - } -} diff --git a/spring-boot-demo-logback/src/main/resources/application.yml b/spring-boot-demo-logback/src/main/resources/application.yml deleted file mode 100644 index e8db9e6..0000000 --- a/spring-boot-demo-logback/src/main/resources/application.yml +++ /dev/null @@ -1,6 +0,0 @@ -server: - port: 8080 - context-path: /demo -spring: - application: - name: logback-demo \ No newline at end of file diff --git a/spring-boot-demo-logback/src/main/resources/logback-spring.xml b/spring-boot-demo-logback/src/main/resources/logback-spring.xml deleted file mode 100644 index 014e9cb..0000000 --- a/spring-boot-demo-logback/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - 【xkcoding】%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx} - - - - - - - - - ${user.dir}/logs/log/logback-demo.%d.log - - - 【xkcoding】%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n - - - - - - ERROR - ACCEPT - DENY - - - - - ${user.dir}/logs/error/logback-demo.%d.error - - - 【xkcoding】%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-demo-logback/src/test/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplicationTests.java b/spring-boot-demo-logback/src/test/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplicationTests.java deleted file mode 100644 index d3bf455..0000000 --- a/spring-boot-demo-logback/src/test/java/com/xkcoding/springbootdemologback/SpringBootDemoLogbackApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemologback; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoLogbackApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-orm-jdbctemplate/README.md b/spring-boot-demo-orm-jdbctemplate/README.md deleted file mode 100644 index 99ce53c..0000000 --- a/spring-boot-demo-orm-jdbctemplate/README.md +++ /dev/null @@ -1,193 +0,0 @@ -# spring-boot-demo-orm-jdbctemplate -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent)、spring-boot-starter-jdbc - -## pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-orm-jdbctemplate - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-orm-jdbctemplate - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - org.springframework.boot - spring-boot-starter-jdbc - - - com.alibaba - druid-spring-boot-starter - 1.1.9 - - - - - spring-boot-demo-orm-jdbctemplate - - - -``` - -## application.yml - -```yaml -server: - port: 8080 - context-path: /demo -spring: - datasource: - # 启动时自动运行的 SQL 文件 - schema: classpath:init-sql/schema.sql - continue-on-error: true - druid: - url: jdbc:mysql://localhost:3306/spring-boot-demo?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false - username: root - password: root - driver-class-name: com.mysql.jdbc.Driver - # 连接池配置 - # 初始化大小,最小,最大 - initialSize: 5 - minIdle: 5 - maxActive: 20 - # 配置获取连接等待超时的时间 - maxWait: 60000 - # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 - timeBetweenEvictionRunsMillis: 60000 - # 配置一个连接在池中最小生存的时间,单位是毫秒 - minEvictableIdleTimeMillis: 300000 - validationQuery: SELECT 1 FROM DUAL - testWhileIdle: true - testOnBorrow: false - testOnReturn: false - # 打开PSCache,并且指定每个连接上PSCache的大小 - poolPreparedStatements: true - maxPoolPreparedStatementPerConnectionSize: 20 - # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 - filters: stat,wall,log4j - # 监控配置 - web-stat-filter: - enabled: true - url-pattern: /* - exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" - stat-view-servlet: - enabled: true - url-pattern: /sys/druid/* - reset-enable: fasle - login-username: xkcoding - login-password: 123456 - filter: - stat: - log-slow-sql: true - slow-sql-millis: 5000 - merge-sql: true -``` - -## schema.sql - -```mysql -SET FOREIGN_KEY_CHECKS=0; - -DROP TABLE IF EXISTS `jdbctemplate_user`; -CREATE TABLE `jdbctemplate_user` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(32) DEFAULT NULL, - `tel` varchar(11) DEFAULT NULL, - `create_time` datetime DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -INSERT INTO `jdbctemplate_user` VALUES (1, 'klay', '13799008800', '2017-11-13 16:04:39'); -INSERT INTO `jdbctemplate_user` VALUES (2, 'Tome', '18988991234', '2017-11-13 16:13:28'); -``` - -## UserServiceImpl.java - -```java -/** - *

- * UserServiceImpl - *

- * - * @package: com.xkcoding.springbootdemoormjdbctemplate.service.impl - * @description: UserServiceImpl - * @author: yangkai.shen - * @date: Created in 2018/5/11 下午3:27 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Service -public class UserServiceImpl implements UserService { - @Autowired - private JdbcTemplate jdbcTemplate; - - @Override - public Integer save(User user) { - String sql = "INSERT INTO jdbctemplate_user (name,tel,create_time) VALUES(?,?,?)"; - return jdbcTemplate.update(sql, user.getName(), user.getTel(), user.getCreateTime()); - } - - @Override - public Integer update(User user) { - String sql = "UPDATE jdbctemplate_user SET name = ?,tel = ? where id = ?"; - return jdbcTemplate.update(sql, user.getName(), user.getTel(), user.getId()); - } - - @Override - public Integer delete(User user) { - String sql = "DELETE FROM jdbctemplate_user where id = ?"; - return jdbcTemplate.update(sql, user.getId()); - } - - @Override - public User findById(Integer id) { - String sql = "SELECT * FROM jdbctemplate_user where id = ?"; - RowMapper rowMapper = new BeanPropertyRowMapper(User.class); - return jdbcTemplate.queryForObject(sql, new Object[]{id}, rowMapper); - } - - @Override - public User findByName(String name) { - String sql = "SELECT * FROM jdbctemplate_user where name = ?"; - RowMapper rowMapper = new BeanPropertyRowMapper(User.class); - return jdbcTemplate.queryForObject(sql, new Object[]{name}, rowMapper); - } - - @Override - public List findAll() { - String sql = "SELECT * FROM jdbctemplate_user"; - List> maps = jdbcTemplate.queryForList(sql); - List ret = Lists.newArrayList(); - maps.forEach(map -> ret.add(BeanUtil.fillBeanWithMap(map, new User(), true, false))); - return ret; - } - - @Override - public List findUserByPage(Integer pageNum, Integer pageSize) { - String sql = "SELECT * FROM jdbctemplate_user LIMIT ?,?"; - Integer offset = (pageNum - 1) * pageSize; - List> maps = jdbcTemplate.queryForList(sql, new Object[]{offset, pageSize}); - List ret = Lists.newArrayList(); - maps.forEach(map -> ret.add(BeanUtil.fillBeanWithMap(map, new User(), true, false))); - return ret; - } -} -``` - -## 其余代码 - -详情请参见本demo。 \ No newline at end of file diff --git a/spring-boot-demo-orm-jdbctemplate/pom.xml b/spring-boot-demo-orm-jdbctemplate/pom.xml deleted file mode 100644 index 13bb488..0000000 --- a/spring-boot-demo-orm-jdbctemplate/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-orm-jdbctemplate - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-orm-jdbctemplate - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - org.springframework.boot - spring-boot-starter-jdbc - - - com.alibaba - druid-spring-boot-starter - 1.1.9 - - - - - spring-boot-demo-orm-jdbctemplate - - - \ No newline at end of file diff --git a/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/SpringBootDemoOrmJdbctemplateApplication.java b/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/SpringBootDemoOrmJdbctemplateApplication.java deleted file mode 100644 index d8f6363..0000000 --- a/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/SpringBootDemoOrmJdbctemplateApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.xkcoding.springbootdemoormjdbctemplate; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringBootDemoOrmJdbctemplateApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoOrmJdbctemplateApplication.class, args); - } -} diff --git a/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/controller/UserController.java b/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/controller/UserController.java deleted file mode 100644 index b051872..0000000 --- a/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/controller/UserController.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.xkcoding.springbootdemoormjdbctemplate.controller; - -import com.xiaoleilu.hutool.util.StrUtil; -import com.xkcoding.springbootdemoormjdbctemplate.model.User; -import com.xkcoding.springbootdemoormjdbctemplate.service.UserService; -import com.xkcoding.springbootdemoormjdbctemplate.vo.R; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import java.util.Date; -import java.util.List; - -/** - *

- * UserController - *

- * - * @package: com.xkcoding.springbootdemoormjdbctemplate.controller - * @description: UserController - * @author: yangkai.shen - * @date: Created in 2018/5/11 下午3:52 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@RestController -@RequestMapping("/user") -public class UserController { - - @Autowired - private UserService userService; - - @GetMapping("/save") - public R save() { - User user = new User(); - user.setName("xkcoding"); - user.setTel("18600000000"); - user.setCreateTime(new Date()); - Integer save = userService.save(user); - if (save > 0) { - return R.builder().code(200).msg("添加成功").data(user).build(); - } - return R.builder().code(500).msg("添加失败").data(null).build(); - } - - @GetMapping("/update") - public R update() { - User user = new User(); - user.setId(2); - user.setName(" 修改后的名字 "); - user.setTel("17300000000"); - Integer update = userService.update(user); - if (update > 0) { - return R.builder().code(200).msg("修改成功").data(userService.findById(2)).build(); - } - return R.builder().code(500).msg("修改失败").data(null).build(); - } - - @GetMapping("/delete") - public R delete() { - User user = new User(); - user.setId(1); - Integer delete = userService.delete(user); - - if (delete > 0) { - return R.builder().code(200).msg("删除成功").data(null).build(); - } - return R.builder().code(500).msg("删除失败").data(null).build(); - } - - @GetMapping("/find/{id}") - public R findById(@PathVariable Integer id) { - User user = userService.findById(id); - return R.builder().code(user == null ? 404 : 200).msg(user == null ? StrUtil.format("没有ID为{}的用户", id) : "查询成功").data(user).build(); - } - - @GetMapping("/find") - public R findByName(@RequestParam String name) { - User user = userService.findByName(name); - return R.builder().code(user == null ? 404 : 200).msg(user == null ? StrUtil.format("没有姓名为{}的用户", name) : "查询成功").data(user).build(); - } - - @GetMapping({"", "/"}) - public R findAll() { - List userList = userService.findAll(); - return R.builder().code(userList.isEmpty() ? 404 : 200).msg(userList.isEmpty() ? "暂无用户" : "查询成功").data(userList).build(); - } - - @GetMapping("/page") - public R findByPage(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize) { - List userList = userService.findUserByPage(pageNum, pageSize); - return R.builder().code(userList.isEmpty() ? 404 : 200).msg(userList.isEmpty() ? "暂无用户" : "查询成功").data(userList).build(); - } -} diff --git a/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/model/User.java b/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/model/User.java deleted file mode 100644 index 3f970db..0000000 --- a/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/model/User.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.xkcoding.springbootdemoormjdbctemplate.model; - -import lombok.Data; - -import java.io.Serializable; -import java.util.Date; - -/** - *

- * 实体类 - *

- * - * @package: com.xkcoding.springbootdemoormjdbctemplate.model - * @description: 实体类 - * @author: yangkai.shen - * @date: Created in 2018/5/11 下午3:24 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Data -public class User implements Serializable { - private int id; - private String name; - private String tel; - private Date createTime; -} diff --git a/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/service/UserService.java b/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/service/UserService.java deleted file mode 100644 index 99e98a7..0000000 --- a/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/service/UserService.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.xkcoding.springbootdemoormjdbctemplate.service; - -import com.xkcoding.springbootdemoormjdbctemplate.model.User; - -import java.util.List; - -/** - *

- * UserService - *

- * - * @package: com.xkcoding.springbootdemoormjdbctemplate.service - * @description: UserService - * @author: yangkai.shen - * @date: Created in 2018/5/11 下午3:26 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -public interface UserService { - Integer save(User user); - - Integer update(User user); - - Integer delete(User user); - - User findById(Integer id); - - User findByName(String name); - - List findAll(); - - List findUserByPage(Integer pageNum, Integer pageSize); -} diff --git a/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/service/impl/UserServiceImpl.java b/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/service/impl/UserServiceImpl.java deleted file mode 100644 index 28f397d..0000000 --- a/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/service/impl/UserServiceImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.xkcoding.springbootdemoormjdbctemplate.service.impl; - -import com.google.common.collect.Lists; -import com.xiaoleilu.hutool.bean.BeanUtil; -import com.xkcoding.springbootdemoormjdbctemplate.model.User; -import com.xkcoding.springbootdemoormjdbctemplate.service.UserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.BeanPropertyRowMapper; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Map; - -/** - *

- * UserServiceImpl - *

- * - * @package: com.xkcoding.springbootdemoormjdbctemplate.service.impl - * @description: UserServiceImpl - * @author: yangkai.shen - * @date: Created in 2018/5/11 下午3:27 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Service -public class UserServiceImpl implements UserService { - @Autowired - private JdbcTemplate jdbcTemplate; - - @Override - public Integer save(User user) { - String sql = "INSERT INTO jdbctemplate_user (name,tel,create_time) VALUES(?,?,?)"; - return jdbcTemplate.update(sql, user.getName(), user.getTel(), user.getCreateTime()); - } - - @Override - public Integer update(User user) { - String sql = "UPDATE jdbctemplate_user SET name = ?,tel = ? where id = ?"; - return jdbcTemplate.update(sql, user.getName(), user.getTel(), user.getId()); - } - - @Override - public Integer delete(User user) { - String sql = "DELETE FROM jdbctemplate_user where id = ?"; - return jdbcTemplate.update(sql, user.getId()); - } - - @Override - public User findById(Integer id) { - String sql = "SELECT * FROM jdbctemplate_user where id = ?"; - RowMapper rowMapper = new BeanPropertyRowMapper(User.class); - return jdbcTemplate.queryForObject(sql, new Object[]{id}, rowMapper); - } - - @Override - public User findByName(String name) { - String sql = "SELECT * FROM jdbctemplate_user where name = ?"; - RowMapper rowMapper = new BeanPropertyRowMapper(User.class); - return jdbcTemplate.queryForObject(sql, new Object[]{name}, rowMapper); - } - - @Override - public List findAll() { - String sql = "SELECT * FROM jdbctemplate_user"; - List> maps = jdbcTemplate.queryForList(sql); - List ret = Lists.newArrayList(); - maps.forEach(map -> ret.add(BeanUtil.fillBeanWithMap(map, new User(), true, false))); - return ret; - } - - @Override - public List findUserByPage(Integer pageNum, Integer pageSize) { - String sql = "SELECT * FROM jdbctemplate_user LIMIT ?,?"; - Integer offset = (pageNum - 1) * pageSize; - List> maps = jdbcTemplate.queryForList(sql, new Object[]{offset, pageSize}); - List ret = Lists.newArrayList(); - maps.forEach(map -> ret.add(BeanUtil.fillBeanWithMap(map, new User(), true, false))); - return ret; - } -} diff --git a/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/vo/R.java b/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/vo/R.java deleted file mode 100644 index 8828204..0000000 --- a/spring-boot-demo-orm-jdbctemplate/src/main/java/com/xkcoding/springbootdemoormjdbctemplate/vo/R.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.xkcoding.springbootdemoormjdbctemplate.vo; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - *

- * 统一返回结果类型 - *

- * - * @package: com.xkcoding.springbootdemoormjdbctemplate.vo - * @description: 统一返回结果类型 - * @author: yangkai.shen - * @date: Created in 2018/5/11 下午3:53 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -public class R { - private int code; - private String msg; - private Object data; -} diff --git a/spring-boot-demo-orm-jdbctemplate/src/main/resources/application.yml b/spring-boot-demo-orm-jdbctemplate/src/main/resources/application.yml deleted file mode 100644 index e8332df..0000000 --- a/spring-boot-demo-orm-jdbctemplate/src/main/resources/application.yml +++ /dev/null @@ -1,49 +0,0 @@ -server: - port: 8080 - context-path: /demo -spring: - datasource: - # 启动时自动运行的 SQL 文件 - schema: classpath:init-sql/schema.sql - continue-on-error: true - druid: - url: jdbc:mysql://localhost:3306/spring-boot-demo?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false - username: root - password: root - driver-class-name: com.mysql.jdbc.Driver - # 连接池配置 - # 初始化大小,最小,最大 - initialSize: 5 - minIdle: 5 - maxActive: 20 - # 配置获取连接等待超时的时间 - maxWait: 60000 - # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 - timeBetweenEvictionRunsMillis: 60000 - # 配置一个连接在池中最小生存的时间,单位是毫秒 - minEvictableIdleTimeMillis: 300000 - validationQuery: SELECT 1 FROM DUAL - testWhileIdle: true - testOnBorrow: false - testOnReturn: false - # 打开PSCache,并且指定每个连接上PSCache的大小 - poolPreparedStatements: true - maxPoolPreparedStatementPerConnectionSize: 20 - # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 - filters: stat,wall,log4j - # 监控配置 - web-stat-filter: - enabled: true - url-pattern: /* - exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" - stat-view-servlet: - enabled: true - url-pattern: /sys/druid/* - reset-enable: fasle - login-username: xkcoding - login-password: 123456 - filter: - stat: - log-slow-sql: true - slow-sql-millis: 5000 - merge-sql: true \ No newline at end of file diff --git a/spring-boot-demo-orm-jdbctemplate/src/main/resources/init-sql/schema.sql b/spring-boot-demo-orm-jdbctemplate/src/main/resources/init-sql/schema.sql deleted file mode 100644 index 5d5d9b9..0000000 --- a/spring-boot-demo-orm-jdbctemplate/src/main/resources/init-sql/schema.sql +++ /dev/null @@ -1,13 +0,0 @@ -SET FOREIGN_KEY_CHECKS=0; - -DROP TABLE IF EXISTS `jdbctemplate_user`; -CREATE TABLE `jdbctemplate_user` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(32) DEFAULT NULL, - `tel` varchar(11) DEFAULT NULL, - `create_time` datetime DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -INSERT INTO `jdbctemplate_user` VALUES (1, 'klay', '13799008800', '2017-11-13 16:04:39'); -INSERT INTO `jdbctemplate_user` VALUES (2, 'Tome', '18988991234', '2017-11-13 16:13:28'); diff --git a/spring-boot-demo-orm-jdbctemplate/src/test/java/com/xkcoding/springbootdemoormjdbctemplate/SpringBootDemoOrmJdbctemplateApplicationTests.java b/spring-boot-demo-orm-jdbctemplate/src/test/java/com/xkcoding/springbootdemoormjdbctemplate/SpringBootDemoOrmJdbctemplateApplicationTests.java deleted file mode 100644 index a98a78b..0000000 --- a/spring-boot-demo-orm-jdbctemplate/src/test/java/com/xkcoding/springbootdemoormjdbctemplate/SpringBootDemoOrmJdbctemplateApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemoormjdbctemplate; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoOrmJdbctemplateApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-orm-jpa/README.md b/spring-boot-demo-orm-jpa/README.md deleted file mode 100644 index 6f2c4fc..0000000 --- a/spring-boot-demo-orm-jpa/README.md +++ /dev/null @@ -1,148 +0,0 @@ -# spring-boot-demo-jpa - -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent)、`spring-boot-starter-data-jpa`、`druid-spring-boot-starter` - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-orm-jpa - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-orm-jpa - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent - - - - 1.1.5 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - com.alibaba - druid-spring-boot-starter - ${druid.starter.version} - - - - - spring-boot-demo-orm-jpa - - - -``` - -### application.yml - -```yaml -server: - port: 8080 - context-path: /demo -spring: - datasource: - continue-on-error: true - druid: - url: jdbc:mysql://localhost:3306/spring-boot-demo?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false - username: root - password: root - driver-class-name: com.mysql.jdbc.Driver - # 连接池配置 - # 初始化大小,最小,最大 - initialSize: 5 - minIdle: 5 - maxActive: 20 - # 配置获取连接等待超时的时间 - maxWait: 60000 - # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 - timeBetweenEvictionRunsMillis: 60000 - # 配置一个连接在池中最小生存的时间,单位是毫秒 - minEvictableIdleTimeMillis: 300000 - validationQuery: SELECT 1 FROM DUAL - testWhileIdle: true - testOnBorrow: false - testOnReturn: false - # 打开PSCache,并且指定每个连接上PSCache的大小 - poolPreparedStatements: true - maxPoolPreparedStatementPerConnectionSize: 20 - # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 - filters: stat,wall,log4j - # 监控配置 - web-stat-filter: - enabled: true - url-pattern: /* - exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" - stat-view-servlet: - enabled: true - url-pattern: /sys/druid/* - reset-enable: fasle - login-username: xkcoding - login-password: 123456 - filter: - stat: - log-slow-sql: true - slow-sql-millis: 5000 - merge-sql: true - jpa: - hibernate: - ddl-auto: create-drop - show-sql: true -``` - -### JpaUser.java - -```java -@Entity -@Data -@DynamicUpdate -public class JpaUser { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(name = "name") - private String name; - - @Column(name = "create_time") - private Date createTime; -} -``` - -### JpaUserRepository.java - -```java -public interface JpaUserRepository extends JpaRepository { - - /** - * 自定义一个查询,HQL,根据姓名查询 - * - * @param name 名称 - * @return JpaUser - */ - @Query("from JpaUser u where u.name like :name") - JpaUser findJpaUser(@Param("name") String name); - - JpaUser findJpaUserByName(String name); - - List findJpaUsersByIdIn(List ids); - -} -``` - -### 其余代码 - -详情请参见本demo。 \ No newline at end of file diff --git a/spring-boot-demo-orm-jpa/pom.xml b/spring-boot-demo-orm-jpa/pom.xml deleted file mode 100644 index 1414b6c..0000000 --- a/spring-boot-demo-orm-jpa/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-orm-jpa - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-orm-jpa - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent - - - - 1.1.5 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - com.alibaba - druid-spring-boot-starter - ${druid.starter.version} - - - - - spring-boot-demo-orm-jpa - - - \ No newline at end of file diff --git a/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/SpringBootDemoOrmJpaApplication.java b/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/SpringBootDemoOrmJpaApplication.java deleted file mode 100644 index 88d9275..0000000 --- a/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/SpringBootDemoOrmJpaApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.xkcoding.springbootdemoormjpa; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringBootDemoOrmJpaApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoOrmJpaApplication.class, args); - } -} diff --git a/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/controller/JpaUserController.java b/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/controller/JpaUserController.java deleted file mode 100644 index e488b16..0000000 --- a/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/controller/JpaUserController.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.xkcoding.springbootdemoormjpa.controller; - -import com.google.common.collect.Lists; -import com.xkcoding.springbootdemoormjpa.entity.JpaUser; -import com.xkcoding.springbootdemoormjpa.service.JpaUserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.web.bind.annotation.*; - -import java.util.Date; -import java.util.List; - -@RestController -@RequestMapping("/user") -public class JpaUserController { - @Autowired - private JpaUserService jpaUserService; - - @GetMapping("/{id}") - public JpaUser findById(@PathVariable Long id) { - return jpaUserService.findById(id); - } - - @GetMapping({"", "/", "/index"}) - public List findAll() { - return jpaUserService.findAll(); - } - - @GetMapping("/save") - public JpaUser insert() { - JpaUser user = new JpaUser(); - user.setName("xkcoding"); - user.setCreateTime(new Date()); - return jpaUserService.insert(user); - } - - @GetMapping("/update") - public JpaUser update() { - JpaUser user = jpaUserService.findById(1L); - user.setName("修改后的姓名"); - return jpaUserService.update(user); - } - - @GetMapping("/delete/{id}") - public String delete(@PathVariable Integer id) { - if (id == null) { - return "Id 不能为空"; - } - JpaUser jpaUser = jpaUserService.findById(id.longValue()); - if (jpaUser == null) { - return "用户不存在"; - } - jpaUserService.delete(jpaUser); - return jpaUser.getName() + "删除成功"; - } - - @GetMapping("/saveList") - public List insertList() { - List userList = Lists.newArrayList(); - for (int i = 0; i < 20; i++) { - JpaUser jpaUser = new JpaUser(); - jpaUser.setName("xkcoding" + i); - jpaUser.setCreateTime(new Date()); - userList.add(jpaUser); - } - return jpaUserService.insertList(userList); - } - - @GetMapping("/find") - public JpaUser findJpaUser(@RequestParam String name) { - return jpaUserService.findJpaUser(name); - } - - @GetMapping("/find/in") - public List findJpaUsersByIdIn() { - List ids = Lists.newArrayList(1L, 2L, 3L); - return jpaUserService.findJpaUsersByIdIn(ids); - } - - @GetMapping("/page") - public Page findByPage(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) { - PageRequest pageRequest = new PageRequest(pageNum - 1, pageSize); - return jpaUserService.findByPage(pageRequest); - } -} diff --git a/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/entity/JpaUser.java b/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/entity/JpaUser.java deleted file mode 100644 index 966ab88..0000000 --- a/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/entity/JpaUser.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.xkcoding.springbootdemoormjpa.entity; - -import lombok.Data; -import org.hibernate.annotations.DynamicUpdate; - -import javax.persistence.*; -import java.util.Date; - -@Entity -@Data -@DynamicUpdate -public class JpaUser { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(name = "name") - private String name; - - @Column(name = "create_time") - private Date createTime; -} diff --git a/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/repository/JpaUserRepository.java b/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/repository/JpaUserRepository.java deleted file mode 100644 index 1d041bc..0000000 --- a/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/repository/JpaUserRepository.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.xkcoding.springbootdemoormjpa.repository; - -import com.xkcoding.springbootdemoormjpa.entity.JpaUser; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.List; - -public interface JpaUserRepository extends JpaRepository { - - /** - * 自定义一个查询,HQL,根据姓名查询 - * - * @param name 名称 - * @return JpaUser - */ - @Query("from JpaUser u where u.name like :name") - JpaUser findJpaUser(@Param("name") String name); - - JpaUser findJpaUserByName(String name); - - List findJpaUsersByIdIn(List ids); - -} diff --git a/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/service/JpaUserService.java b/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/service/JpaUserService.java deleted file mode 100644 index 51c4af3..0000000 --- a/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/service/JpaUserService.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.xkcoding.springbootdemoormjpa.service; - -import com.xkcoding.springbootdemoormjpa.entity.JpaUser; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -import java.util.List; - -public interface JpaUserService { - JpaUser findById(Long id); - - List findAll(); - - JpaUser insert(JpaUser user); - - JpaUser update(JpaUser user); - - void delete(JpaUser user); - - List insertList(List userList); - - JpaUser findJpaUser(String name); - - List findJpaUsersByIdIn(List ids); - - Page findByPage(Pageable pageable); -} diff --git a/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/service/impl/JpaUserServiceImpl.java b/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/service/impl/JpaUserServiceImpl.java deleted file mode 100644 index 60748d9..0000000 --- a/spring-boot-demo-orm-jpa/src/main/java/com/xkcoding/springbootdemoormjpa/service/impl/JpaUserServiceImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.xkcoding.springbootdemoormjpa.service.impl; - -import com.xkcoding.springbootdemoormjpa.entity.JpaUser; -import com.xkcoding.springbootdemoormjpa.repository.JpaUserRepository; -import com.xkcoding.springbootdemoormjpa.service.JpaUserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -public class JpaUserServiceImpl implements JpaUserService { - @Autowired - private JpaUserRepository jpaUserRepository; - - @Override - public JpaUser findById(Long id) { - return jpaUserRepository.findOne(id); - } - - @Override - public List findAll() { - return jpaUserRepository.findAll(); - } - - @Override - public JpaUser insert(JpaUser user) { - return jpaUserRepository.save(user); - } - - @Override - public JpaUser update(JpaUser user) { - return jpaUserRepository.save(user); - } - - @Override - public void delete(JpaUser user) { - jpaUserRepository.delete(user); - } - - @Override - public List insertList(List userList) { - return jpaUserRepository.save(userList); - } - - @Override - public JpaUser findJpaUser(String name) { - return jpaUserRepository.findJpaUser(name); - } - - @Override - public List findJpaUsersByIdIn(List ids) { - return jpaUserRepository.findJpaUsersByIdIn(ids); - } - - @Override - public Page findByPage(Pageable pageable) { - return jpaUserRepository.findAll(pageable); - } -} diff --git a/spring-boot-demo-orm-jpa/src/main/resources/application.yml b/spring-boot-demo-orm-jpa/src/main/resources/application.yml deleted file mode 100644 index 9cadf45..0000000 --- a/spring-boot-demo-orm-jpa/src/main/resources/application.yml +++ /dev/null @@ -1,51 +0,0 @@ -server: - port: 8080 - context-path: /demo -spring: - datasource: - continue-on-error: true - druid: - url: jdbc:mysql://localhost:3306/spring-boot-demo?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false - username: root - password: root - driver-class-name: com.mysql.jdbc.Driver - # 连接池配置 - # 初始化大小,最小,最大 - initialSize: 5 - minIdle: 5 - maxActive: 20 - # 配置获取连接等待超时的时间 - maxWait: 60000 - # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 - timeBetweenEvictionRunsMillis: 60000 - # 配置一个连接在池中最小生存的时间,单位是毫秒 - minEvictableIdleTimeMillis: 300000 - validationQuery: SELECT 1 FROM DUAL - testWhileIdle: true - testOnBorrow: false - testOnReturn: false - # 打开PSCache,并且指定每个连接上PSCache的大小 - poolPreparedStatements: true - maxPoolPreparedStatementPerConnectionSize: 20 - # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 - filters: stat,wall,log4j - # 监控配置 - web-stat-filter: - enabled: true - url-pattern: /* - exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" - stat-view-servlet: - enabled: true - url-pattern: /sys/druid/* - reset-enable: fasle - login-username: xkcoding - login-password: 123456 - filter: - stat: - log-slow-sql: true - slow-sql-millis: 5000 - merge-sql: true - jpa: - hibernate: - ddl-auto: create-drop - show-sql: true diff --git a/spring-boot-demo-orm-jpa/src/test/java/com/xkcoding/springbootdemoormjpa/SpringBootDemoOrmJpaApplicationTests.java b/spring-boot-demo-orm-jpa/src/test/java/com/xkcoding/springbootdemoormjpa/SpringBootDemoOrmJpaApplicationTests.java deleted file mode 100644 index 943f38d..0000000 --- a/spring-boot-demo-orm-jpa/src/test/java/com/xkcoding/springbootdemoormjpa/SpringBootDemoOrmJpaApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemoormjpa; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoOrmJpaApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-orm-mybatis/README.md b/spring-boot-demo-orm-mybatis/README.md deleted file mode 100644 index 86ea32e..0000000 --- a/spring-boot-demo-orm-mybatis/README.md +++ /dev/null @@ -1,244 +0,0 @@ -# spring-boot-demo-orm-mybatis - -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent)、`mybatis-spring-boot-starter`、`druid-spring-boot-starter`、`mapper-spring-boot-starter`(通用Mapper)、`pagehelper-spring-boot-starter`(分页插件PageHelper) - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-orm-mybatis - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-orm-mybatis - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - 1.3.1 - 1.1.5 - 1.1.1 - 1.1.0 - - - - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - ${mybatis.starter.version} - - - - com.alibaba - druid-spring-boot-starter - ${druid.starter.version} - - - - tk.mybatis - mapper-spring-boot-starter - ${mapper.version} - - - - com.github.pagehelper - pagehelper-spring-boot-starter - ${pagehelper.version} - - - - - spring-boot-demo-orm-mybatis - - - -``` - -### application.yml - -```yaml -server: - port: 8080 - context-path: /demo -spring: - # json 转化移除 null 字段 - # jackson: - # default-property-inclusion: non_null - datasource: - # 启动时自动运行的 SQL 文件 - schema: classpath:init-sql/schema.sql - continue-on-error: true - druid: - url: jdbc:mysql://localhost:3306/spring-boot-demo?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false - username: root - password: root - driver-class-name: com.mysql.jdbc.Driver - # 连接池配置 - # 初始化大小,最小,最大 - initialSize: 5 - minIdle: 5 - maxActive: 20 - # 配置获取连接等待超时的时间 - maxWait: 60000 - # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 - timeBetweenEvictionRunsMillis: 60000 - # 配置一个连接在池中最小生存的时间,单位是毫秒 - minEvictableIdleTimeMillis: 300000 - validationQuery: SELECT 1 FROM DUAL - testWhileIdle: true - testOnBorrow: false - testOnReturn: false - # 打开PSCache,并且指定每个连接上PSCache的大小 - poolPreparedStatements: true - maxPoolPreparedStatementPerConnectionSize: 20 - # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 - filters: stat,wall,log4j - # 监控配置 - web-stat-filter: - enabled: true - url-pattern: /* - exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" - stat-view-servlet: - enabled: true - url-pattern: /sys/druid/* - reset-enable: fasle - login-username: xkcoding - login-password: 123456 - filter: - stat: - log-slow-sql: true - slow-sql-millis: 5000 - merge-sql: true -# mybatis 配置 -mybatis: - type-aliases-package: com.xkcoding.springbootdemoormmybatistis.model - mapper-locations: classpath:mapper/*.xml - # 配置项:开启下划线到驼峰的自动转换. 作用:将数据库字段根据驼峰规则自动注入到对象属性 - configuration: - map-underscore-to-camel-case: true -# 通用 Mapper 配置 -mapper: - not-empty: false - identity: MYSQL - mappers: com.xkcoding.springbootdemoormmybatistis.util.MyMapper -# PageHelper 配置 -pagehelper: - helper-dialect: mysql - reasonable: true - support-methods-arguments: true - params: count=countSql -``` - -### schema.sql - -```mysql -SET FOREIGN_KEY_CHECKS=0; - --- ---------------------------- --- Table structure for `boot_user` --- ---------------------------- -DROP TABLE IF EXISTS `mybatis_user`; -CREATE TABLE `mybatis_user` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(32) DEFAULT NULL, - `tel` varchar(11) DEFAULT NULL, - `create_time` datetime DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- ---------------------------- --- Records of boot_user --- ---------------------------- -INSERT INTO `mybatis_user` VALUES (1, 'klay', '13799008800', '2017-11-13 16:04:39'); -INSERT INTO `mybatis_user` VALUES (2, 'Tome', '18988991234', '2017-11-13 16:13:28'); -``` - -### SpringBootDemoOrmMybatisApplication.java - -```java -@SpringBootApplication -@MapperScan(basePackages = {"com.xkcoding.springbootdemoormmybatis.mapper"}) -public class SpringBootDemoOrmMybatisApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoOrmMybatisApplication.class, args); - } -} -``` - -### MybatisUser.java - -```java -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -@ToString -@Table(name = "mybatis_user") -public class MybatisUser { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY,generator = "JDBC") - private Long id; - - @Column(name = "name") - private String name; - - @Column(name = "tel") - private String tel; - - @Column(name = "create_time") - private Date createTime; -} -``` - -### MyMapper.java - -```java -public interface MyMapper extends Mapper, MySqlMapper { -} -``` - -### MybatisUserMapper.java - -```java -@Component -public interface MybatisUserMapper extends MyMapper { - MybatisUser findByName(@Param("name") String name); -} -``` - -### MybatisUserMapper.xml - -```xml - - - - - - - - - - - - - - -``` - -### 其余代码 - -详情请参见本demo。 \ No newline at end of file diff --git a/spring-boot-demo-orm-mybatis/pom.xml b/spring-boot-demo-orm-mybatis/pom.xml deleted file mode 100644 index c38de00..0000000 --- a/spring-boot-demo-orm-mybatis/pom.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-orm-mybatis - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-orm-mybatis - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - 1.3.1 - 1.1.5 - 1.1.1 - 1.1.0 - - - - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - ${mybatis.starter.version} - - - - com.alibaba - druid-spring-boot-starter - ${druid.starter.version} - - - - tk.mybatis - mapper-spring-boot-starter - ${mapper.version} - - - - com.github.pagehelper - pagehelper-spring-boot-starter - ${pagehelper.version} - - - - - spring-boot-demo-orm-mybatis - - - diff --git a/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/SpringBootDemoOrmMybatisApplication.java b/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/SpringBootDemoOrmMybatisApplication.java deleted file mode 100644 index b0163dd..0000000 --- a/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/SpringBootDemoOrmMybatisApplication.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.xkcoding.springbootdemoormmybatis; - -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -@MapperScan(basePackages = {"com.xkcoding.springbootdemoormmybatis.mapper"}) -public class SpringBootDemoOrmMybatisApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoOrmMybatisApplication.class, args); - } -} diff --git a/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/controller/MybatisUserController.java b/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/controller/MybatisUserController.java deleted file mode 100644 index 8f4b250..0000000 --- a/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/controller/MybatisUserController.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.xkcoding.springbootdemoormmybatis.controller; - -import com.google.common.collect.Lists; -import com.xkcoding.springbootdemoormmybatis.model.MybatisUser; -import com.xkcoding.springbootdemoormmybatis.service.MybatisUserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -@RestController -@RequestMapping("/user") -public class MybatisUserController { - - @Autowired - private MybatisUserService mybatisUserService; - - @GetMapping("/save") - public MybatisUser save() { - MybatisUser mybatisUser = new MybatisUser(); - mybatisUser.setName("xkcoding"); - mybatisUser.setTel("18600000000"); - mybatisUser.setCreateTime(new Date()); - return mybatisUserService.save(mybatisUser); - } - - @GetMapping("/saveList") - public List saveList() { - ArrayList userList = Lists.newArrayList(); - for (int i = 0; i < 20; i++) { - MybatisUser mybatisUser = new MybatisUser(); - mybatisUser.setName("xkcoding" + i); - mybatisUser.setTel("186111111" + ((i < 10) ? ("0" + i) : i)); - mybatisUser.setCreateTime(new Date()); - userList.add(mybatisUser); - } - return mybatisUserService.saveList(userList); - } - - @GetMapping("/update") - public MybatisUser update() { - MybatisUser mybatisUser = new MybatisUser(); - mybatisUser.setId(2L); - mybatisUser.setName(" 修改后的名字 "); - mybatisUserService.update(mybatisUser); - - return mybatisUserService.update(mybatisUser); - } - - @GetMapping("/delete") - public MybatisUser delete() { - MybatisUser mybatisUser = new MybatisUser(); - mybatisUser.setId(1L); - mybatisUserService.delete(mybatisUser); - - return mybatisUserService.findById(1L); - } - - @GetMapping("/find/{id}") - public MybatisUser findById(@PathVariable Long id) { - return mybatisUserService.findById(id); - } - - @GetMapping("/find") - public MybatisUser findByName(@RequestParam String name) { - return mybatisUserService.findByName(name); - } - - @GetMapping({"", "/"}) - public List findAll() { - return mybatisUserService.findAll(); - } - - @GetMapping("/page") - public List findByPage(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize) { - return mybatisUserService.findMybatisUserByPage(pageNum, pageSize); - } -} diff --git a/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/mapper/MybatisUserMapper.java b/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/mapper/MybatisUserMapper.java deleted file mode 100644 index 71bbda0..0000000 --- a/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/mapper/MybatisUserMapper.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.xkcoding.springbootdemoormmybatis.mapper; - -import com.xkcoding.springbootdemoormmybatis.model.MybatisUser; -import com.xkcoding.springbootdemoormmybatis.util.MyMapper; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Component; - -@Component -public interface MybatisUserMapper extends MyMapper { - MybatisUser findByName(@Param("name") String name); -} diff --git a/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/model/MybatisUser.java b/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/model/MybatisUser.java deleted file mode 100644 index e4c2348..0000000 --- a/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/model/MybatisUser.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.xkcoding.springbootdemoormmybatis.model; - -import lombok.*; - -import javax.persistence.*; -import java.util.Date; - -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -@ToString -@Table(name = "mybatis_user") -public class MybatisUser { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY,generator = "JDBC") - private Long id; - - @Column(name = "name") - private String name; - - @Column(name = "tel") - private String tel; - - @Column(name = "create_time") - private Date createTime; -} diff --git a/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/service/MybatisUserService.java b/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/service/MybatisUserService.java deleted file mode 100644 index d2e2a2b..0000000 --- a/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/service/MybatisUserService.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.xkcoding.springbootdemoormmybatis.service; - -import com.xkcoding.springbootdemoormmybatis.model.MybatisUser; - -import java.util.List; - -public interface MybatisUserService { - MybatisUser save(MybatisUser user); - - List saveList(List userList); - - MybatisUser update(MybatisUser user); - - Integer delete(MybatisUser user); - - MybatisUser findById(Long id); - - MybatisUser findByName(String name); - - List findAll(); - - List findMybatisUserByPage(Integer pageNum, Integer pageSize); -} diff --git a/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/service/impl/MybatisUserServiceImpl.java b/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/service/impl/MybatisUserServiceImpl.java deleted file mode 100644 index ff4e4ae..0000000 --- a/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/service/impl/MybatisUserServiceImpl.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.xkcoding.springbootdemoormmybatis.service.impl; - -import com.github.pagehelper.PageHelper; -import com.xkcoding.springbootdemoormmybatis.mapper.MybatisUserMapper; -import com.xkcoding.springbootdemoormmybatis.model.MybatisUser; -import com.xkcoding.springbootdemoormmybatis.service.MybatisUserService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -@Slf4j -public class MybatisUserServiceImpl implements MybatisUserService { - - @Autowired - private MybatisUserMapper mybatisUserMapper; - - @Override - public MybatisUser save(MybatisUser user) { - mybatisUserMapper.insertUseGeneratedKeys(user); - return user; - } - - @Override - public List saveList(List userList) { - mybatisUserMapper.insertList(userList); - return userList; - } - - @Override - public MybatisUser update(MybatisUser user) { - int i = mybatisUserMapper.updateByPrimaryKeySelective(user); - if (i > 0) { - log.info("【MybatisUserService】更新成功:{}条目", i); - } else { - log.error("【MybatisUserService】更新失败:{}", user); - } - return mybatisUserMapper.selectByPrimaryKey(user.getId()); - } - - @Override - public Integer delete(MybatisUser user) { - return mybatisUserMapper.deleteByPrimaryKey(user); - } - - @Override - public MybatisUser findById(Long id) { - return mybatisUserMapper.selectByPrimaryKey(id); - } - - @Override - public MybatisUser findByName(String name) { - return mybatisUserMapper.findByName(name); - } - - @Override - public List findAll() { - return mybatisUserMapper.selectAll(); - } - - @Override - public List findMybatisUserByPage(Integer pageNum, Integer pageSize) { - PageHelper.startPage(pageNum, pageSize); - return mybatisUserMapper.selectAll(); - } -} diff --git a/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/util/MyMapper.java b/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/util/MyMapper.java deleted file mode 100644 index 7d8eaef..0000000 --- a/spring-boot-demo-orm-mybatis/src/main/java/com/xkcoding/springbootdemoormmybatis/util/MyMapper.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.xkcoding.springbootdemoormmybatis.util; - -import tk.mybatis.mapper.common.Mapper; -import tk.mybatis.mapper.common.MySqlMapper; - -public interface MyMapper extends Mapper, MySqlMapper { -} diff --git a/spring-boot-demo-orm-mybatis/src/main/resources/application.yml b/spring-boot-demo-orm-mybatis/src/main/resources/application.yml deleted file mode 100644 index e6239a3..0000000 --- a/spring-boot-demo-orm-mybatis/src/main/resources/application.yml +++ /dev/null @@ -1,70 +0,0 @@ -server: - port: 8080 - context-path: /demo -spring: - # json 转化移除 null 字段 - # jackson: - # default-property-inclusion: non_null - datasource: - # 启动时自动运行的 SQL 文件 - schema: classpath:init-sql/schema.sql - continue-on-error: true - druid: - url: jdbc:mysql://localhost:3306/spring-boot-demo?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false - username: root - password: root - driver-class-name: com.mysql.jdbc.Driver - # 连接池配置 - # 初始化大小,最小,最大 - initialSize: 5 - minIdle: 5 - maxActive: 20 - # 配置获取连接等待超时的时间 - maxWait: 60000 - # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 - timeBetweenEvictionRunsMillis: 60000 - # 配置一个连接在池中最小生存的时间,单位是毫秒 - minEvictableIdleTimeMillis: 300000 - validationQuery: SELECT 1 FROM DUAL - testWhileIdle: true - testOnBorrow: false - testOnReturn: false - # 打开PSCache,并且指定每个连接上PSCache的大小 - poolPreparedStatements: true - maxPoolPreparedStatementPerConnectionSize: 20 - # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 - filters: stat,wall,log4j - # 监控配置 - web-stat-filter: - enabled: true - url-pattern: /* - exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" - stat-view-servlet: - enabled: true - url-pattern: /sys/druid/* - reset-enable: fasle - login-username: xkcoding - login-password: 123456 - filter: - stat: - log-slow-sql: true - slow-sql-millis: 5000 - merge-sql: true -# mybatis 配置 -mybatis: - type-aliases-package: com.xkcoding.springbootdemoormmybatis.model - mapper-locations: classpath:mapper/*.xml - # 配置项:开启下划线到驼峰的自动转换. 作用:将数据库字段根据驼峰规则自动注入到对象属性 - configuration: - map-underscore-to-camel-case: true -# 通用 Mapper 配置 -mapper: - not-empty: false - identity: MYSQL - mappers: com.xkcoding.springbootdemoormmybatis.util.MyMapper -# PageHelper 配置 -pagehelper: - helper-dialect: mysql - reasonable: true - support-methods-arguments: true - params: count=countSql \ No newline at end of file diff --git a/spring-boot-demo-orm-mybatis/src/main/resources/init-sql/schema.sql b/spring-boot-demo-orm-mybatis/src/main/resources/init-sql/schema.sql deleted file mode 100644 index 0ddc300..0000000 --- a/spring-boot-demo-orm-mybatis/src/main/resources/init-sql/schema.sql +++ /dev/null @@ -1,19 +0,0 @@ -SET FOREIGN_KEY_CHECKS=0; - --- ---------------------------- --- Table structure for `boot_user` --- ---------------------------- -DROP TABLE IF EXISTS `mybatis_user`; -CREATE TABLE `mybatis_user` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(32) DEFAULT NULL, - `tel` varchar(11) DEFAULT NULL, - `create_time` datetime DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - --- ---------------------------- --- Records of boot_user --- ---------------------------- -INSERT INTO `mybatis_user` VALUES (1, 'klay', '13799008800', '2017-11-13 16:04:39'); -INSERT INTO `mybatis_user` VALUES (2, 'Tome', '18988991234', '2017-11-13 16:13:28'); diff --git a/spring-boot-demo-orm-mybatis/src/main/resources/logback-spring.xml b/spring-boot-demo-orm-mybatis/src/main/resources/logback-spring.xml deleted file mode 100644 index ed14f85..0000000 --- a/spring-boot-demo-orm-mybatis/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - 【xkcoding】%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx} - - - - - - - - - ${user.dir}/logs/log/mybatis-demo.%d.log - - - 【xkcoding】%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n - - - - - - ERROR - ACCEPT - DENY - - - - - ${user.dir}/logs/error/mybatis-demo.%d.error - - - 【xkcoding】%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n - - - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-demo-orm-mybatis/src/main/resources/mapper/MybatisUserMapper.xml b/spring-boot-demo-orm-mybatis/src/main/resources/mapper/MybatisUserMapper.xml deleted file mode 100644 index a79ad3c..0000000 --- a/spring-boot-demo-orm-mybatis/src/main/resources/mapper/MybatisUserMapper.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-demo-orm-mybatis/src/test/java/com/xkcoding/springbootdemoormmybatis/SpringBootDemoOrmMybatisApplicationTests.java b/spring-boot-demo-orm-mybatis/src/test/java/com/xkcoding/springbootdemoormmybatis/SpringBootDemoOrmMybatisApplicationTests.java deleted file mode 100644 index 02f5ff2..0000000 --- a/spring-boot-demo-orm-mybatis/src/test/java/com/xkcoding/springbootdemoormmybatis/SpringBootDemoOrmMybatisApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemoormmybatis; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoOrmMybatisApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-parent/pom.xml b/spring-boot-demo-parent/pom.xml deleted file mode 100644 index 1151ff6..0000000 --- a/spring-boot-demo-parent/pom.xml +++ /dev/null @@ -1,115 +0,0 @@ - - - 4.0.0 - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - pom - - spring-boot-demo-parent - The parent of spring-boot-demo - - - ../spring-boot-demo-helloworld - ../spring-boot-demo-properties - ../spring-boot-demo-actuator - ../spring-boot-demo-admin - ../spring-boot-demo-logback - ../spring-boot-demo-aoplog - ../spring-boot-demo-exceptionhandler - ../spring-boot-demo-template-freemarker - ../spring-boot-demo-template-thymeleaf - ../spring-boot-demo-orm-jpa - ../spring-boot-demo-orm-mybatis - ../spring-boot-demo-cache-redis - ../spring-boot-demo-swagger - ../spring-boot-demo-rabc-shiro-mybatis - ../spring-boot-demo-ureport2 - ../spring-boot-demo-war - ../spring-boot-demo-util - ../spring-boot-demo-elasticsearch - ../spring-boot-demo-template-beetl - ../spring-boot-demo-task-schedule - ../spring-boot-demo-orm-jdbctemplate - - - - org.springframework.boot - spring-boot-starter-parent - 1.5.8.RELEASE - - - - - UTF-8 - UTF-8 - 1.8 - 3.2.0 - 3.5 - 3.2.2 - 1.10 - - - - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-test - test - - - - mysql - mysql-connector-java - - - - org.apache.commons - commons-lang3 - ${commons.lang3.version} - - - commons-collections - commons-collections - ${commons.collections.version} - - - commons-codec - commons-codec - ${commons.codec.version} - - - com.xiaoleilu - hutool-all - ${hutool.version} - - - com.google.guava - guava - 23.0 - - - org.projectlombok - lombok - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - \ No newline at end of file diff --git a/spring-boot-demo-properties/README.md b/spring-boot-demo-properties/README.md deleted file mode 100644 index 29a8e0e..0000000 --- a/spring-boot-demo-properties/README.md +++ /dev/null @@ -1,48 +0,0 @@ -# spring-boot-demo-properties - -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent) - -### application.yml - -```yaml -server: - port: 8080 - context-path: /demo -application: - name: spring-boot-demo-properties - version: 0.0.1-SNAPSHOT - author: - name: xkcoding - website: xkcoding.com - qq: 237497819 - phone-number: 18601224166 -``` - -### 读取配置文件的两种方式 - -#### ApplicationConfig.java(第一种方式) - -```java -@Component -@Data -public class ApplicationConfig { - @Value("${application.name}") - private String name; - @Value("${application.version}") - private String version; -} -``` - -#### AuthorConfig.java(第二种方式) - -```java -@Data -@ConfigurationProperties(prefix = "application.author") -@Component -public class AuthorConfig { - private String name; - private String website; - private String qq; - private String phoneNumber; -} -``` \ No newline at end of file diff --git a/spring-boot-demo-properties/pom.xml b/spring-boot-demo-properties/pom.xml deleted file mode 100644 index 4b507e7..0000000 --- a/spring-boot-demo-properties/pom.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-properties - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-properties - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - spring-boot-demo-properties - - - diff --git a/spring-boot-demo-properties/src/main/java/com/xkcoding/springbootdemoproperties/SpringBootDemoPropertiesApplication.java b/spring-boot-demo-properties/src/main/java/com/xkcoding/springbootdemoproperties/SpringBootDemoPropertiesApplication.java deleted file mode 100644 index 5dc8077..0000000 --- a/spring-boot-demo-properties/src/main/java/com/xkcoding/springbootdemoproperties/SpringBootDemoPropertiesApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.xkcoding.springbootdemoproperties; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringBootDemoPropertiesApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoPropertiesApplication.class, args); - } -} diff --git a/spring-boot-demo-properties/src/main/java/com/xkcoding/springbootdemoproperties/config/ApplicationConfig.java b/spring-boot-demo-properties/src/main/java/com/xkcoding/springbootdemoproperties/config/ApplicationConfig.java deleted file mode 100644 index f2eb5fe..0000000 --- a/spring-boot-demo-properties/src/main/java/com/xkcoding/springbootdemoproperties/config/ApplicationConfig.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.xkcoding.springbootdemoproperties.config; - -import lombok.Data; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -@Data -public class ApplicationConfig { - @Value("${application.name}") - private String name; - @Value("${application.version}") - private String version; -} diff --git a/spring-boot-demo-properties/src/main/java/com/xkcoding/springbootdemoproperties/config/AuthorConfig.java b/spring-boot-demo-properties/src/main/java/com/xkcoding/springbootdemoproperties/config/AuthorConfig.java deleted file mode 100644 index 18ea05b..0000000 --- a/spring-boot-demo-properties/src/main/java/com/xkcoding/springbootdemoproperties/config/AuthorConfig.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.xkcoding.springbootdemoproperties.config; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -@Data -@ConfigurationProperties(prefix = "application.author") -@Component -public class AuthorConfig { - private String name; - private String website; - private String qq; - private String phoneNumber; -} diff --git a/spring-boot-demo-properties/src/main/java/com/xkcoding/springbootdemoproperties/controller/ConfigController.java b/spring-boot-demo-properties/src/main/java/com/xkcoding/springbootdemoproperties/controller/ConfigController.java deleted file mode 100644 index ec1a84a..0000000 --- a/spring-boot-demo-properties/src/main/java/com/xkcoding/springbootdemoproperties/controller/ConfigController.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.xkcoding.springbootdemoproperties.controller; - -import com.google.common.collect.Maps; -import com.xkcoding.springbootdemoproperties.config.ApplicationConfig; -import com.xkcoding.springbootdemoproperties.config.AuthorConfig; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.HashMap; -import java.util.Map; - -@RestController -@RequestMapping("/config") -public class ConfigController { - @Autowired - private ApplicationConfig applicationConfig; - @Autowired - private AuthorConfig authorConfig; - - @GetMapping({"", "/", "/index"}) - public Map index() { - HashMap ret = Maps.newHashMap(); - ret.put("applicationConfig", applicationConfig); - ret.put("authorConfig", authorConfig); - return ret; - } -} diff --git a/spring-boot-demo-properties/src/main/resources/application.yml b/spring-boot-demo-properties/src/main/resources/application.yml deleted file mode 100644 index 82dcd36..0000000 --- a/spring-boot-demo-properties/src/main/resources/application.yml +++ /dev/null @@ -1,11 +0,0 @@ -server: - port: 8080 - context-path: /demo -application: - name: spring-boot-demo-properties - version: 0.0.1-SNAPSHOT - author: - name: xkcoding - website: xkcoding.com - qq: 237497819 - phone-number: 18601224166 \ No newline at end of file diff --git a/spring-boot-demo-properties/src/test/java/com/xkcoding/springbootdemoproperties/SpringBootDemoPropertiesApplicationTests.java b/spring-boot-demo-properties/src/test/java/com/xkcoding/springbootdemoproperties/SpringBootDemoPropertiesApplicationTests.java deleted file mode 100644 index 7ed478f..0000000 --- a/spring-boot-demo-properties/src/test/java/com/xkcoding/springbootdemoproperties/SpringBootDemoPropertiesApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemoproperties; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoPropertiesApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-rabc-shiro-mybatis/README.md b/spring-boot-demo-rabc-shiro-mybatis/README.md deleted file mode 100644 index 2152873..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# 未完成 -此 demo 未完成 \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/pom.xml b/spring-boot-demo-rabc-shiro-mybatis/pom.xml deleted file mode 100644 index e33def1..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/pom.xml +++ /dev/null @@ -1,122 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-rabc-shiro-mybatis - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-rabc-shiro-mybatis - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent - - - - 1.3.2 - 2.4.2.1-RELEASE - 1.3.1 - 1.1.5 - 1.1.1 - 1.1.0 - - - - ${basedir}/src/main/java - com.xkcoding.springbootdemorabcshiromybatis.dao - com.xkcoding.springbootdemorabcshiromybatis.model - - ${basedir}/src/main/resources - mapper - - 3.4.0 - 5.1.29 - - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - ${mybatis.starter.version} - - - - com.alibaba - druid-spring-boot-starter - ${druid.starter.version} - - - - tk.mybatis - mapper-spring-boot-starter - ${mapper.version} - - - - com.github.pagehelper - pagehelper-spring-boot-starter - ${pagehelper.version} - - - org.apache.shiro - shiro-spring - ${shiro.version} - - - org.crazycake - shiro-redis - ${shiro.redis.version} - - - - com.xkcoding - spring-boot-demo-util - 0.0.1-SNAPSHOT - - - com.xiaoleilu - hutool-all - - - - - - - - - org.mybatis.generator - mybatis-generator-maven-plugin - 1.3.2 - - ${basedir}/src/main/resources/generator/generatorConfig.xml - true - true - - - - mysql - mysql-connector-java - ${mysql.version} - - - tk.mybatis - mapper - ${mapper.generator.version} - - - - - spring-boot-demo-rabc-shiro-mybatis - - - \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/SpringBootDemoRabcShiroMybatisApplication.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/SpringBootDemoRabcShiroMybatisApplication.java deleted file mode 100644 index 9e5492a..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/SpringBootDemoRabcShiroMybatisApplication.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis; - -import lombok.extern.slf4j.Slf4j; -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; - -@SpringBootApplication -@MapperScan(basePackages = {"com.xkcoding.springbootdemorabcshiromybatis.dao"}) -@Slf4j -@Controller -public class SpringBootDemoRabcShiroMybatisApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoRabcShiroMybatisApplication.class, args); - log.info("SpringBootDemoRabcShiroMybatisApplication 启动成功。。。。"); - } - - @GetMapping("/login.page") - public String index() { - return "index"; - } -} diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroAclMapper.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroAclMapper.java deleted file mode 100644 index cff068b..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroAclMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.dao; - -import com.xkcoding.springbootdemorabcshiromybatis.model.MybatisShiroAcl; -import com.xkcoding.springbootdemorabcshiromybatis.util.MyMapper; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Component -public interface MybatisShiroAclMapper extends MyMapper { - /** - * 根据角色id获取权限列表 - * - * @param roleId 角色id - * @return 权限列表 - */ - List getResUrlsByRoleId(Integer roleId); -} \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroDeptMapper.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroDeptMapper.java deleted file mode 100644 index 9ae8d9a..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroDeptMapper.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.dao; - -import com.xkcoding.springbootdemorabcshiromybatis.model.MybatisShiroDept; -import com.xkcoding.springbootdemorabcshiromybatis.util.MyMapper; -import org.springframework.stereotype.Component; - -@Component -public interface MybatisShiroDeptMapper extends MyMapper { -} \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroLogMapper.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroLogMapper.java deleted file mode 100644 index 2003b20..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroLogMapper.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.dao; - -import com.xkcoding.springbootdemorabcshiromybatis.model.MybatisShiroLog; -import com.xkcoding.springbootdemorabcshiromybatis.util.MyMapper; -import org.springframework.stereotype.Component; - -@Component -public interface MybatisShiroLogMapper extends MyMapper { -} \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroRoleAclMapper.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroRoleAclMapper.java deleted file mode 100644 index d7ce932..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroRoleAclMapper.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.dao; - -import com.xkcoding.springbootdemorabcshiromybatis.model.MybatisShiroRoleAcl; -import com.xkcoding.springbootdemorabcshiromybatis.util.MyMapper; -import org.springframework.stereotype.Component; - -@Component -public interface MybatisShiroRoleAclMapper extends MyMapper { -} \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroRoleMapper.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroRoleMapper.java deleted file mode 100644 index f76f18c..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroRoleMapper.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.dao; - -import com.xkcoding.springbootdemorabcshiromybatis.model.MybatisShiroRole; -import com.xkcoding.springbootdemorabcshiromybatis.util.MyMapper; -import org.springframework.stereotype.Component; - -@Component -public interface MybatisShiroRoleMapper extends MyMapper { -} \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroRoleUserMapper.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroRoleUserMapper.java deleted file mode 100644 index 6e8bed2..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroRoleUserMapper.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.dao; - -import com.xkcoding.springbootdemorabcshiromybatis.model.MybatisShiroRoleUser; -import com.xkcoding.springbootdemorabcshiromybatis.util.MyMapper; -import org.springframework.stereotype.Component; - -@Component -public interface MybatisShiroRoleUserMapper extends MyMapper { -} \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroUserMapper.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroUserMapper.java deleted file mode 100644 index b9e27b0..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/dao/MybatisShiroUserMapper.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.dao; - -import com.xkcoding.springbootdemorabcshiromybatis.model.MybatisShiroUser; -import com.xkcoding.springbootdemorabcshiromybatis.util.MyMapper; -import org.springframework.stereotype.Component; - -@Component -public interface MybatisShiroUserMapper extends MyMapper { - /** - * 根据用户账号获得用户信息 - * - * @param username 用户账号 - * @return 用户对象 - */ - MybatisShiroUser findByUsername(String username); -} \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/domain/LoginParam.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/domain/LoginParam.java deleted file mode 100644 index 984ae05..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/domain/LoginParam.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.domain; - -import lombok.Data; - -/** - *

- * 登录参数 - *

- * - * @package: com.xkcoding.springbootdemorabcshiromybatis.domain - * @description: 登录参数 - * @author: yangkai.shen - * @date: Created in 2017/12/7 下午3:45 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Data -public class LoginParam { - private String username; - private String password; - private String kaptcha; - private Boolean rememberMe; -} diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroAcl.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroAcl.java deleted file mode 100644 index 70d2a5c..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroAcl.java +++ /dev/null @@ -1,334 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.model; - -import java.util.Date; -import javax.persistence.*; - -@Table(name = "mybatis_shiro_acl") -public class MybatisShiroAcl { - /** - * 权限id - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - /** - * 权限编号 - */ - private String code; - - /** - * 权限名称 - */ - private String name; - - /** - * 权限图标 - */ - private String icon; - - /** - * 上级权限id - */ - @Column(name = "parent_id") - private Integer parentId; - - /** - * 权限层级,默认为0,层级直接用逗号(半角)隔开 - */ - private String level; - - /** - * 权限的url, 可以填正则表达式 - */ - private String url; - - /** - * 类型,1:菜单,2:按钮,3:其他 - */ - private Integer type; - - /** - * 状态,0:冻结,1:正常 - */ - private Integer status; - - /** - * 权限在当前层级下的顺序,由小到大 - */ - private Integer seq; - - /** - * 备注 - */ - private String remark; - - /** - * 操作者 - */ - private String operator; - - /** - * 最后一次更新时间 - */ - @Column(name = "operate_time") - private Date operateTime; - - /** - * 最后一次更新操作者的ip地址 - */ - @Column(name = "operate_ip") - private String operateIp; - - /** - * 获取权限id - * - * @return id - 权限id - */ - public Integer getId() { - return id; - } - - /** - * 设置权限id - * - * @param id 权限id - */ - public void setId(Integer id) { - this.id = id; - } - - /** - * 获取权限编号 - * - * @return code - 权限编号 - */ - public String getCode() { - return code; - } - - /** - * 设置权限编号 - * - * @param code 权限编号 - */ - public void setCode(String code) { - this.code = code; - } - - /** - * 获取权限名称 - * - * @return name - 权限名称 - */ - public String getName() { - return name; - } - - /** - * 设置权限名称 - * - * @param name 权限名称 - */ - public void setName(String name) { - this.name = name; - } - - /** - * 获取权限图标 - * - * @return icon - 权限图标 - */ - public String getIcon() { - return icon; - } - - /** - * 设置权限图标 - * - * @param icon 权限图标 - */ - public void setIcon(String icon) { - this.icon = icon; - } - - /** - * 获取上级权限id - * - * @return parent_id - 上级权限id - */ - public Integer getParentId() { - return parentId; - } - - /** - * 设置上级权限id - * - * @param parentId 上级权限id - */ - public void setParentId(Integer parentId) { - this.parentId = parentId; - } - - /** - * 获取权限层级,默认为0,层级直接用逗号(半角)隔开 - * - * @return level - 权限层级,默认为0,层级直接用逗号(半角)隔开 - */ - public String getLevel() { - return level; - } - - /** - * 设置权限层级,默认为0,层级直接用逗号(半角)隔开 - * - * @param level 权限层级,默认为0,层级直接用逗号(半角)隔开 - */ - public void setLevel(String level) { - this.level = level; - } - - /** - * 获取权限的url, 可以填正则表达式 - * - * @return url - 权限的url, 可以填正则表达式 - */ - public String getUrl() { - return url; - } - - /** - * 设置权限的url, 可以填正则表达式 - * - * @param url 权限的url, 可以填正则表达式 - */ - public void setUrl(String url) { - this.url = url; - } - - /** - * 获取类型,1:菜单,2:按钮,3:其他 - * - * @return type - 类型,1:菜单,2:按钮,3:其他 - */ - public Integer getType() { - return type; - } - - /** - * 设置类型,1:菜单,2:按钮,3:其他 - * - * @param type 类型,1:菜单,2:按钮,3:其他 - */ - public void setType(Integer type) { - this.type = type; - } - - /** - * 获取状态,0:冻结,1:正常 - * - * @return status - 状态,0:冻结,1:正常 - */ - public Integer getStatus() { - return status; - } - - /** - * 设置状态,0:冻结,1:正常 - * - * @param status 状态,0:冻结,1:正常 - */ - public void setStatus(Integer status) { - this.status = status; - } - - /** - * 获取权限在当前层级下的顺序,由小到大 - * - * @return seq - 权限在当前层级下的顺序,由小到大 - */ - public Integer getSeq() { - return seq; - } - - /** - * 设置权限在当前层级下的顺序,由小到大 - * - * @param seq 权限在当前层级下的顺序,由小到大 - */ - public void setSeq(Integer seq) { - this.seq = seq; - } - - /** - * 获取备注 - * - * @return remark - 备注 - */ - public String getRemark() { - return remark; - } - - /** - * 设置备注 - * - * @param remark 备注 - */ - public void setRemark(String remark) { - this.remark = remark; - } - - /** - * 获取操作者 - * - * @return operator - 操作者 - */ - public String getOperator() { - return operator; - } - - /** - * 设置操作者 - * - * @param operator 操作者 - */ - public void setOperator(String operator) { - this.operator = operator; - } - - /** - * 获取最后一次更新时间 - * - * @return operate_time - 最后一次更新时间 - */ - public Date getOperateTime() { - return operateTime; - } - - /** - * 设置最后一次更新时间 - * - * @param operateTime 最后一次更新时间 - */ - public void setOperateTime(Date operateTime) { - this.operateTime = operateTime; - } - - /** - * 获取最后一次更新操作者的ip地址 - * - * @return operate_ip - 最后一次更新操作者的ip地址 - */ - public String getOperateIp() { - return operateIp; - } - - /** - * 设置最后一次更新操作者的ip地址 - * - * @param operateIp 最后一次更新操作者的ip地址 - */ - public void setOperateIp(String operateIp) { - this.operateIp = operateIp; - } -} \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroDept.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroDept.java deleted file mode 100644 index 27c9c34..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroDept.java +++ /dev/null @@ -1,219 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.model; - -import java.util.Date; -import javax.persistence.*; - -@Table(name = "mybatis_shiro_dept") -public class MybatisShiroDept { - /** - * 部门id - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - /** - * 部门名称 - */ - private String name; - - /** - * 上级部门id,顶层是0 - */ - @Column(name = "parent_id") - private Integer parentId; - - /** - * 部门层级,默认为0,层级直接用逗号(半角)隔开 - */ - private String level; - - /** - * 部门在当前层级下的顺序,由小到大 - */ - private Integer seq; - - /** - * 备注 - */ - private String remark; - - /** - * 操作者 - */ - private String operator; - - /** - * 最后一次更新时间 - */ - @Column(name = "operate_time") - private Date operateTime; - - /** - * 最后一次更新操作者的ip地址 - */ - @Column(name = "operate_ip") - private String operateIp; - - /** - * 获取部门id - * - * @return id - 部门id - */ - public Integer getId() { - return id; - } - - /** - * 设置部门id - * - * @param id 部门id - */ - public void setId(Integer id) { - this.id = id; - } - - /** - * 获取部门名称 - * - * @return name - 部门名称 - */ - public String getName() { - return name; - } - - /** - * 设置部门名称 - * - * @param name 部门名称 - */ - public void setName(String name) { - this.name = name; - } - - /** - * 获取上级部门id,顶层是0 - * - * @return parent_id - 上级部门id,顶层是0 - */ - public Integer getParentId() { - return parentId; - } - - /** - * 设置上级部门id,顶层是0 - * - * @param parentId 上级部门id,顶层是0 - */ - public void setParentId(Integer parentId) { - this.parentId = parentId; - } - - /** - * 获取部门层级,默认为0,层级直接用逗号(半角)隔开 - * - * @return level - 部门层级,默认为0,层级直接用逗号(半角)隔开 - */ - public String getLevel() { - return level; - } - - /** - * 设置部门层级,默认为0,层级直接用逗号(半角)隔开 - * - * @param level 部门层级,默认为0,层级直接用逗号(半角)隔开 - */ - public void setLevel(String level) { - this.level = level; - } - - /** - * 获取部门在当前层级下的顺序,由小到大 - * - * @return seq - 部门在当前层级下的顺序,由小到大 - */ - public Integer getSeq() { - return seq; - } - - /** - * 设置部门在当前层级下的顺序,由小到大 - * - * @param seq 部门在当前层级下的顺序,由小到大 - */ - public void setSeq(Integer seq) { - this.seq = seq; - } - - /** - * 获取备注 - * - * @return remark - 备注 - */ - public String getRemark() { - return remark; - } - - /** - * 设置备注 - * - * @param remark 备注 - */ - public void setRemark(String remark) { - this.remark = remark; - } - - /** - * 获取操作者 - * - * @return operator - 操作者 - */ - public String getOperator() { - return operator; - } - - /** - * 设置操作者 - * - * @param operator 操作者 - */ - public void setOperator(String operator) { - this.operator = operator; - } - - /** - * 获取最后一次更新时间 - * - * @return operate_time - 最后一次更新时间 - */ - public Date getOperateTime() { - return operateTime; - } - - /** - * 设置最后一次更新时间 - * - * @param operateTime 最后一次更新时间 - */ - public void setOperateTime(Date operateTime) { - this.operateTime = operateTime; - } - - /** - * 获取最后一次更新操作者的ip地址 - * - * @return operate_ip - 最后一次更新操作者的ip地址 - */ - public String getOperateIp() { - return operateIp; - } - - /** - * 设置最后一次更新操作者的ip地址 - * - * @param operateIp 最后一次更新操作者的ip地址 - */ - public void setOperateIp(String operateIp) { - this.operateIp = operateIp; - } -} \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroLog.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroLog.java deleted file mode 100644 index e0826e3..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroLog.java +++ /dev/null @@ -1,221 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.model; - -import java.util.Date; -import javax.persistence.*; - -@Table(name = "mybatis_shiro_log") -public class MybatisShiroLog { - /** - * 日志记录id - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - /** - * 权限更新的类型,1:部门,2:用户,3:权限模块,4:权限,5:角色,6:角色用户关系,7:角色权限关系 - */ - private Integer type; - - /** - * 基于type后指定的对象id,比如用户、权限、角色等表的主键 - */ - @Column(name = "target_id") - private Integer targetId; - - /** - * 操作者 - */ - private String operator; - - /** - * 最后一次更新时间 - */ - @Column(name = "operate_time") - private Date operateTime; - - /** - * 最后一次更新操作者的ip地址 - */ - @Column(name = "operate_ip") - private String operateIp; - - /** - * 当前是否复原过,0:没有复原过,1:复原过 - */ - private Integer status; - - /** - * 旧值 - */ - @Column(name = "old_value") - private String oldValue; - - /** - * 新值 - */ - @Column(name = "new_value") - private String newValue; - - /** - * 获取日志记录id - * - * @return id - 日志记录id - */ - public Integer getId() { - return id; - } - - /** - * 设置日志记录id - * - * @param id 日志记录id - */ - public void setId(Integer id) { - this.id = id; - } - - /** - * 获取权限更新的类型,1:部门,2:用户,3:权限模块,4:权限,5:角色,6:角色用户关系,7:角色权限关系 - * - * @return type - 权限更新的类型,1:部门,2:用户,3:权限模块,4:权限,5:角色,6:角色用户关系,7:角色权限关系 - */ - public Integer getType() { - return type; - } - - /** - * 设置权限更新的类型,1:部门,2:用户,3:权限模块,4:权限,5:角色,6:角色用户关系,7:角色权限关系 - * - * @param type 权限更新的类型,1:部门,2:用户,3:权限模块,4:权限,5:角色,6:角色用户关系,7:角色权限关系 - */ - public void setType(Integer type) { - this.type = type; - } - - /** - * 获取基于type后指定的对象id,比如用户、权限、角色等表的主键 - * - * @return target_id - 基于type后指定的对象id,比如用户、权限、角色等表的主键 - */ - public Integer getTargetId() { - return targetId; - } - - /** - * 设置基于type后指定的对象id,比如用户、权限、角色等表的主键 - * - * @param targetId 基于type后指定的对象id,比如用户、权限、角色等表的主键 - */ - public void setTargetId(Integer targetId) { - this.targetId = targetId; - } - - /** - * 获取操作者 - * - * @return operator - 操作者 - */ - public String getOperator() { - return operator; - } - - /** - * 设置操作者 - * - * @param operator 操作者 - */ - public void setOperator(String operator) { - this.operator = operator; - } - - /** - * 获取最后一次更新时间 - * - * @return operate_time - 最后一次更新时间 - */ - public Date getOperateTime() { - return operateTime; - } - - /** - * 设置最后一次更新时间 - * - * @param operateTime 最后一次更新时间 - */ - public void setOperateTime(Date operateTime) { - this.operateTime = operateTime; - } - - /** - * 获取最后一次更新操作者的ip地址 - * - * @return operate_ip - 最后一次更新操作者的ip地址 - */ - public String getOperateIp() { - return operateIp; - } - - /** - * 设置最后一次更新操作者的ip地址 - * - * @param operateIp 最后一次更新操作者的ip地址 - */ - public void setOperateIp(String operateIp) { - this.operateIp = operateIp; - } - - /** - * 获取当前是否复原过,0:没有复原过,1:复原过 - * - * @return status - 当前是否复原过,0:没有复原过,1:复原过 - */ - public Integer getStatus() { - return status; - } - - /** - * 设置当前是否复原过,0:没有复原过,1:复原过 - * - * @param status 当前是否复原过,0:没有复原过,1:复原过 - */ - public void setStatus(Integer status) { - this.status = status; - } - - /** - * 获取旧值 - * - * @return old_value - 旧值 - */ - public String getOldValue() { - return oldValue; - } - - /** - * 设置旧值 - * - * @param oldValue 旧值 - */ - public void setOldValue(String oldValue) { - this.oldValue = oldValue; - } - - /** - * 获取新值 - * - * @return new_value - 新值 - */ - public String getNewValue() { - return newValue; - } - - /** - * 设置新值 - * - * @param newValue 新值 - */ - public void setNewValue(String newValue) { - this.newValue = newValue; - } -} \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroRole.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroRole.java deleted file mode 100644 index 0358321..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroRole.java +++ /dev/null @@ -1,195 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.model; - -import java.util.Date; -import javax.persistence.*; - -@Table(name = "mybatis_shiro_role") -public class MybatisShiroRole { - /** - * 角色id - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - /** - * 角色名称 - */ - private String name; - - /** - * 角色的类型,1:管理员角色,2:其他 - */ - private Integer type; - - /** - * 状态,0:冻结,1:可用 - */ - private Integer status; - - /** - * 备注 - */ - private String remark; - - /** - * 操作者 - */ - private String operator; - - /** - * 最后一次更新时间 - */ - @Column(name = "operate_time") - private Date operateTime; - - /** - * 最后一次更新操作者的ip地址 - */ - @Column(name = "operate_ip") - private String operateIp; - - /** - * 获取角色id - * - * @return id - 角色id - */ - public Integer getId() { - return id; - } - - /** - * 设置角色id - * - * @param id 角色id - */ - public void setId(Integer id) { - this.id = id; - } - - /** - * 获取角色名称 - * - * @return name - 角色名称 - */ - public String getName() { - return name; - } - - /** - * 设置角色名称 - * - * @param name 角色名称 - */ - public void setName(String name) { - this.name = name; - } - - /** - * 获取角色的类型,1:管理员角色,2:其他 - * - * @return type - 角色的类型,1:管理员角色,2:其他 - */ - public Integer getType() { - return type; - } - - /** - * 设置角色的类型,1:管理员角色,2:其他 - * - * @param type 角色的类型,1:管理员角色,2:其他 - */ - public void setType(Integer type) { - this.type = type; - } - - /** - * 获取状态,0:冻结,1:可用 - * - * @return status - 状态,0:冻结,1:可用 - */ - public Integer getStatus() { - return status; - } - - /** - * 设置状态,0:冻结,1:可用 - * - * @param status 状态,0:冻结,1:可用 - */ - public void setStatus(Integer status) { - this.status = status; - } - - /** - * 获取备注 - * - * @return remark - 备注 - */ - public String getRemark() { - return remark; - } - - /** - * 设置备注 - * - * @param remark 备注 - */ - public void setRemark(String remark) { - this.remark = remark; - } - - /** - * 获取操作者 - * - * @return operator - 操作者 - */ - public String getOperator() { - return operator; - } - - /** - * 设置操作者 - * - * @param operator 操作者 - */ - public void setOperator(String operator) { - this.operator = operator; - } - - /** - * 获取最后一次更新时间 - * - * @return operate_time - 最后一次更新时间 - */ - public Date getOperateTime() { - return operateTime; - } - - /** - * 设置最后一次更新时间 - * - * @param operateTime 最后一次更新时间 - */ - public void setOperateTime(Date operateTime) { - this.operateTime = operateTime; - } - - /** - * 获取最后一次更新操作者的ip地址 - * - * @return operate_ip - 最后一次更新操作者的ip地址 - */ - public String getOperateIp() { - return operateIp; - } - - /** - * 设置最后一次更新操作者的ip地址 - * - * @param operateIp 最后一次更新操作者的ip地址 - */ - public void setOperateIp(String operateIp) { - this.operateIp = operateIp; - } -} \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroRoleAcl.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroRoleAcl.java deleted file mode 100644 index aaeab53..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroRoleAcl.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.model; - -import java.util.Date; -import javax.persistence.*; - -@Table(name = "mybatis_shiro_role_acl") -public class MybatisShiroRoleAcl { - /** - * 角色-权限id - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - /** - * 角色id - */ - @Column(name = "role_id") - private Integer roleId; - - /** - * 权限id - */ - @Column(name = "acl_id") - private Integer aclId; - - /** - * 操作者 - */ - private String operator; - - /** - * 最后一次更新时间 - */ - @Column(name = "operate_time") - private Date operateTime; - - /** - * 最后一次更新操作者的ip地址 - */ - @Column(name = "operate_ip") - private String operateIp; - - /** - * 获取角色-权限id - * - * @return id - 角色-权限id - */ - public Integer getId() { - return id; - } - - /** - * 设置角色-权限id - * - * @param id 角色-权限id - */ - public void setId(Integer id) { - this.id = id; - } - - /** - * 获取角色id - * - * @return role_id - 角色id - */ - public Integer getRoleId() { - return roleId; - } - - /** - * 设置角色id - * - * @param roleId 角色id - */ - public void setRoleId(Integer roleId) { - this.roleId = roleId; - } - - /** - * 获取权限id - * - * @return acl_id - 权限id - */ - public Integer getAclId() { - return aclId; - } - - /** - * 设置权限id - * - * @param aclId 权限id - */ - public void setAclId(Integer aclId) { - this.aclId = aclId; - } - - /** - * 获取操作者 - * - * @return operator - 操作者 - */ - public String getOperator() { - return operator; - } - - /** - * 设置操作者 - * - * @param operator 操作者 - */ - public void setOperator(String operator) { - this.operator = operator; - } - - /** - * 获取最后一次更新时间 - * - * @return operate_time - 最后一次更新时间 - */ - public Date getOperateTime() { - return operateTime; - } - - /** - * 设置最后一次更新时间 - * - * @param operateTime 最后一次更新时间 - */ - public void setOperateTime(Date operateTime) { - this.operateTime = operateTime; - } - - /** - * 获取最后一次更新操作者的ip地址 - * - * @return operate_ip - 最后一次更新操作者的ip地址 - */ - public String getOperateIp() { - return operateIp; - } - - /** - * 设置最后一次更新操作者的ip地址 - * - * @param operateIp 最后一次更新操作者的ip地址 - */ - public void setOperateIp(String operateIp) { - this.operateIp = operateIp; - } -} \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroRoleUser.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroRoleUser.java deleted file mode 100644 index 1ea2885..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroRoleUser.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.model; - -import java.util.Date; -import javax.persistence.*; - -@Table(name = "mybatis_shiro_role_user") -public class MybatisShiroRoleUser { - /** - * 角色-用户id - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - /** - * 角色id - */ - @Column(name = "role_id") - private Integer roleId; - - /** - * 用户id - */ - @Column(name = "user_id") - private Integer userId; - - /** - * 操作者 - */ - private String operator; - - /** - * 最后一次更新时间 - */ - @Column(name = "operate_time") - private Date operateTime; - - /** - * 最后一次更新操作者的ip地址 - */ - @Column(name = "operate_ip") - private String operateIp; - - /** - * 获取角色-用户id - * - * @return id - 角色-用户id - */ - public Integer getId() { - return id; - } - - /** - * 设置角色-用户id - * - * @param id 角色-用户id - */ - public void setId(Integer id) { - this.id = id; - } - - /** - * 获取角色id - * - * @return role_id - 角色id - */ - public Integer getRoleId() { - return roleId; - } - - /** - * 设置角色id - * - * @param roleId 角色id - */ - public void setRoleId(Integer roleId) { - this.roleId = roleId; - } - - /** - * 获取用户id - * - * @return user_id - 用户id - */ - public Integer getUserId() { - return userId; - } - - /** - * 设置用户id - * - * @param userId 用户id - */ - public void setUserId(Integer userId) { - this.userId = userId; - } - - /** - * 获取操作者 - * - * @return operator - 操作者 - */ - public String getOperator() { - return operator; - } - - /** - * 设置操作者 - * - * @param operator 操作者 - */ - public void setOperator(String operator) { - this.operator = operator; - } - - /** - * 获取最后一次更新时间 - * - * @return operate_time - 最后一次更新时间 - */ - public Date getOperateTime() { - return operateTime; - } - - /** - * 设置最后一次更新时间 - * - * @param operateTime 最后一次更新时间 - */ - public void setOperateTime(Date operateTime) { - this.operateTime = operateTime; - } - - /** - * 获取最后一次更新操作者的ip地址 - * - * @return operate_ip - 最后一次更新操作者的ip地址 - */ - public String getOperateIp() { - return operateIp; - } - - /** - * 设置最后一次更新操作者的ip地址 - * - * @param operateIp 最后一次更新操作者的ip地址 - */ - public void setOperateIp(String operateIp) { - this.operateIp = operateIp; - } -} \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroUser.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroUser.java deleted file mode 100644 index 4317b07..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/model/MybatisShiroUser.java +++ /dev/null @@ -1,382 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.model; - -import java.util.Date; -import javax.persistence.*; - -@Table(name = "mybatis_shiro_user") -public class MybatisShiroUser { - /** - * 用户id - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - /** - * 用户名 - */ - private String username; - - /** - * 加密后的密码 - */ - private String password; - - /** - * 密码加密的盐值 - */ - private String salt; - - /** - * 头像 - */ - private String avatar; - - /** - * 真实姓名 - */ - private String realname; - - /** - * 手机号 - */ - private String telephone; - - /** - * 邮箱 - */ - private String mail; - - /** - * 用户所在部门的id - */ - @Column(name = "dept_id") - private Integer deptId; - - /** - * 状态,-1:删除,0:冻结状态,1:正常 - */ - private Integer status; - - /** - * 备注 - */ - private String remark; - - /** - * 最后一次登录的时间 - */ - @Column(name = "last_time") - private Date lastTime; - - /** - * 最后一次登录的ip地址 - */ - @Column(name = "last_ip") - private String lastIp; - - /** - * 操作者 - */ - private String operator; - - /** - * 最后一次更新时间 - */ - @Column(name = "operate_time") - private Date operateTime; - - /** - * 最后一次更新操作者的ip地址 - */ - @Column(name = "operate_ip") - private String operateIp; - - /** - * 获取用户id - * - * @return id - 用户id - */ - public Integer getId() { - return id; - } - - /** - * 设置用户id - * - * @param id 用户id - */ - public void setId(Integer id) { - this.id = id; - } - - /** - * 获取用户名 - * - * @return username - 用户名 - */ - public String getUsername() { - return username; - } - - /** - * 设置用户名 - * - * @param username 用户名 - */ - public void setUsername(String username) { - this.username = username; - } - - /** - * 获取加密后的密码 - * - * @return password - 加密后的密码 - */ - public String getPassword() { - return password; - } - - /** - * 设置加密后的密码 - * - * @param password 加密后的密码 - */ - public void setPassword(String password) { - this.password = password; - } - - /** - * 获取密码加密的盐值 - * - * @return salt - 密码加密的盐值 - */ - public String getSalt() { - return salt; - } - - /** - * 设置密码加密的盐值 - * - * @param salt 密码加密的盐值 - */ - public void setSalt(String salt) { - this.salt = salt; - } - - /** - * 获取头像 - * - * @return avatar - 头像 - */ - public String getAvatar() { - return avatar; - } - - /** - * 设置头像 - * - * @param avatar 头像 - */ - public void setAvatar(String avatar) { - this.avatar = avatar; - } - - /** - * 获取真实姓名 - * - * @return realname - 真实姓名 - */ - public String getRealname() { - return realname; - } - - /** - * 设置真实姓名 - * - * @param realname 真实姓名 - */ - public void setRealname(String realname) { - this.realname = realname; - } - - /** - * 获取手机号 - * - * @return telephone - 手机号 - */ - public String getTelephone() { - return telephone; - } - - /** - * 设置手机号 - * - * @param telephone 手机号 - */ - public void setTelephone(String telephone) { - this.telephone = telephone; - } - - /** - * 获取邮箱 - * - * @return mail - 邮箱 - */ - public String getMail() { - return mail; - } - - /** - * 设置邮箱 - * - * @param mail 邮箱 - */ - public void setMail(String mail) { - this.mail = mail; - } - - /** - * 获取用户所在部门的id - * - * @return dept_id - 用户所在部门的id - */ - public Integer getDeptId() { - return deptId; - } - - /** - * 设置用户所在部门的id - * - * @param deptId 用户所在部门的id - */ - public void setDeptId(Integer deptId) { - this.deptId = deptId; - } - - /** - * 获取状态,-1:删除,0:冻结状态,1:正常 - * - * @return status - 状态,-1:删除,0:冻结状态,1:正常 - */ - public Integer getStatus() { - return status; - } - - /** - * 设置状态,-1:删除,0:冻结状态,1:正常 - * - * @param status 状态,-1:删除,0:冻结状态,1:正常 - */ - public void setStatus(Integer status) { - this.status = status; - } - - /** - * 获取备注 - * - * @return remark - 备注 - */ - public String getRemark() { - return remark; - } - - /** - * 设置备注 - * - * @param remark 备注 - */ - public void setRemark(String remark) { - this.remark = remark; - } - - /** - * 获取最后一次登录的时间 - * - * @return last_time - 最后一次登录的时间 - */ - public Date getLastTime() { - return lastTime; - } - - /** - * 设置最后一次登录的时间 - * - * @param lastTime 最后一次登录的时间 - */ - public void setLastTime(Date lastTime) { - this.lastTime = lastTime; - } - - /** - * 获取最后一次登录的ip地址 - * - * @return last_ip - 最后一次登录的ip地址 - */ - public String getLastIp() { - return lastIp; - } - - /** - * 设置最后一次登录的ip地址 - * - * @param lastIp 最后一次登录的ip地址 - */ - public void setLastIp(String lastIp) { - this.lastIp = lastIp; - } - - /** - * 获取操作者 - * - * @return operator - 操作者 - */ - public String getOperator() { - return operator; - } - - /** - * 设置操作者 - * - * @param operator 操作者 - */ - public void setOperator(String operator) { - this.operator = operator; - } - - /** - * 获取最后一次更新时间 - * - * @return operate_time - 最后一次更新时间 - */ - public Date getOperateTime() { - return operateTime; - } - - /** - * 设置最后一次更新时间 - * - * @param operateTime 最后一次更新时间 - */ - public void setOperateTime(Date operateTime) { - this.operateTime = operateTime; - } - - /** - * 获取最后一次更新操作者的ip地址 - * - * @return operate_ip - 最后一次更新操作者的ip地址 - */ - public String getOperateIp() { - return operateIp; - } - - /** - * 设置最后一次更新操作者的ip地址 - * - * @param operateIp 最后一次更新操作者的ip地址 - */ - public void setOperateIp(String operateIp) { - this.operateIp = operateIp; - } -} \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/util/IpUtil.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/util/IpUtil.java deleted file mode 100644 index 32d1a20..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/util/IpUtil.java +++ /dev/null @@ -1,147 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.util; - -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -import javax.servlet.http.HttpServletRequest; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - *

- * 获取 IP 工具类 - *

- * - * @package: com.xkcoding.springbootdemorabcshiromybatis.util - * @description: 获取 IP 工具类 - * @author: yangkai.shen - * @date: Created in 2017/12/7 上午11:13 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Slf4j -public class IpUtil { - public final static String ERROR_IP = "127.0.0.1"; - - public final static Pattern pattern = Pattern. - compile("(2[5][0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})"); - - /** - * 取外网IP - * - * @param request - * @return - */ - public static String getRemoteIp(HttpServletRequest request) { - String ip = request.getHeader("x-real-ip"); - if (ip == null) { - ip = request.getRemoteAddr(); - } - - //过滤反向代理的ip - String[] stemps = ip.split(","); - if (stemps != null && stemps.length >= 1) { - //得到第一个IP,即客户端真实IP - ip = stemps[0]; - } - - ip = ip.trim(); - if (ip.length() > 23) { - ip = ip.substring(0, 23); - } - - return ip; - } - - /** - * 获取用户的真实ip - * - * @param request - * @return - */ - public static String getUserIP(HttpServletRequest request) { - - // 优先取X-Real-IP - String ip = request.getHeader("X-Real-IP"); - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getHeader("x-forwarded-for"); - } - - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getRemoteAddr(); - if ("0:0:0:0:0:0:0:1".equals(ip)) { - ip = ERROR_IP; - } - } - - if ("unknown".equalsIgnoreCase(ip)) { - ip = ERROR_IP; - return ip; - } - - int pos = ip.indexOf(','); - if (pos >= 0) { - ip = ip.substring(0, pos); - } - - return ip; - } - - public static String getLastIpSegment(HttpServletRequest request) { - String ip = getUserIP(request); - if (ip != null) { - ip = ip.substring(ip.lastIndexOf('.') + 1); - } else { - ip = "0"; - } - return ip; - } - - public static boolean isValidIP(HttpServletRequest request) { - String ip = getUserIP(request); - return isValidIP(ip); - } - - /** - * 判断我们获取的ip是否是一个符合规则ip - * - * @param ip - * @return - */ - public static boolean isValidIP(String ip) { - if (StringUtils.isEmpty(ip)) { - log.debug("ip is null. valid result is false"); - return false; - } - - Matcher matcher = pattern.matcher(ip); - boolean isValid = matcher.matches(); - log.debug("valid ip:" + ip + " result is: " + isValid); - return isValid; - } - - public static String getLastServerIpSegment() { - String ip = getServerIP(); - if (ip != null) { - ip = ip.substring(ip.lastIndexOf('.') + 1); - } else { - ip = "0"; - } - return ip; - } - - public static String getServerIP() { - InetAddress inet; - try { - inet = InetAddress.getLocalHost(); - String hostAddress = inet.getHostAddress(); - return hostAddress; - } catch (UnknownHostException e) { - e.printStackTrace(); - } - return "127.0.0.1"; - } -} diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/util/JsonMapper.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/util/JsonMapper.java deleted file mode 100644 index 940252e..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/util/JsonMapper.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.util; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; - -import java.io.IOException; - -/** - * Json 转化工具类 - * - * @package: com.xkcoding.springbootdemoaoplog.util - * @description:Json 转化工具类 - * @author: yangkai.shen - * @date: Created in 2017/11/24 上午9:36 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Slf4j -public class JsonMapper { - private static ObjectMapper objectMapper = new ObjectMapper(); - - /** - * 对象转 json 字符串 - * - * @param src 元对象 - * @param 类型 - * @return json 字符串 - */ - public static String obj2Str(T src) { - if (src == null) { - return null; - } - try { - return src instanceof String ? (String) src : objectMapper.writeValueAsString(src); - } catch (IOException e) { - log.error("【JSON 转换:对象 --> 字符串】,异常堆栈:{}", e); - return null; - } - } - - /** - * json 字符串转化为对象 - * - * @param src 源 json 字符串 - * @param typeReference 转化后的类型 - * @param 类型 - * @return 返回转化后的对象 - */ - public static T str2Obj(String src, TypeReference typeReference) { - if (src == null || typeReference == null) { - return null; - } - try { - return (T) (typeReference.getType().equals(String.class) ? src : objectMapper.readValue(src, typeReference)); - } catch (Exception e) { - log.error("【JSON 转换:字符串 --> 对象】,异常堆栈:{}", e); - return null; - } - } -} diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/util/MyMapper.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/util/MyMapper.java deleted file mode 100644 index bde8aff..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/util/MyMapper.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.util; - -import tk.mybatis.mapper.common.Mapper; -import tk.mybatis.mapper.common.MySqlMapper; - -public interface MyMapper extends Mapper, MySqlMapper { -} diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/util/SpringContextHolder.java b/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/util/SpringContextHolder.java deleted file mode 100644 index cf84333..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/java/com/xkcoding/springbootdemorabcshiromybatis/util/SpringContextHolder.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis.util; - -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.stereotype.Component; - -/** - *

- * Spring 的 ApplicationContext 的持有者,可以用静态方法的方式获取 spring 容器中的 bean - *

- * - * @package: com.xkcoding.springbootdemorabcshiromybatis.util - * @description: Spring 的 ApplicationContext 的持有者,可以用静态方法的方式获取 spring 容器中的 bean - * @author: yangkai.shen - * @date: Created in 2017/12/1 下午3:47 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Component -public class SpringContextHolder implements ApplicationContextAware { - private static ApplicationContext applicationContext; - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - SpringContextHolder.applicationContext = applicationContext; - } - - public static ApplicationContext getApplicationContext() { - assertApplicationContext(); - return applicationContext; - } - - public static T getBean(String beanName) { - assertApplicationContext(); - return (T) applicationContext.getBean(beanName); - } - - public static T getBean(Class requiredType) { - assertApplicationContext(); - return applicationContext.getBean(requiredType); - } - - private static void assertApplicationContext() { - if (SpringContextHolder.applicationContext == null) { - throw new RuntimeException("applicaitonContext属性为null,请检查是否注入了SpringContextHolder!"); - } - } -} diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/application.yml b/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/application.yml deleted file mode 100644 index f61816b..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/application.yml +++ /dev/null @@ -1,75 +0,0 @@ -server: - port: 8080 - context-path: /demo -spring: - thymeleaf: - mode: HTML5 - encoding: UTF-8 - content-type: text/html - cache: false - jackson: - time-zone: GMT+8 - date-format: yyyy-MM-dd HH:mm:ss - datasource: - # 启动时自动运行的 SQL 文件 - schema: classpath:init-sql/shiro.sql - continue-on-error: true - druid: - url: jdbc:mysql://localhost:3306/spring-boot-demo?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false - username: root - password: root - driver-class-name: com.mysql.jdbc.Driver - # 连接池配置 - # 初始化大小,最小,最大 - initialSize: 5 - minIdle: 5 - maxActive: 20 - # 配置获取连接等待超时的时间 - maxWait: 60000 - # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 - timeBetweenEvictionRunsMillis: 60000 - # 配置一个连接在池中最小生存的时间,单位是毫秒 - minEvictableIdleTimeMillis: 300000 - validationQuery: SELECT 1 FROM DUAL - testWhileIdle: true - testOnBorrow: false - testOnReturn: false - # 打开PSCache,并且指定每个连接上PSCache的大小 - poolPreparedStatements: true - maxPoolPreparedStatementPerConnectionSize: 20 - # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 - filters: stat,wall,log4j - # 监控配置 - web-stat-filter: - enabled: true - url-pattern: /* - exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" - stat-view-servlet: - enabled: true - url-pattern: /sys/druid/* - reset-enable: fasle - login-username: xkcoding - login-password: 123456 - filter: - stat: - log-slow-sql: true - slow-sql-millis: 5000 - merge-sql: true -# mybatis 配置 -mybatis: - type-aliases-package: com.xkcoding.springbootdemoormmybatistis.model - mapper-locations: classpath:mapper/*.xml - # 配置项:开启下划线到驼峰的自动转换. 作用:将数据库字段根据驼峰规则自动注入到对象属性 - configuration: - map-underscore-to-camel-case: true -# 通用 Mapper 配置 -mapper: - not-empty: false - identity: MYSQL - mappers: com.xkcoding.springbootdemorabcshiromybatis.util.MyMapper -# PageHelper 配置 -pagehelper: - helper-dialect: mysql - reasonable: true - support-methods-arguments: true - params: count=countSql \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/generator/config.properties b/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/generator/config.properties deleted file mode 100644 index 039f8f7..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/generator/config.properties +++ /dev/null @@ -1,8 +0,0 @@ -# 数据库配置 -jdbc.driverClass=com.mysql.jdbc.Driver -jdbc.url=jdbc:mysql://localhost:3306/spring-boot-demo -jdbc.user=root -jdbc.password=root -# 通用Mapper配置 -mapper.plugin=tk.mybatis.mapper.generator.MapperPlugin -mapper.Mapper=com.xkcoding.springbootdemorabcshiromybatis.util.MyMapper \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/generator/generatorConfig.xml b/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/generator/generatorConfig.xml deleted file mode 100644 index 702b499..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/generator/generatorConfig.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
\ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/init-sql/shiro.sql b/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/init-sql/shiro.sql deleted file mode 100644 index c95e350..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/init-sql/shiro.sql +++ /dev/null @@ -1,143 +0,0 @@ --- 建表 -- --- 部门表 -- -DROP TABLE IF EXISTS `mybatis_shiro_dept`; -CREATE TABLE `mybatis_shiro_dept` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '部门id', - `name` varchar(20) NOT NULL DEFAULT '' COMMENT '部门名称', - `parent_id` int(11) NOT NULL DEFAULT '0' COMMENT '上级部门id,顶层是0', - `level` varchar(255) NOT NULL DEFAULT '0' COMMENT '部门层级,默认为0,层级直接用逗号(半角)隔开', - `seq` int(11) NOT NULL DEFAULT '0' COMMENT '部门在当前层级下的顺序,由小到大', - `remark` varchar(200) DEFAULT '' COMMENT '备注', - `operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者', - `operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新时间', - `operate_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新操作者的ip地址', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='部门表'; - -INSERT INTO `mybatis_shiro_dept` VALUES (1, '总公司', 0, '0', 0, '总公司', '系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_dept` VALUES (2, '开发部', 1, '0,1', 0, '开发部', '系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_dept` VALUES (3, '运营部', 1, '0,1', 1, '运营部', '系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_dept` VALUES (4, '战略部', 1, '0,1', 2, '战略部', '系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_dept` VALUES (5, '软件部', 2, '0,1,2', 0, '软件部', '系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_dept` VALUES (6, '硬件部', 2, '0,1,2', 1, '硬件部', '系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_dept` VALUES (7, '采购部', 6, '0,1,2,6', 0, '采购部', '系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_dept` VALUES (8, '维修部', 6, '0,1,2,6', 1, '维修部', '系统', '2017-12-01 00:00:00', '127.0.0.1'); - --- 用户表 -- -DROP TABLE IF EXISTS `mybatis_shiro_user`; -CREATE TABLE `mybatis_shiro_user` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户id', - `username` varchar(20) NOT NULL DEFAULT '' COMMENT '用户名', - `password` varchar(40) NOT NULL DEFAULT '' COMMENT '加密后的密码', - `salt` varchar(32) NOT NULL DEFAULT '' COMMENT '密码加密的盐值', - `avatar` varchar(255) DEFAULT NULL COMMENT '头像', - `realname` varchar(20) NOT NULL DEFAULT '' COMMENT '真实姓名', - `telephone` varchar(13) NOT NULL DEFAULT '' COMMENT '手机号', - `mail` varchar(20) NOT NULL DEFAULT '' COMMENT '邮箱', - `dept_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户所在部门的id', - `status` int(11) NOT NULL DEFAULT '1' COMMENT '状态,-1:删除,0:冻结状态,1:正常', - `remark` varchar(200) DEFAULT '' COMMENT '备注', - `last_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次登录的时间', - `last_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次登录的ip地址', - `operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者', - `operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新时间', - `operate_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新操作者的ip地址', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT ='用户表'; - -INSERT INTO `mybatis_shiro_user` VALUES (1, 'xkcoding', '29b97b26be547c8442689bdbe6f1efb9', '77798aa08e914989bb588188cb2c0ad4', '','沈扬凯','18601224166','237497819@qq.com',5,1,'本尊','2017-12-01 00:00:00', '127.0.0.1', '系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_user` VALUES (2, 'test', '29b97b26be547c8442689bdbe6f1efb9', '77798aa08e914989bb588188cb2c0ad4', '','测试用户','18666666666','qaz@qq.com',6,1,'测试用户', '2017-12-01 00:00:00', '127.0.0.1','系统', '2017-12-01 00:00:00', '127.0.0.1'); - --- 权限表 -- -DROP TABLE IF EXISTS `mybatis_shiro_acl`; -CREATE TABLE `mybatis_shiro_acl` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '权限id', - `code` varchar(20) NOT NULL DEFAULT '' COMMENT '权限编号', - `name` varchar(20) NOT NULL DEFAULT '' COMMENT '权限名称', - `icon` varchar(255) DEFAULT NULL COMMENT '权限图标', - `parent_id` int(11) NOT NULL DEFAULT '0' COMMENT '上级权限id', - `level` varchar(255) NOT NULL DEFAULT '' COMMENT '权限层级,默认为0,层级直接用逗号(半角)隔开', - `url` varchar(100) NOT NULL DEFAULT '' COMMENT '权限的url, 可以填正则表达式', - `type` int(11) NOT NULL DEFAULT '3' COMMENT '类型,1:菜单,2:按钮,3:其他', - `status` int(11) NOT NULL DEFAULT '1' COMMENT '状态,0:冻结,1:正常', - `seq` int(11) NOT NULL DEFAULT '0' COMMENT '权限在当前层级下的顺序,由小到大', - `remark` varchar(200) DEFAULT '' COMMENT '备注', - `operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者', - `operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新时间', - `operate_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新操作者的ip地址', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT ='权限表'; - -INSERT INTO `mybatis_shiro_acl` VALUES (1,'system_mgr','系统管理','',0,'0','/system_mgr/*',1,1,0,'系统管理', '系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_acl` VALUES (2,'user_mgr','用户管理','',1,'0,1','/system_mgr/user_mgr/*',1,1,0,'用户管理', '系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_acl` VALUES (3,'user_insert','新增用户','',2,'0,1,2','/user/add',2,1,0,'新增用户','系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_acl` VALUES (4,'user_delete','删除用户','',2,'0,1,2','/user/delete',2,1,1,'删除用户','系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_acl` VALUES (5,'user_update','修改用户','',2,'0,1,2','/user/update',2,1,2,'修改用户','系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_acl` VALUES (6,'user_select','查询用户','',2,'0,1,2','/user/select',2,1,3,'查询用户','系统', '2017-12-01 00:00:00', '127.0.0.1'); - --- 角色表 -- -DROP TABLE IF EXISTS `mybatis_shiro_role`; -CREATE TABLE `mybatis_shiro_role` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '角色id', - `name` varchar(20) NOT NULL COMMENT '角色名称', - `type` int(11) NOT NULL DEFAULT '1' COMMENT '角色的类型,1:管理员角色,2:其他', - `status` int(11) NOT NULL DEFAULT '1' COMMENT '状态,0:冻结,1:可用', - `remark` varchar(200) DEFAULT '' COMMENT '备注', - `operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者', - `operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新时间', - `operate_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新操作者的ip地址', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT ='角色表'; - -INSERT INTO `mybatis_shiro_role` VALUES (1,'超级管理员', 1, 1,'超级管理员' ,'系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_role` VALUES (2, '临时', 2, 1,'临时','系统', '2017-12-01 00:00:00', '127.0.0.1'); - --- 角色-用户表 -- -DROP TABLE IF EXISTS `mybatis_shiro_role_user`; -CREATE TABLE `mybatis_shiro_role_user` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '角色-用户id', - `role_id` int(11) NOT NULL COMMENT '角色id', - `user_id` int(11) NOT NULL COMMENT '用户id', - `operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者', - `operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新时间', - `operate_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新操作者的ip地址', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -INSERT INTO `mybatis_shiro_role_user` VALUES (1, 1, 1,'系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_role_user` VALUES (2, 2, 2,'系统', '2017-12-01 00:00:00', '127.0.0.1'); - --- 角色-权限表 -- -DROP TABLE IF EXISTS `mybatis_shiro_role_acl`; -CREATE TABLE `mybatis_shiro_role_acl` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '角色-权限id', - `role_id` int(11) NOT NULL COMMENT '角色id', - `acl_id` int(11) NOT NULL COMMENT '权限id', - `operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者', - `operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新时间', - `operate_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新操作者的ip地址', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -INSERT INTO `mybatis_shiro_role_acl` VALUES (1, 1, 1,'系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_role_acl` VALUES (2, 1, 2,'系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_role_acl` VALUES (3, 1, 3,'系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_role_acl` VALUES (4, 1, 4,'系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_role_acl` VALUES (5, 1, 5,'系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_role_acl` VALUES (6, 1, 6,'系统', '2017-12-01 00:00:00', '127.0.0.1'); -INSERT INTO `mybatis_shiro_role_acl` VALUES (7, 2, 6,'系统', '2017-12-01 00:00:00', '127.0.0.1'); - --- 日志记录表 -- -DROP TABLE IF EXISTS `mybatis_shiro_log`; -CREATE TABLE `mybatis_shiro_log` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '日志记录id', - `type` int(11) NOT NULL DEFAULT '0' COMMENT '权限更新的类型,1:部门,2:用户,3:权限模块,4:权限,5:角色,6:角色用户关系,7:角色权限关系', - `target_id` int(11) NOT NULL COMMENT '基于type后指定的对象id,比如用户、权限、角色等表的主键', - `old_value` text COMMENT '旧值', - `new_value` text COMMENT '新值', - `operator` varchar(20) NOT NULL DEFAULT '' COMMENT '操作者', - `operate_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新时间', - `operate_ip` varchar(20) NOT NULL DEFAULT '' COMMENT '最后一次更新操作者的ip地址', - `status` int(11) NOT NULL DEFAULT '0' COMMENT '当前是否复原过,0:没有复原过,1:复原过', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/logback-spring.xml b/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/logback-spring.xml deleted file mode 100644 index 77cf77a..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - 【xkcoding】%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx} - - - - - - - - - ${user.dir}/logs/log/spring-boot-demo-rabc-shiro-mybatis.%d.log - - - 【xkcoding】%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n - - - - - - ERROR - ACCEPT - DENY - - - - - ${user.dir}/logs/error/spring-boot-demo-rabc-shiro-mybatis.%d.error - - - 【xkcoding】%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n - - - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroAclMapper.xml b/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroAclMapper.xml deleted file mode 100644 index ea67113..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroAclMapper.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroDeptMapper.xml b/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroDeptMapper.xml deleted file mode 100644 index be1d71c..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroDeptMapper.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroLogMapper.xml b/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroLogMapper.xml deleted file mode 100644 index c33df40..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroLogMapper.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroRoleAclMapper.xml b/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroRoleAclMapper.xml deleted file mode 100644 index 02170ff..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroRoleAclMapper.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroRoleMapper.xml b/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroRoleMapper.xml deleted file mode 100644 index bd64e59..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroRoleMapper.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroRoleUserMapper.xml b/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroRoleUserMapper.xml deleted file mode 100644 index 2d4d9d4..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroRoleUserMapper.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroUserMapper.xml b/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroUserMapper.xml deleted file mode 100644 index a7998a1..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/mapper/MybatisShiroUserMapper.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/templates/index.html b/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/templates/index.html deleted file mode 100644 index ac445e9..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/main/resources/templates/index.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - Document - - - - -用户名: -密码: - - - - - \ No newline at end of file diff --git a/spring-boot-demo-rabc-shiro-mybatis/src/test/java/com/xkcoding/springbootdemorabcshiromybatis/SpringBootDemoRabcShiroMybatisApplicationTests.java b/spring-boot-demo-rabc-shiro-mybatis/src/test/java/com/xkcoding/springbootdemorabcshiromybatis/SpringBootDemoRabcShiroMybatisApplicationTests.java deleted file mode 100644 index 96e27ab..0000000 --- a/spring-boot-demo-rabc-shiro-mybatis/src/test/java/com/xkcoding/springbootdemorabcshiromybatis/SpringBootDemoRabcShiroMybatisApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemorabcshiromybatis; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoRabcShiroMybatisApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-swagger/README.md b/spring-boot-demo-swagger/README.md deleted file mode 100644 index 37b4baa..0000000 --- a/spring-boot-demo-swagger/README.md +++ /dev/null @@ -1,178 +0,0 @@ -# spring-boot-demo-swagger - -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent)、[spring-boot-starter-swagger](https://github.com/SpringForAll/spring-boot-starter-swagger) (由大佬[翟永超](http://blog.didispace.com/)开源) - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-swagger - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-swagger - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - 1.5.1.RELEASE - - - - - com.spring4all - spring-boot-starter-swagger - ${swagger.version} - - - - - spring-boot-demo-swagger - - - -``` - -### application.yml - -```yaml -server: - port: 8080 - context-path: /demo -swagger: - # 是否启用swagger,默认:true - enabled: true - # 标题 - title: swagger-demo API 管理 - # 描述 - description: 这里是 swagger-demo API 管理的描述信息 - # 版本 - version: 0.0.1-SNAPSHOT - # 许可证 - license: MIT License - # 许可证URL - licenseUrl: https://github.com/xkcoding/spring-boot-demo/blob/master/LICENSE - # 许可证URL - termsOfServiceUrl: https://github.com/xkcoding/spring-boot-demo/blob/master/LICENSE - contact: - # 维护人 - name: xkcoding - # 维护人URL - url: http://xkcoding.com - # 维护人URL - email: 237497819@qq.com - # swagger扫描的基础包,默认:全扫描 - base-package: com.xkcoding - # 需要处理的基础URL规则,默认:/** - base-path: /** - # 需要排除的URL规则,默认:空 - exclude-path: /error -# swagger.host=文档的host信息,默认:空 -# swagger.globalOperationParameters[0].name=参数名 -# swagger.globalOperationParameters[0].description=描述信息 -# swagger.globalOperationParameters[0].modelRef=指定参数类型 -# swagger.globalOperationParameters[0].parameterType=指定参数存放位置,可选header,query,path,body.form -# swagger.globalOperationParameters[0].required=指定参数是否必传,true,false -``` - -### SpringBootDemoSwaggerApplication.java - -```java -@SpringBootApplication -@EnableSwagger2Doc // 启用 Swagger -public class SpringBootDemoSwaggerApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoSwaggerApplication.class, args); - } -} -``` - -### User.java - -```java -@Data -@NoArgsConstructor -@AllArgsConstructor -@ApiModel("用户基本信息") -public class User { - private Long id; - - @ApiModelProperty("姓名") - @Size(max = 20) - private String name; - - @Max(value = 30, message = "年龄小于30岁才可以!") - @Min(value = 18, message = "你必须成年才可以!") - private Integer age; - - @Pattern(regexp = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", message = "邮箱格式错误!") - private String email; - - @Pattern(regexp = "^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$", message = "请输入正确的手机格式!") - private String phone; -} -``` - -### UserController.java - -```java -@Api(tags = "用户管理") -@RestController -@RequestMapping("/user") -public class UserController { - - @ApiOperation("新增用户") - @PostMapping({"", "/"}) - public User insert(@RequestBody @Valid User user) { - return user; - } - - @ApiIgnore - @DeleteMapping("/{id}") - public String deleteById(@PathVariable Long id) { - return "已删除用户 --> " + id; - } - - @ApiOperation("修改用户详情") - @PutMapping("/{id}") - public User update(@PathVariable Long id, @RequestBody @Valid User user) { - user.setId(id); - return user; - } - - @ApiOperation("用户详情") - @GetMapping("/{id}") - public User findById(@PathVariable Long id) { - return new User(id, "xkcoding" + id, 21, StrUtil.format("xkcoding{}@163.com", id), StrUtil.fill("186", id.toString().charAt(0), 11, false)); - } - - @ApiOperation("用户列表") - @GetMapping({"", "/"}) - public List index(@ApiParam("第几页") @RequestParam(defaultValue = "1") Integer pageNum, @ApiParam("每页的条目数") @RequestParam(defaultValue = "20") Integer pageSize) { - List users = Lists.newArrayList(); - users.add(new User(0L, "xkcoding0", 18, "xkcoding0@163.com", "18600000000")); - users.add(new User(1L, "xkcoding1", 19, "xkcoding1@163.com", "18611111111")); - return users; - } - -} -``` - -### 启动项目,查看 API 接口信息 - -http://localhost:8080/demo/swagger-ui.html - -### 附上大佬(翟永超)博客关于 swagger 的一些文章 - -http://blog.didispace.com/tags/Swagger/ \ No newline at end of file diff --git a/spring-boot-demo-swagger/pom.xml b/spring-boot-demo-swagger/pom.xml deleted file mode 100644 index 06848fb..0000000 --- a/spring-boot-demo-swagger/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-swagger - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-swagger - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - 1.5.1.RELEASE - - - - - com.spring4all - spring-boot-starter-swagger - ${swagger.version} - - - - - spring-boot-demo-swagger - - - \ No newline at end of file diff --git a/spring-boot-demo-swagger/src/main/java/com/xkcoding/springbootdemoswagger/SpringBootDemoSwaggerApplication.java b/spring-boot-demo-swagger/src/main/java/com/xkcoding/springbootdemoswagger/SpringBootDemoSwaggerApplication.java deleted file mode 100644 index 975bc5c..0000000 --- a/spring-boot-demo-swagger/src/main/java/com/xkcoding/springbootdemoswagger/SpringBootDemoSwaggerApplication.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.xkcoding.springbootdemoswagger; - -import com.spring4all.swagger.EnableSwagger2Doc; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -@EnableSwagger2Doc // 启用 Swagger -public class SpringBootDemoSwaggerApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoSwaggerApplication.class, args); - } -} diff --git a/spring-boot-demo-swagger/src/main/java/com/xkcoding/springbootdemoswagger/controller/UserController.java b/spring-boot-demo-swagger/src/main/java/com/xkcoding/springbootdemoswagger/controller/UserController.java deleted file mode 100644 index 41024ec..0000000 --- a/spring-boot-demo-swagger/src/main/java/com/xkcoding/springbootdemoswagger/controller/UserController.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.xkcoding.springbootdemoswagger.controller; - -import com.google.common.collect.Lists; -import com.xiaoleilu.hutool.util.StrUtil; -import com.xkcoding.springbootdemoswagger.model.User; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import org.springframework.web.bind.annotation.*; -import springfox.documentation.annotations.ApiIgnore; - -import javax.validation.Valid; -import java.util.List; - -@Api(tags = "用户管理") -@RestController -@RequestMapping("/user") -public class UserController { - - @ApiOperation("新增用户") - @PostMapping({"", "/"}) - public User insert(@RequestBody @Valid User user) { - return user; - } - - @ApiIgnore - @DeleteMapping("/{id}") - public String deleteById(@PathVariable Long id) { - return "已删除用户 --> " + id; - } - - @ApiOperation("修改用户详情") - @PutMapping("/{id}") - public User update(@PathVariable Long id, @RequestBody @Valid User user) { - user.setId(id); - return user; - } - - @ApiOperation("用户详情") - @GetMapping("/{id}") - public User findById(@PathVariable Long id) { - return new User(id, "xkcoding" + id, 21, StrUtil.format("xkcoding{}@163.com", id), StrUtil.fill("186", id.toString().charAt(0), 11, false)); - } - - @ApiOperation("用户列表") - @GetMapping({"", "/"}) - public List index(@ApiParam("第几页") @RequestParam(defaultValue = "1") Integer pageNum, @ApiParam("每页的条目数") @RequestParam(defaultValue = "20") Integer pageSize) { - List users = Lists.newArrayList(); - users.add(new User(0L, "xkcoding0", 18, "xkcoding0@163.com", "18600000000")); - users.add(new User(1L, "xkcoding1", 19, "xkcoding1@163.com", "18611111111")); - return users; - } - -} diff --git a/spring-boot-demo-swagger/src/main/java/com/xkcoding/springbootdemoswagger/model/User.java b/spring-boot-demo-swagger/src/main/java/com/xkcoding/springbootdemoswagger/model/User.java deleted file mode 100644 index 1d461f4..0000000 --- a/spring-boot-demo-swagger/src/main/java/com/xkcoding/springbootdemoswagger/model/User.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.xkcoding.springbootdemoswagger.model; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.validation.constraints.Max; -import javax.validation.constraints.Min; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@ApiModel("用户基本信息") -public class User { - private Long id; - - @ApiModelProperty("姓名") - @Size(max = 20) - private String name; - - @Max(value = 30, message = "年龄小于30岁才可以!") - @Min(value = 18, message = "你必须成年才可以!") - private Integer age; - - @Pattern(regexp = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", message = "邮箱格式错误!") - private String email; - - @Pattern(regexp = "^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$", message = "请输入正确的手机格式!") - private String phone; -} diff --git a/spring-boot-demo-swagger/src/main/resources/application.yml b/spring-boot-demo-swagger/src/main/resources/application.yml deleted file mode 100644 index e2bb77e..0000000 --- a/spring-boot-demo-swagger/src/main/resources/application.yml +++ /dev/null @@ -1,37 +0,0 @@ -server: - port: 8080 - context-path: /demo -swagger: - # 是否启用swagger,默认:true - enabled: true - # 标题 - title: swagger-demo API 管理 - # 描述 - description: 这里是 swagger-demo API 管理的描述信息 - # 版本 - version: 0.0.1-SNAPSHOT - # 许可证 - license: MIT License - # 许可证URL - licenseUrl: https://github.com/xkcoding/spring-boot-demo/blob/master/LICENSE - # 许可证URL - termsOfServiceUrl: https://github.com/xkcoding/spring-boot-demo/blob/master/LICENSE - contact: - # 维护人 - name: xkcoding - # 维护人URL - url: http://xkcoding.com - # 维护人URL - email: 237497819@qq.com - # swagger扫描的基础包,默认:全扫描 - base-package: com.xkcoding - # 需要处理的基础URL规则,默认:/** - base-path: /** - # 需要排除的URL规则,默认:空 - exclude-path: /error -# swagger.host=文档的host信息,默认:空 -# swagger.globalOperationParameters[0].name=参数名 -# swagger.globalOperationParameters[0].description=描述信息 -# swagger.globalOperationParameters[0].modelRef=指定参数类型 -# swagger.globalOperationParameters[0].parameterType=指定参数存放位置,可选header,query,path,body.form -# swagger.globalOperationParameters[0].required=指定参数是否必传,true,false \ No newline at end of file diff --git a/spring-boot-demo-swagger/src/test/java/com/xkcoding/springbootdemoswagger/SpringBootDemoSwaggerApplicationTests.java b/spring-boot-demo-swagger/src/test/java/com/xkcoding/springbootdemoswagger/SpringBootDemoSwaggerApplicationTests.java deleted file mode 100644 index e151ffb..0000000 --- a/spring-boot-demo-swagger/src/test/java/com/xkcoding/springbootdemoswagger/SpringBootDemoSwaggerApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemoswagger; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoSwaggerApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-task-schedule/README.md b/spring-boot-demo-task-schedule/README.md deleted file mode 100644 index 98ccfdf..0000000 --- a/spring-boot-demo-task-schedule/README.md +++ /dev/null @@ -1,84 +0,0 @@ -# spring-boot-demo-task-schedule - -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent) - -## TaskConfig.java - -```java -/** - *

- * 定时任务配置,配置线程池,使用不同线程执行任务,提升效率 - *

- * - * @package: com.xkcoding.springbootdemotaskschedule.config - * @description: 定时任务配置,配置线程池,使用不同线程执行任务,提升效率 - * @author: yangkai.shen - * @date: Created in 2018/5/8 上午10:01 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Configuration -@EnableScheduling -@ComponentScan(basePackages = "com.xkcoding.springbootdemotaskschedule.task") -public class TaskConfig implements SchedulingConfigurer { - - @Override - public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { - taskRegistrar.setScheduler(taskExecutor()); - } - - @Bean - public Executor taskExecutor() { - return Executors.newScheduledThreadPool(100); - } - -} -``` - -## TaskJob.java - -```java -/** - *

- * 定时任务 - *

- * - * @package: com.xkcoding.springbootdemotaskschedule.task - * @description: 定时任务 - * @author: yangkai.shen - * @date: Created in 2018/5/8 上午10:05 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Component -@Slf4j -public class TaskJob { - - /** - * 每隔 10s 执行一次 - */ - @Scheduled(cron = "0/10 * * * * ?") - public void job1(){ - log.info("【job1】开始执行:{}",DateUtil.formatDateTime(new Date())); - } - - /** - * 间隔 2s 执行 - */ - @Scheduled(fixedRate = 2000) - public void job2(){ - log.info("【job2】开始执行:{}",DateUtil.formatDateTime(new Date())); - } - - /** - * 延迟 5s 后间隔 4s 执行 - */ - @Scheduled(fixedDelay = 4000,initialDelay = 5000) - public void job3(){ - log.info("【job3】开始执行:{}",DateUtil.formatDateTime(new Date())); - } -} -``` - diff --git a/spring-boot-demo-task-schedule/pom.xml b/spring-boot-demo-task-schedule/pom.xml deleted file mode 100644 index 1f0508f..0000000 --- a/spring-boot-demo-task-schedule/pom.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-task-schedule - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-task-schedule - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - spring-boot-demo-task-schedule - - - \ No newline at end of file diff --git a/spring-boot-demo-task-schedule/src/main/java/com/xkcoding/springbootdemotaskschedule/SpringBootDemoTaskScheduleApplication.java b/spring-boot-demo-task-schedule/src/main/java/com/xkcoding/springbootdemotaskschedule/SpringBootDemoTaskScheduleApplication.java deleted file mode 100644 index 20a0e77..0000000 --- a/spring-boot-demo-task-schedule/src/main/java/com/xkcoding/springbootdemotaskschedule/SpringBootDemoTaskScheduleApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.xkcoding.springbootdemotaskschedule; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringBootDemoTaskScheduleApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoTaskScheduleApplication.class, args); - } -} diff --git a/spring-boot-demo-task-schedule/src/main/java/com/xkcoding/springbootdemotaskschedule/config/TaskConfig.java b/spring-boot-demo-task-schedule/src/main/java/com/xkcoding/springbootdemotaskschedule/config/TaskConfig.java deleted file mode 100644 index d36a1f7..0000000 --- a/spring-boot-demo-task-schedule/src/main/java/com/xkcoding/springbootdemotaskschedule/config/TaskConfig.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.xkcoding.springbootdemotaskschedule.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.scheduling.annotation.SchedulingConfigurer; -import org.springframework.scheduling.config.ScheduledTaskRegistrar; - -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; - -/** - *

- * 定时任务配置,配置线程池,使用不同线程执行任务,提升效率 - *

- * - * @package: com.xkcoding.springbootdemotaskschedule.config - * @description: 定时任务配置,配置线程池,使用不同线程执行任务,提升效率 - * @author: yangkai.shen - * @date: Created in 2018/5/8 上午10:01 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Configuration -@EnableScheduling -@ComponentScan(basePackages = "com.xkcoding.springbootdemotaskschedule.task") -public class TaskConfig implements SchedulingConfigurer { - - @Override - public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { - taskRegistrar.setScheduler(taskExecutor()); - } - - @Bean - public Executor taskExecutor() { - return Executors.newScheduledThreadPool(100); - } - -} diff --git a/spring-boot-demo-task-schedule/src/main/java/com/xkcoding/springbootdemotaskschedule/task/TaskJob.java b/spring-boot-demo-task-schedule/src/main/java/com/xkcoding/springbootdemotaskschedule/task/TaskJob.java deleted file mode 100644 index 00514b3..0000000 --- a/spring-boot-demo-task-schedule/src/main/java/com/xkcoding/springbootdemotaskschedule/task/TaskJob.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.xkcoding.springbootdemotaskschedule.task; - -import com.xiaoleilu.hutool.date.DateUtil; -import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import java.util.Date; - -/** - *

- * 定时任务 - *

- * - * @package: com.xkcoding.springbootdemotaskschedule.task - * @description: 定时任务 - * @author: yangkai.shen - * @date: Created in 2018/5/8 上午10:05 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Component -@Slf4j -public class TaskJob { - - /** - * 每隔 10s 执行一次 - */ - @Scheduled(cron = "0/10 * * * * ?") - public void job1(){ - log.info("【job1】开始执行:{}",DateUtil.formatDateTime(new Date())); - } - - /** - * 间隔 2s 执行 - * 固定间隔时间 - */ - @Scheduled(fixedRate = 2000) - public void job2(){ - log.info("【job2】开始执行:{}",DateUtil.formatDateTime(new Date())); - } - - /** - * 延迟 5s 后间隔 4s 执行 - * 固定等待时间 - */ - @Scheduled(fixedDelay = 4000,initialDelay = 5000) - public void job3(){ - log.info("【job3】开始执行:{}",DateUtil.formatDateTime(new Date())); - } -} diff --git a/spring-boot-demo-task-schedule/src/main/resources/application.yml b/spring-boot-demo-task-schedule/src/main/resources/application.yml deleted file mode 100644 index e69de29..0000000 diff --git a/spring-boot-demo-task-schedule/src/test/java/com/xkcoding/springbootdemotaskschedule/SpringBootDemoTaskScheduleApplicationTests.java b/spring-boot-demo-task-schedule/src/test/java/com/xkcoding/springbootdemotaskschedule/SpringBootDemoTaskScheduleApplicationTests.java deleted file mode 100644 index f4d5943..0000000 --- a/spring-boot-demo-task-schedule/src/test/java/com/xkcoding/springbootdemotaskschedule/SpringBootDemoTaskScheduleApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemotaskschedule; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoTaskScheduleApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-template-beetl/README.md b/spring-boot-demo-template-beetl/README.md deleted file mode 100644 index a47829e..0000000 --- a/spring-boot-demo-template-beetl/README.md +++ /dev/null @@ -1,145 +0,0 @@ -# spring-boot-demo-template-beetl - -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent) 、`beetl-framework-starter` - -## pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-template-beetl - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-template-beetl - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - com.ibeetl - beetl-framework-starter - 1.1.46.RELEASE - - - - - spring-boot-demo-template-beetl - - - -``` - -## HomeController.java - -```java -/** - *

- * 首页 Controller - *

- * - * @package: com.xkcoding.springbootdemotemplatebeetl.controller - * @description: 首页 Controller - * @author: yangkai.shen - * @date: Created in 2018/4/26 下午4:36 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Controller -public class HomeController { - - @GetMapping({"", "/", "/index"}) - public ModelAndView index() { - ModelAndView view = new ModelAndView("/index.btl"); - User admin = new User(0, "admin", "phone0",true); - List userList = Lists.newArrayList(new User(1, "user1", "phone1",false), new User(2, "user2", "phone2",true), new User(3, "user3", "phone3",true),new User(4, "user4", "phone4",false)); - - view.addObject("admin",admin); - view.addObject("userList",userList); - return view; - } -} -``` - -## index.btl - -```html - - - - - - - Beetl demo - - -this is index.btl to show some beetl demos!
- - -<% -/* demo01 */ -var a = 1; -var b = 2; -var result = a + b; -%> -1+2=${result}
- - -<% -/* demo02 */ -print(111); -%> - - -欢迎登录,${admin.admin?"管理员":"员工"} ${admin.name}
- - - - - - - - - - - - - - - <%for(u in userList){%> - - - - - - - <%if(uLP.even){%> - - <%}else{%> - - <%}%> - - <%}%> - -
序号编号姓名手机职位注册日期
${uLP.index}${u.id}${u.name}${u.tel}${u.admin?"管理员":"员工"}<%var today = date();%> ${today,dateFormat="yyyy-MM-dd HH:mm:ss"}<%var today = date();%> ${today,dateFormat="yyyy-MM-dd"}
- - - -``` - -## Beetl 语法 - -请查看 Beetl 官网: - -http://ibeetl.com/guide/#beetl \ No newline at end of file diff --git a/spring-boot-demo-template-beetl/pom.xml b/spring-boot-demo-template-beetl/pom.xml deleted file mode 100644 index f6601b1..0000000 --- a/spring-boot-demo-template-beetl/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-template-beetl - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-template-beetl - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - com.ibeetl - beetl-framework-starter - 1.1.46.RELEASE - - - - - spring-boot-demo-template-beetl - - - \ No newline at end of file diff --git a/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/SpringBootDemoTemplateBeetlApplication.java b/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/SpringBootDemoTemplateBeetlApplication.java deleted file mode 100644 index 59424b5..0000000 --- a/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/SpringBootDemoTemplateBeetlApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.xkcoding.springbootdemotemplatebeetl; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringBootDemoTemplateBeetlApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoTemplateBeetlApplication.class, args); - } -} diff --git a/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/controller/HomeController.java b/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/controller/HomeController.java deleted file mode 100644 index 0680ddc..0000000 --- a/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/controller/HomeController.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.xkcoding.springbootdemotemplatebeetl.controller; - -import com.google.common.collect.Lists; -import com.xkcoding.springbootdemotemplatebeetl.model.User; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.servlet.ModelAndView; - -import java.util.List; - -/** - *

- * 首页 Controller - *

- * - * @package: com.xkcoding.springbootdemotemplatebeetl.controller - * @description: 首页 Controller - * @author: yangkai.shen - * @date: Created in 2018/4/26 下午4:36 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Controller -public class HomeController { - - @GetMapping({"", "/", "/index"}) - public ModelAndView index() { - ModelAndView view = new ModelAndView("/index.btl"); - User admin = new User(0, "admin", "phone0",true); - List userList = Lists.newArrayList(new User(1, "user1", "phone1",false), new User(2, "user2", "phone2",true), new User(3, "user3", "phone3",true),new User(4, "user4", "phone4",false)); - - view.addObject("admin",admin); - view.addObject("userList",userList); - return view; - } -} diff --git a/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/model/User.java b/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/model/User.java deleted file mode 100644 index d832972..0000000 --- a/spring-boot-demo-template-beetl/src/main/java/com/xkcoding/springbootdemotemplatebeetl/model/User.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.xkcoding.springbootdemotemplatebeetl.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.io.Serializable; - -/** - *

- * 用户实体类 - *

- * - * @package: com.xkcoding.springbootdemotemplatebeetl.model - * @description: 用户实体类 - * @author: yangkai.shen - * @date: Created in 2018/4/26 下午4:46 - * @copyright: Copyright (c) 2018 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class User implements Serializable { - private Integer id; - private String name; - private String tel; - private Boolean admin; -} diff --git a/spring-boot-demo-template-beetl/src/main/resources/application.yml b/spring-boot-demo-template-beetl/src/main/resources/application.yml deleted file mode 100644 index 172dc29..0000000 --- a/spring-boot-demo-template-beetl/src/main/resources/application.yml +++ /dev/null @@ -1,5 +0,0 @@ -server: - port: 8080 - context-path: /demo -beetlSql: - enabled: false diff --git a/spring-boot-demo-template-beetl/src/main/resources/templates/index.btl b/spring-boot-demo-template-beetl/src/main/resources/templates/index.btl deleted file mode 100644 index 0017df3..0000000 --- a/spring-boot-demo-template-beetl/src/main/resources/templates/index.btl +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - Beetl demo - - -this is index.btl to show some beetl demos!
- - -<% -/* demo01 */ -var a = 1; -var b = 2; -var result = a + b; -%> -1+2=${result}
- - -<% -/* demo02 */ -print(111); -%> - - -欢迎登录,${admin.admin?"管理员":"员工"} ${admin.name}
- - - - - - - - - - - - - - - <%for(u in userList){%> - - - - - - - <%if(uLP.even){%> - - <%}else{%> - - <%}%> - - <%}%> - -
序号编号姓名手机职位注册日期
${uLP.index}${u.id}${u.name}${u.tel}${u.admin?"管理员":"员工"}<%var today = date();%> ${today,dateFormat="yyyy-MM-dd HH:mm:ss"}<%var today = date();%> ${today,dateFormat="yyyy-MM-dd"}
- - - \ No newline at end of file diff --git a/spring-boot-demo-template-beetl/src/test/java/com/xkcoding/springbootdemotemplatebeetl/SpringBootDemoTemplateBeetlApplicationTests.java b/spring-boot-demo-template-beetl/src/test/java/com/xkcoding/springbootdemotemplatebeetl/SpringBootDemoTemplateBeetlApplicationTests.java deleted file mode 100644 index 5e453dc..0000000 --- a/spring-boot-demo-template-beetl/src/test/java/com/xkcoding/springbootdemotemplatebeetl/SpringBootDemoTemplateBeetlApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemotemplatebeetl; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoTemplateBeetlApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-template-freemarker/README.md b/spring-boot-demo-template-freemarker/README.md deleted file mode 100644 index 4b61977..0000000 --- a/spring-boot-demo-template-freemarker/README.md +++ /dev/null @@ -1,140 +0,0 @@ -# spring-boot-demo-template-freemarker - -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent) 、`spring-boot-starter-freemarker` - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-template-freemarker - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-template-freemarker - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - org.springframework.boot - spring-boot-starter-freemarker - - - - - spring-boot-demo-template-freemarker - - - -``` - -### SpringBootDemoTemplateFreemarkerApplication.java - -```java -@Controller -@SpringBootApplication -public class SpringBootDemoTemplateFreemarkerApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoTemplateFreemarkerApplication.class, args); - } - - @GetMapping({"","/"}) - public ModelAndView home(){ - return new ModelAndView("index"); - } -} -``` - -### UserController.java - -```java -/** - * 用户 Controller - * - * @package: com.xkcoding.springbootdemotemplatefreemarker.controller - * @description: 用户 Controller - * @author: yangkai.shen - * @date: Created in 2017/11/26 下午6:47 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Controller -@RequestMapping("/user") -@Slf4j -public class UserController { - - @PostMapping("/login") - public ModelAndView login(User user, HttpServletRequest request) { - ModelAndView mv = new ModelAndView(); - - mv.addObject(user); - mv.setViewName("home"); - - request.getSession().setAttribute("user", user); - return mv; - } - - @GetMapping("/login") - public ModelAndView login(HttpServletRequest request) { - ModelAndView mv = new ModelAndView(); - - User user = (User) request.getSession().getAttribute("user"); - if (user == null) { - mv.setViewName("redirect:/"); - } else { - mv.setViewName("home"); - } - - return mv; - } -} -``` - -### home.ftl - -```html - - -<#include "./common/header.ftl"> - -
- 欢迎登录,${user.name}! -
- - -``` - -### index.ftl - -```html - - -<#include "./common/header.ftl"> - -
-
- 用户名 - 密码 - -
-
- - - -``` - -### Freemarker 语法 - -待补充。。。 \ No newline at end of file diff --git a/spring-boot-demo-template-freemarker/pom.xml b/spring-boot-demo-template-freemarker/pom.xml deleted file mode 100644 index 7a9731b..0000000 --- a/spring-boot-demo-template-freemarker/pom.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-template-freemarker - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-template-freemarker - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - org.springframework.boot - spring-boot-starter-freemarker - - - - - spring-boot-demo-template-freemarker - - - \ No newline at end of file diff --git a/spring-boot-demo-template-freemarker/src/main/java/com/xkcoding/springbootdemotemplatefreemarker/SpringBootDemoTemplateFreemarkerApplication.java b/spring-boot-demo-template-freemarker/src/main/java/com/xkcoding/springbootdemotemplatefreemarker/SpringBootDemoTemplateFreemarkerApplication.java deleted file mode 100644 index 4cab05b..0000000 --- a/spring-boot-demo-template-freemarker/src/main/java/com/xkcoding/springbootdemotemplatefreemarker/SpringBootDemoTemplateFreemarkerApplication.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.xkcoding.springbootdemotemplatefreemarker; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.servlet.ModelAndView; - -@Controller -@SpringBootApplication -public class SpringBootDemoTemplateFreemarkerApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoTemplateFreemarkerApplication.class, args); - } - - @GetMapping({"","/"}) - public ModelAndView home(){ - return new ModelAndView("index"); - } -} diff --git a/spring-boot-demo-template-freemarker/src/main/java/com/xkcoding/springbootdemotemplatefreemarker/controller/UserController.java b/spring-boot-demo-template-freemarker/src/main/java/com/xkcoding/springbootdemotemplatefreemarker/controller/UserController.java deleted file mode 100644 index 46cafa6..0000000 --- a/spring-boot-demo-template-freemarker/src/main/java/com/xkcoding/springbootdemotemplatefreemarker/controller/UserController.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.xkcoding.springbootdemotemplatefreemarker.controller; - -import com.xkcoding.springbootdemotemplatefreemarker.domain.User; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; - -/** - * 用户 Controller - * - * @package: com.xkcoding.springbootdemotemplatefreemarker.controller - * @description: 用户 Controller - * @author: yangkai.shen - * @date: Created in 2017/11/26 下午6:47 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Controller -@RequestMapping("/user") -@Slf4j -public class UserController { - - @PostMapping("/login") - public ModelAndView login(User user, HttpServletRequest request) { - ModelAndView mv = new ModelAndView(); - - mv.addObject(user); - mv.setViewName("home"); - - request.getSession().setAttribute("user", user); - return mv; - } - - @GetMapping("/login") - public ModelAndView login(HttpServletRequest request) { - ModelAndView mv = new ModelAndView(); - - User user = (User) request.getSession().getAttribute("user"); - if (user == null) { - mv.setViewName("redirect:/"); - } else { - mv.setViewName("home"); - } - - return mv; - } -} diff --git a/spring-boot-demo-template-freemarker/src/main/java/com/xkcoding/springbootdemotemplatefreemarker/domain/User.java b/spring-boot-demo-template-freemarker/src/main/java/com/xkcoding/springbootdemotemplatefreemarker/domain/User.java deleted file mode 100644 index 8480d96..0000000 --- a/spring-boot-demo-template-freemarker/src/main/java/com/xkcoding/springbootdemotemplatefreemarker/domain/User.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.xkcoding.springbootdemotemplatefreemarker.domain; - -import lombok.Data; - -import java.io.Serializable; - -/** - * 用户实体类 - * - * @package: com.xkcoding.springbootdemotemplatefreemarker - * @description: 用户实体类 - * @author: yangkai.shen - * @date: Created in 2017/11/26 下午6:50 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Data -public class User implements Serializable { - private String name; - private String password; -} diff --git a/spring-boot-demo-template-freemarker/src/main/resources/application.yml b/spring-boot-demo-template-freemarker/src/main/resources/application.yml deleted file mode 100644 index 3cae10b..0000000 --- a/spring-boot-demo-template-freemarker/src/main/resources/application.yml +++ /dev/null @@ -1,3 +0,0 @@ -server: - port: 8080 - context-path: /demo \ No newline at end of file diff --git a/spring-boot-demo-template-freemarker/src/main/resources/templates/common/header.ftl b/spring-boot-demo-template-freemarker/src/main/resources/templates/common/header.ftl deleted file mode 100644 index 9a9b873..0000000 --- a/spring-boot-demo-template-freemarker/src/main/resources/templates/common/header.ftl +++ /dev/null @@ -1,7 +0,0 @@ - - - - - spring-boot-demo-template-thymeleaf - \ No newline at end of file diff --git a/spring-boot-demo-template-freemarker/src/main/resources/templates/home.ftl b/spring-boot-demo-template-freemarker/src/main/resources/templates/home.ftl deleted file mode 100644 index 47f2033..0000000 --- a/spring-boot-demo-template-freemarker/src/main/resources/templates/home.ftl +++ /dev/null @@ -1,9 +0,0 @@ - - -<#include "./common/header.ftl"> - -
- 欢迎登录,${user.name}! -
- - \ No newline at end of file diff --git a/spring-boot-demo-template-freemarker/src/main/resources/templates/index.ftl b/spring-boot-demo-template-freemarker/src/main/resources/templates/index.ftl deleted file mode 100644 index 8dc90bd..0000000 --- a/spring-boot-demo-template-freemarker/src/main/resources/templates/index.ftl +++ /dev/null @@ -1,14 +0,0 @@ - - -<#include "./common/header.ftl"> - -
-
- 用户名 - 密码 - -
-
- - - \ No newline at end of file diff --git a/spring-boot-demo-template-freemarker/src/test/java/com/xkcoding/springbootdemotemplatefreemarker/SpringBootDemoTemplateFreemarkerApplicationTests.java b/spring-boot-demo-template-freemarker/src/test/java/com/xkcoding/springbootdemotemplatefreemarker/SpringBootDemoTemplateFreemarkerApplicationTests.java deleted file mode 100644 index 3fbb5af..0000000 --- a/spring-boot-demo-template-freemarker/src/test/java/com/xkcoding/springbootdemotemplatefreemarker/SpringBootDemoTemplateFreemarkerApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemotemplatefreemarker; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoTemplateFreemarkerApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-template-thymeleaf/README.md b/spring-boot-demo-template-thymeleaf/README.md deleted file mode 100644 index 36ae7a7..0000000 --- a/spring-boot-demo-template-thymeleaf/README.md +++ /dev/null @@ -1,100 +0,0 @@ -# spring-boot-demo-template-thymeleaf -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent)、`spring-boot-starter-thymeleaf` - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-template-thymeleaf - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-template-thymeleaf - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - - - spring-boot-demo-template-thymeleaf - - - -``` - -### application.yml - -```yaml -server: - port: 8080 - context-path: /demo -spring: - thymeleaf: - mode: HTML5 - encoding: UTF-8 - content-type: text/html - cache: false -``` - -### SpringBootDemoTemplateThymeleafApplication.java - -```java -@SpringBootApplication -@Controller -public class SpringBootDemoTemplateThymeleafApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoTemplateThymeleafApplication.class, args); - } - - @GetMapping({"", "/"}) - public ModelAndView index(@RequestParam(defaultValue = "thymeleaf") String name) { - ModelAndView mv = new ModelAndView(); - mv.addObject("name", name); - mv.setViewName("index"); - return mv; - } -} -``` - -### index.html - -```html - - - - - spring-boot-demo-template-thymeleaf - - - - - -``` - -### 测试 - -浏览器分别输入: - -http://localhost:8080/demo → Hello,thymeleaf! - -http://localhost:8080/demo?name=xkcoding → Hello,xkcoding! - -### Thymeleaf 语法 - -待补充。。。 \ No newline at end of file diff --git a/spring-boot-demo-template-thymeleaf/pom.xml b/spring-boot-demo-template-thymeleaf/pom.xml deleted file mode 100644 index d8f565f..0000000 --- a/spring-boot-demo-template-thymeleaf/pom.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-template-thymeleaf - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-template-thymeleaf - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - - - spring-boot-demo-template-thymeleaf - - - \ No newline at end of file diff --git a/spring-boot-demo-template-thymeleaf/src/main/java/com/xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplication.java b/spring-boot-demo-template-thymeleaf/src/main/java/com/xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplication.java deleted file mode 100644 index 465f589..0000000 --- a/spring-boot-demo-template-thymeleaf/src/main/java/com/xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplication.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.xkcoding.springbootdemotemplatethymeleaf; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.servlet.ModelAndView; - -@SpringBootApplication -@Controller -public class SpringBootDemoTemplateThymeleafApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoTemplateThymeleafApplication.class, args); - } - - @GetMapping({"", "/"}) - public ModelAndView index(@RequestParam(defaultValue = "thymeleaf") String name) { - ModelAndView mv = new ModelAndView(); - mv.addObject("name", name); - mv.setViewName("index"); - return mv; - } -} diff --git a/spring-boot-demo-template-thymeleaf/src/main/resources/application.yml b/spring-boot-demo-template-thymeleaf/src/main/resources/application.yml deleted file mode 100644 index 9b72a64..0000000 --- a/spring-boot-demo-template-thymeleaf/src/main/resources/application.yml +++ /dev/null @@ -1,9 +0,0 @@ -server: - port: 8080 - context-path: /demo -spring: - thymeleaf: - mode: HTML5 - encoding: UTF-8 - content-type: text/html - cache: false \ No newline at end of file diff --git a/spring-boot-demo-template-thymeleaf/src/main/resources/templates/index.html b/spring-boot-demo-template-thymeleaf/src/main/resources/templates/index.html deleted file mode 100644 index 34cee6c..0000000 --- a/spring-boot-demo-template-thymeleaf/src/main/resources/templates/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - spring-boot-demo-template-thymeleaf - - - - - \ No newline at end of file diff --git a/spring-boot-demo-template-thymeleaf/src/test/java/com/xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplicationTests.java b/spring-boot-demo-template-thymeleaf/src/test/java/com/xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplicationTests.java deleted file mode 100644 index 35a0125..0000000 --- a/spring-boot-demo-template-thymeleaf/src/test/java/com/xkcoding/springbootdemotemplatethymeleaf/SpringBootDemoTemplateThymeleafApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemotemplatethymeleaf; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoTemplateThymeleafApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-ureport2/README.md b/spring-boot-demo-ureport2/README.md deleted file mode 100644 index 64a166a..0000000 --- a/spring-boot-demo-ureport2/README.md +++ /dev/null @@ -1,102 +0,0 @@ -# spring-boot-demo-ureport2 - -依赖 [spring-boot-demo-parent](../spring-boot-demo-parent)、[ureport2](https://github.com/youseries/ureport) (ureport2 可以轻松实现复杂的中国式报表,功能十分强大) - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-ureport2 - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-ureport2 - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - 2.2 - - - - - com.bstek.ureport - ureport2-console - ${ureport2.version} - - - - - spring-boot-demo-ureport2 - - - -``` - -### UReportConfiguration.java - -```java -@Configuration -@ImportResource("classpath:ureport-context.xml") -public class UReportConfiguration { - - @Bean - public ServletRegistrationBean initUReport() { - return new ServletRegistrationBean(new UReportServlet(), "/ureport/*"); - } -} -``` - -### ureport-context.xml - -```xml - - - - - - - - classpath:ureport-config.properties - - - -``` - -### ureport-config.properties - -```properties -# 配置模板存放的位置 -ureport.fileStoreDir=/Users/yangkai.shen/Documents/code/back-end/spring-boot-demo/spring-boot-demo-ureport2/src/main/resources/ureportfiles -``` - -### resources目录 - -``` -resources -├── application.yml···························spring boot 配置文件 -├── export····································运行 demo 示例后,导出的文件 -│   ├── ureport.docx··························导出的 word 文件 -│   ├── ureport.pdf···························导出的 PDF 文件 -│   └── ureport.xlsx··························导出的 Excel 文件 -├── ureport-config.properties·················ureport2 自定义的一些配置信息,比如模板存放路径 -├── ureport-context.xml·······················ureport2 的配置文件 -└── ureportfiles······························用于存放 ureport2 的模板文件 - └── ureport-demo.ureport.xml··············demo 示例的模板文件 -``` - -### 访问 - - 报表设计器 http://localhost:8080/demo/ureport/designer \ No newline at end of file diff --git a/spring-boot-demo-ureport2/pom.xml b/spring-boot-demo-ureport2/pom.xml deleted file mode 100644 index 9a9aeba..0000000 --- a/spring-boot-demo-ureport2/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-ureport2 - 0.0.1-SNAPSHOT - jar - - spring-boot-demo-ureport2 - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - 2.2 - - - - - com.bstek.ureport - ureport2-console - ${ureport2.version} - - - - - spring-boot-demo-ureport2 - - - \ No newline at end of file diff --git a/spring-boot-demo-ureport2/src/main/java/com/xkcoding/springbootdemoureport2/SpringBootDemoUreport2Application.java b/spring-boot-demo-ureport2/src/main/java/com/xkcoding/springbootdemoureport2/SpringBootDemoUreport2Application.java deleted file mode 100644 index 5551812..0000000 --- a/spring-boot-demo-ureport2/src/main/java/com/xkcoding/springbootdemoureport2/SpringBootDemoUreport2Application.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.xkcoding.springbootdemoureport2; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringBootDemoUreport2Application { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoUreport2Application.class, args); - } -} diff --git a/spring-boot-demo-ureport2/src/main/java/com/xkcoding/springbootdemoureport2/configuration/UReportConfiguration.java b/spring-boot-demo-ureport2/src/main/java/com/xkcoding/springbootdemoureport2/configuration/UReportConfiguration.java deleted file mode 100644 index c985ac8..0000000 --- a/spring-boot-demo-ureport2/src/main/java/com/xkcoding/springbootdemoureport2/configuration/UReportConfiguration.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.xkcoding.springbootdemoureport2.configuration; - -import com.bstek.ureport.console.UReportServlet; -import org.springframework.boot.web.servlet.ServletRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; - -@Configuration -@ImportResource("classpath:ureport-context.xml") -public class UReportConfiguration { - - @Bean - public ServletRegistrationBean initUReport() { - return new ServletRegistrationBean(new UReportServlet(), "/ureport/*"); - } -} diff --git a/spring-boot-demo-ureport2/src/main/resources/application.yml b/spring-boot-demo-ureport2/src/main/resources/application.yml deleted file mode 100644 index 3cae10b..0000000 --- a/spring-boot-demo-ureport2/src/main/resources/application.yml +++ /dev/null @@ -1,3 +0,0 @@ -server: - port: 8080 - context-path: /demo \ No newline at end of file diff --git a/spring-boot-demo-ureport2/src/main/resources/export/ureport.docx b/spring-boot-demo-ureport2/src/main/resources/export/ureport.docx deleted file mode 100644 index 3f56419..0000000 Binary files a/spring-boot-demo-ureport2/src/main/resources/export/ureport.docx and /dev/null differ diff --git a/spring-boot-demo-ureport2/src/main/resources/export/ureport.pdf b/spring-boot-demo-ureport2/src/main/resources/export/ureport.pdf deleted file mode 100644 index 025c436..0000000 Binary files a/spring-boot-demo-ureport2/src/main/resources/export/ureport.pdf and /dev/null differ diff --git a/spring-boot-demo-ureport2/src/main/resources/export/ureport.xlsx b/spring-boot-demo-ureport2/src/main/resources/export/ureport.xlsx deleted file mode 100644 index 4d5da3b..0000000 Binary files a/spring-boot-demo-ureport2/src/main/resources/export/ureport.xlsx and /dev/null differ diff --git a/spring-boot-demo-ureport2/src/main/resources/ureport-config.properties b/spring-boot-demo-ureport2/src/main/resources/ureport-config.properties deleted file mode 100644 index 956cbfa..0000000 --- a/spring-boot-demo-ureport2/src/main/resources/ureport-config.properties +++ /dev/null @@ -1,2 +0,0 @@ -# 配置模板存放的位置 -ureport.fileStoreDir=/Users/yangkai.shen/Documents/code/back-end/spring-boot-demo/spring-boot-demo-ureport2/src/main/resources/ureportfiles \ No newline at end of file diff --git a/spring-boot-demo-ureport2/src/main/resources/ureport-context.xml b/spring-boot-demo-ureport2/src/main/resources/ureport-context.xml deleted file mode 100644 index 04da7bd..0000000 --- a/spring-boot-demo-ureport2/src/main/resources/ureport-context.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - classpath:ureport-config.properties - - - \ No newline at end of file diff --git a/spring-boot-demo-ureport2/src/main/resources/ureportfiles/ureport-demo.ureport.xml b/spring-boot-demo-ureport2/src/main/resources/ureportfiles/ureport-demo.ureport.xml deleted file mode 100644 index f36e1ee..0000000 --- a/spring-boot-demo-ureport2/src/main/resources/ureportfiles/ureport-demo.ureport.xml +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/spring-boot-demo-ureport2/src/test/java/com/xkcoding/springbootdemoureport2/SpringBootDemoUreport2ApplicationTests.java b/spring-boot-demo-ureport2/src/test/java/com/xkcoding/springbootdemoureport2/SpringBootDemoUreport2ApplicationTests.java deleted file mode 100644 index 67839c0..0000000 --- a/spring-boot-demo-ureport2/src/test/java/com/xkcoding/springbootdemoureport2/SpringBootDemoUreport2ApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemoureport2; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoUreport2ApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-demo-util/pom.xml b/spring-boot-demo-util/pom.xml deleted file mode 100644 index e7b6ffa..0000000 --- a/spring-boot-demo-util/pom.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - 4.0.0 - - com.xkcoding - spring-boot-demo-util - 0.0.1-SNAPSHOT - jar - - - - com.xiaoleilu - hutool-all - 3.2.0 - - - com.google.guava - guava - 20.0 - - - org.projectlombok - lombok - 1.16.18 - - - - - spring-boot-demo-util - - - \ No newline at end of file diff --git a/spring-boot-demo-util/src/main/java/com/xkcoding/util/PingyinUtil.java b/spring-boot-demo-util/src/main/java/com/xkcoding/util/PingyinUtil.java deleted file mode 100644 index fa2ffac..0000000 --- a/spring-boot-demo-util/src/main/java/com/xkcoding/util/PingyinUtil.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.xkcoding.util; - -import java.util.Random; - -/** - *

- * 得到中文首字母 - *

- * - * @package: com.xkcoding.util - * @description: 得到中文首字母 - * @author: yangkai.shen - * @date: Created in 2017/12/1 下午3:52 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -public class PingyinUtil { - public static void main(String[] args) { - String str = "我是一串中文"; - System.out.println("我是一串中文:" + getPYIndexStr(str, true)); - } - - /** - * 返回首字母 - * - * @param strChinese 中文字符串 - * @param bUpCase 是否为大写 - * @return 中文字符串的首字母 - */ - public static String getPYIndexStr(String strChinese, boolean bUpCase) { - try { - StringBuffer buffer = new StringBuffer(); - // 把中文转化成byte数组 - byte b[] = strChinese.getBytes("GBK"); - for (int i = 0; i < b.length; i++) { - if ((b[i] & 255) > 128) { - int char1 = b[i++] & 255; - // 左移运算符用“<<”表示,是将运算符左边的对象,向左移动运算符右边指定的位数,并且在低位补零。其实,向左移n位,就相当于乘上2的n次方 - char1 <<= 8; - int chart = char1 + (b[i] & 255); - buffer.append(getPYIndexChar((char) chart, bUpCase)); - continue; - } - char c = (char) b[i]; - // 确定指定字符是否可以是 Java - if (!Character.isJavaIdentifierPart(c)) { - // 标识符中首字符以外的部分。 - c = 'A'; - } - buffer.append(c); - } - return buffer.toString(); - } catch (Exception e) { - System.out.println((new StringBuilder()).append("\u53D6\u4E2D\u6587\u62FC\u97F3\u6709\u9519").append(e.getMessage()).toString()); - } - return null; - } - - /** - * 得到首字母 - * - * @param strChinese 中文字符 - * @param bUpCase 是否大写 - * @return 中文字符的首字母 - */ - private static char getPYIndexChar(char strChinese, boolean bUpCase) { - - int charGBK = strChinese; - - char result; - - if (charGBK >= 45217 && charGBK <= 45252) { - result = 'A'; - } else if (charGBK >= 45253 && charGBK <= 45760) { - result = 'B'; - } else if (charGBK >= 45761 && charGBK <= 46317) { - result = 'C'; - } else if (charGBK >= 46318 && charGBK <= 46825) { - result = 'D'; - } else if (charGBK >= 46826 && charGBK <= 47009) { - result = 'E'; - } else if (charGBK >= 47010 && charGBK <= 47296) { - result = 'F'; - } else if (charGBK >= 47297 && charGBK <= 47613) { - result = 'G'; - } else if (charGBK >= 47614 && charGBK <= 48118) { - result = 'H'; - } else if (charGBK >= 48119 && charGBK <= 49061) { - result = 'J'; - } else if (charGBK >= 49062 && charGBK <= 49323) { - result = 'K'; - } else if (charGBK >= 49324 && charGBK <= 49895) { - result = 'L'; - } else if (charGBK >= 49896 && charGBK <= 50370) { - result = 'M'; - } else if (charGBK >= 50371 && charGBK <= 50613) { - result = 'N'; - } else if (charGBK >= 50614 && charGBK <= 50621) { - result = 'O'; - } else if (charGBK >= 50622 && charGBK <= 50905) { - result = 'P'; - } else if (charGBK >= 50906 && charGBK <= 51386) { - result = 'Q'; - } else if (charGBK >= 51387 && charGBK <= 51445) { - result = 'R'; - } else if (charGBK >= 51446 && charGBK <= 52217) { - result = 'S'; - } else if (charGBK >= 52218 && charGBK <= 52697) { - result = 'T'; - } else if (charGBK >= 52698 && charGBK <= 52979) { - result = 'W'; - } else if (charGBK >= 52980 && charGBK <= 53688) { - result = 'X'; - } else if (charGBK >= 53689 && charGBK <= 54480) { - result = 'Y'; - } else if (charGBK >= 54481 && charGBK <= 55289) { - result = 'Z'; - } else { - result = (char) (65 + (new Random()).nextInt(25)); - } - if (!bUpCase) { - result = Character.toLowerCase(result); - } - return result; - } -} diff --git a/spring-boot-demo-util/src/main/java/com/xkcoding/util/T.java b/spring-boot-demo-util/src/main/java/com/xkcoding/util/T.java deleted file mode 100644 index 95d783b..0000000 --- a/spring-boot-demo-util/src/main/java/com/xkcoding/util/T.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.xkcoding.util; - -import com.google.common.collect.Maps; -import com.sun.istack.internal.NotNull; -import com.xiaoleilu.hutool.http.HttpUtil; -import com.xiaoleilu.hutool.json.JSONObject; -import com.xiaoleilu.hutool.json.JSONUtil; -import com.xiaoleilu.hutool.util.RandomUtil; -import com.xiaoleilu.hutool.util.StrUtil; -import com.xkcoding.util.domain.ShortUrlRet; - -import java.util.Map; - -/** - *

- * 高频工具类 - *

- * - * @package: com.xkcoding.util - * @description: 高频工具类 - * @author: yangkai.shen - * @date: Created in 2017/12/1 下午4:24 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -public class T { - private static final String URL_SEPARATOR = "//"; - private static final String URL_PROTOCOL = "http"; - - /** - * 获取 UUID - * - * @return 返回没有“-”的 UUID - */ - public static String UUID() { - return RandomUtil.randomUUID().replace("-", ""); - } - - /** - * 长地址转短地址 - * - * @param longUrl 长地址 - * @return 长地址转化后的短地址 - */ - public static String shortURL(@NotNull String longUrl) { - Map params = Maps.newHashMap(); - if (StrUtil.isEmpty(longUrl)) { - return null; - } - if (!longUrl.contains(URL_SEPARATOR)) { - longUrl = URL_PROTOCOL + ":" + URL_SEPARATOR + longUrl; - } - params.put("url", longUrl); - params.put("email", "ws@parg.co"); - params.put("api_key", "4786a32f20f79a70b1ced1bf242a120e"); - String data = HttpUtil.post("https://parg.co/api/shorten", params); - JSONObject ret = JSONUtil.parseObj(data); - ShortUrlRet shortUrlRet = ret.toBean(ShortUrlRet.class); - return shortUrlRet.getShort_url(); - } - -} diff --git a/spring-boot-demo-util/src/main/java/com/xkcoding/util/TreeUtil.java b/spring-boot-demo-util/src/main/java/com/xkcoding/util/TreeUtil.java deleted file mode 100644 index ea428f6..0000000 --- a/spring-boot-demo-util/src/main/java/com/xkcoding/util/TreeUtil.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.xkcoding.util; - -import com.google.common.collect.Lists; -import com.xiaoleilu.hutool.json.JSONUtil; -import com.xkcoding.util.domain.TreeNode; - -import java.util.Iterator; -import java.util.List; - -/** - *

- * 把一个list集合,里面的bean含有 parentId 转为树形式 - *

- * - * @package: com.xkcoding.util - * @description: 把一个list集合, 里面的bean含有 parentId 转为树形式 - * @author: yangkai.shen - * @date: Created in 2017/12/7 上午10:26 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -public class TreeUtil { - - /** - * 测试层级 - * - * @param args - */ - public static void main(String[] args) { - long start = System.currentTimeMillis(); - - List treeObjectList = Lists.newArrayList(); - - treeObjectList.add(new TreeNode(1, "总部", 0, "0", 1, "总部", Lists.newArrayList())); - treeObjectList.add(new TreeNode(2, "技术部", 1, "0,1", 1, "技术部", Lists.newArrayList())); - treeObjectList.add(new TreeNode(3, "软件部", 2, "0,1,2", 1, "软件部", Lists.newArrayList())); - treeObjectList.add(new TreeNode(4, "硬件部", 2, "0,1,2", 2, "硬件部", Lists.newArrayList())); - treeObjectList.add(new TreeNode(5, "维修部", 4, "0,1,2,4", 1, "维修部", Lists.newArrayList())); - treeObjectList.add(new TreeNode(6, "采购部", 4, "0,1,2,4", 2, "采购部", Lists.newArrayList())); - - TreeUtil mt = new TreeUtil(); - - List ns = mt.getChildTreeNodes(treeObjectList, 0); - - for (TreeNode m : ns) { - System.out.println(m); - System.out.println(JSONUtil.parseObj(m, false).toStringPretty()); - } - - long end = System.currentTimeMillis(); - - System.out.println("用时:" + (end - start) + "ms"); - } - - /** - * 根据父节点 id 获取所有子节点 - * - * @param list 列表 - * @param parentId 父节点 id - * @return 所有子节点 - */ - public List getChildTreeNodes(List list, Integer parentId) { - List returnList = Lists.newArrayList(); - for (Iterator iterator = list.iterator(); iterator.hasNext(); ) { - TreeNode t = iterator.next(); - // 一、根据传入的某个父节点ID,遍历该父节点的所有子节点 - if (t.getParentId().equals(parentId)) { - recursionFn(list, t); - returnList.add(t); - } - } - return returnList; - } - - /** - * 递归列表 - * - * @param list 列表 - * @param t 树节点 - */ - private void recursionFn(List list, TreeNode t) { - // 得到子节点列表 - List childList = getChildList(list, t); - - t.setChildren(childList); - for (TreeNode tChild : childList) { - // 判断是否有子节点 - if (hasChild(list, tChild)) { - Iterator it = childList.iterator(); - while (it.hasNext()) { - TreeNode n = it.next(); - recursionFn(list, n); - } - } - } - } - - /** - * 判断是否存在子节点 - * - * @param list - * @param tChild - * @return - */ - private boolean hasChild(List list, TreeNode tChild) { - return getChildList(list, tChild).size() > 0; - } - - /** - * 获得子节点列表 - * - * @param list - * @param t - * @return - */ - private List getChildList(List list, TreeNode t) { - List tlist = Lists.newArrayList(); - Iterator it = list.iterator(); - while (it.hasNext()) { - TreeNode n = it.next(); - if (n.getParentId().equals(t.getId())) { - tlist.add(n); - } - } - return tlist; - } - -} diff --git a/spring-boot-demo-util/src/main/java/com/xkcoding/util/domain/ShortUrlRet.java b/spring-boot-demo-util/src/main/java/com/xkcoding/util/domain/ShortUrlRet.java deleted file mode 100644 index 2f2dd37..0000000 --- a/spring-boot-demo-util/src/main/java/com/xkcoding/util/domain/ShortUrlRet.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.xkcoding.util.domain; - -import lombok.Data; - -/** - *

- * 短地址请求返回类型 - *

- * - * @package: com.xkcoding.util.domain - * @description: 短地址请求返回类型 - * @author: yangkai.shen - * @date: Created in 2017/12/4 上午11:29 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Data -public class ShortUrlRet { - private String short_url; - private String long_encoded; - private String long_decoded; - private String status; -} diff --git a/spring-boot-demo-util/src/main/java/com/xkcoding/util/domain/TreeNode.java b/spring-boot-demo-util/src/main/java/com/xkcoding/util/domain/TreeNode.java deleted file mode 100644 index 7d6c969..0000000 --- a/spring-boot-demo-util/src/main/java/com/xkcoding/util/domain/TreeNode.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.xkcoding.util.domain; - -import com.google.common.collect.Lists; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; - -/** - *

- * 树节点 - *

- * - * @package: com.xkcoding.util.domain - * @description: 树节点 - * @author: yangkai.shen - * @date: Created in 2017/12/7 上午10:27 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class TreeNode { - /** - * id 编号 - */ - private Integer id; - /** - * 节点名称 - */ - private String name; - /** - * 父节点 id - */ - private Integer parentId; - /** - * 层级 - */ - private String level; - /** - * 当前层级顺序 - */ - private Integer seq; - /** - * 备注 - */ - private String remark; - /** - * 子节点列表 - */ - private List children = Lists.newArrayList(); -} diff --git a/spring-boot-demo-war/README.md b/spring-boot-demo-war/README.md deleted file mode 100644 index 001e0c1..0000000 --- a/spring-boot-demo-war/README.md +++ /dev/null @@ -1,67 +0,0 @@ -# spring-boot-demo-war - -依赖[spring-boot-demo-parent](../spring-boot-demo-parent)、`spring-boot-starter-tomcat` - -### pom.xml - -```xml - - - 4.0.0 - - spring-boot-demo-war - 0.0.1-SNAPSHOT - - war - - spring-boot-demo-war - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - - - org.springframework.boot - spring-boot-starter-tomcat - provided - - - - - spring-boot-demo-war - - - -``` - -### ServletInitializer.java - -```java -/** - * 新建一个 ServletInitializer 类,继承 SpringBootServletInitializer - *

打成 war 包修改的第 ③ 处

- * @package: com.xkcoding.springbootdemowar - * @description: 新建一个 ServletInitializer 类,继承 SpringBootServletInitializer - * @author: yangkai.shen - * @date: Created in 2017/11/30 下午1:26 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -public class ServletInitializer extends SpringBootServletInitializer { - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SpringBootDemoWarApplication.class); - } - -} -``` \ No newline at end of file diff --git a/spring-boot-demo-war/pom.xml b/spring-boot-demo-war/pom.xml deleted file mode 100644 index 3fd916e..0000000 --- a/spring-boot-demo-war/pom.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - 4.0.0 - - spring-boot-demo-war - 0.0.1-SNAPSHOT - - war - - spring-boot-demo-war - Demo project for Spring Boot - - - com.xkcoding - spring-boot-demo-parent - 0.0.1-SNAPSHOT - ../spring-boot-demo-parent/pom.xml - - - - - - - org.springframework.boot - spring-boot-starter-tomcat - provided - - - - - spring-boot-demo-war - - - \ No newline at end of file diff --git a/spring-boot-demo-war/src/main/java/com/xkcoding/springbootdemowar/ServletInitializer.java b/spring-boot-demo-war/src/main/java/com/xkcoding/springbootdemowar/ServletInitializer.java deleted file mode 100644 index c8dd840..0000000 --- a/spring-boot-demo-war/src/main/java/com/xkcoding/springbootdemowar/ServletInitializer.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.xkcoding.springbootdemowar; - -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.support.SpringBootServletInitializer; - -/** - * 新建一个 ServletInitializer 类,继承 SpringBootServletInitializer - *

打成 war 包修改的第 ③ 处

- * @package: com.xkcoding.springbootdemowar - * @description: 新建一个 ServletInitializer 类,继承 SpringBootServletInitializer - * @author: yangkai.shen - * @date: Created in 2017/11/30 下午1:26 - * @copyright: Copyright (c) 2017 - * @version: 0.0.1 - * @modified: yangkai.shen - */ -public class ServletInitializer extends SpringBootServletInitializer { - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SpringBootDemoWarApplication.class); - } - -} diff --git a/spring-boot-demo-war/src/main/java/com/xkcoding/springbootdemowar/SpringBootDemoWarApplication.java b/spring-boot-demo-war/src/main/java/com/xkcoding/springbootdemowar/SpringBootDemoWarApplication.java deleted file mode 100644 index 8d51f05..0000000 --- a/spring-boot-demo-war/src/main/java/com/xkcoding/springbootdemowar/SpringBootDemoWarApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.xkcoding.springbootdemowar; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringBootDemoWarApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootDemoWarApplication.class, args); - } -} diff --git a/spring-boot-demo-war/src/main/resources/application.yml b/spring-boot-demo-war/src/main/resources/application.yml deleted file mode 100644 index 3cae10b..0000000 --- a/spring-boot-demo-war/src/main/resources/application.yml +++ /dev/null @@ -1,3 +0,0 @@ -server: - port: 8080 - context-path: /demo \ No newline at end of file diff --git a/spring-boot-demo-war/src/test/java/com/xkcoding/springbootdemowar/SpringBootDemoWarApplicationTests.java b/spring-boot-demo-war/src/test/java/com/xkcoding/springbootdemowar/SpringBootDemoWarApplicationTests.java deleted file mode 100644 index 8c0fec2..0000000 --- a/spring-boot-demo-war/src/test/java/com/xkcoding/springbootdemowar/SpringBootDemoWarApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.xkcoding.springbootdemowar; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootDemoWarApplicationTests { - - @Test - public void contextLoads() { - } - -}