├── src
├── main
│ ├── resources
│ │ ├── application-prod.properties
│ │ ├── application-test.properties
│ │ ├── banner.txt
│ │ ├── application.properties
│ │ ├── application-dev.yml
│ │ └── mapper
│ │ │ └── TUserMapper.xml
│ └── java
│ │ └── com
│ │ └── company
│ │ └── project
│ │ ├── core
│ │ ├── ServiceException.java
│ │ ├── MybatisPlusConfig.java
│ │ ├── ProjectConstant.java
│ │ ├── MessageResultUtils.java
│ │ ├── Query.java
│ │ └── CodeMsgEnum.java
│ │ ├── Application.java
│ │ └── configurer
│ │ ├── MybatisConfigurer.java
│ │ ├── Swagger2Configurer.java
│ │ └── WebConfigurer.java
└── test
│ ├── resources
│ ├── generator
│ │ └── template
│ │ │ ├── service.ftl
│ │ │ ├── service-impl.ftl
│ │ │ ├── controller.ftl
│ │ │ └── controller-restful.ftl
│ └── demo-user.sql
│ └── java
│ ├── com
│ └── company
│ │ └── project
│ │ ├── Tester.java
│ │ └── GeneratorSwagger2Model.java
│ └── CodeGenerator.java
├── spring-cloud-learning-01
├── jf-mybatis
│ ├── src
│ │ ├── main
│ │ │ ├── resources
│ │ │ │ ├── application.properties
│ │ │ │ ├── application-dev.yml
│ │ │ │ └── mapper
│ │ │ │ │ └── TUserMapper.xml
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── demo
│ │ │ │ ├── core
│ │ │ │ ├── ServiceException.java
│ │ │ │ ├── MybatisPlusConfig.java
│ │ │ │ ├── ProjectConstant.java
│ │ │ │ ├── MessageResultUtils.java
│ │ │ │ ├── Query.java
│ │ │ │ └── CodeMsgEnum.java
│ │ │ │ ├── JfMybatisApplication.java
│ │ │ │ └── configurer
│ │ │ │ ├── MybatisConfigurer.java
│ │ │ │ ├── Swagger2Configurer.java
│ │ │ │ └── WebConfigurer.java
│ │ └── test
│ │ │ ├── resources
│ │ │ ├── generator
│ │ │ │ └── template
│ │ │ │ │ ├── service.ftl
│ │ │ │ │ ├── service-impl.ftl
│ │ │ │ │ ├── controller.ftl
│ │ │ │ │ └── controller-restful.ftl
│ │ │ └── demo-user.sql
│ │ │ └── java
│ │ │ ├── com
│ │ │ └── demo
│ │ │ │ └── GeneratorSwagger2Model.java
│ │ │ └── CodeGenerator.java
│ └── pom.xml
├── jf-client01
│ ├── src
│ │ └── main
│ │ │ ├── resources
│ │ │ └── application.yml
│ │ │ └── java
│ │ │ └── com
│ │ │ └── demo
│ │ │ └── JfClient01Application.java
│ └── pom.xml
├── jf-server
│ ├── src
│ │ └── main
│ │ │ ├── resources
│ │ │ └── application.yml
│ │ │ └── java
│ │ │ └── com
│ │ │ └── demo
│ │ │ └── EurekaServerApplication.java
│ └── pom.xml
├── pom.xml
└── log
│ └── learing-test.log
├── .gitignore
├── README.md
└── pom.xml
/src/main/resources/application-prod.properties:
--------------------------------------------------------------------------------
1 | # 生产环境配置
2 |
--------------------------------------------------------------------------------
/src/main/resources/application-test.properties:
--------------------------------------------------------------------------------
1 | # 测试环境配置
2 |
--------------------------------------------------------------------------------
/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | ////////////////////////////////////////////////////////////////////
2 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.profiles.active=dev
2 | # 所有环境通用的配置,放在这里
3 |
4 | # 404 交给异常处理器处理
5 | spring.mvc.throw-exception-if-no-handler-found=true
6 | spring.resources.add-mappings=false
7 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-mybatis/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sjf1256754123/spring-boot-api-mybatis-plus/HEAD/spring-cloud-learning-01/jf-mybatis/src/main/resources/application.properties
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-client01/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8082
3 |
4 | spring:
5 | application:
6 | name: service-client01
7 |
8 | eureka:
9 | client:
10 | serviceUrl:
11 | defaultZone: http://localhost:8081/eureka/
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 |
3 | ### STS ###
4 | .apt_generated
5 | .classpath
6 | .factorypath
7 | .project
8 | .settings
9 | .springBeans
10 |
11 | ### IntelliJ IDEA ###
12 | .idea
13 | *.iws
14 | *.iml
15 | *.ipr
16 |
17 | ### NetBeans ###
18 | nbproject/private/
19 | build/
20 | nbbuild/
21 | dist/
22 | nbdist/
23 | .nb-gradle/
--------------------------------------------------------------------------------
/src/test/resources/generator/template/service.ftl:
--------------------------------------------------------------------------------
1 | package ${basePackage}.service;
2 | import ${basePackage}.model.${modelNameUpperCamel};
3 | import ${basePackage}.core.Service;
4 |
5 |
6 | /**
7 | * @author ${author}
8 | * @data ${date}.
9 | */
10 | public interface ${modelNameUpperCamel}Service extends Service<${modelNameUpperCamel}> {
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-mybatis/src/test/resources/generator/template/service.ftl:
--------------------------------------------------------------------------------
1 | package ${basePackage}.service;
2 | import ${basePackage}.model.${modelNameUpperCamel};
3 | import ${basePackage}.core.Service;
4 |
5 |
6 | /**
7 | * @author ${author}
8 | * @data ${date}.
9 | */
10 | public interface ${modelNameUpperCamel}Service extends Service<${modelNameUpperCamel}> {
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-server/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8081
3 |
4 | eureka:
5 | instance:
6 | hostname: localhost
7 | client:
8 | registerWithEureka: false
9 | fetchRegistry: false
10 | serviceUrl:
11 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
12 |
13 | spring:
14 | application:
15 | name: eurka-server
16 |
17 |
--------------------------------------------------------------------------------
/src/main/java/com/company/project/core/ServiceException.java:
--------------------------------------------------------------------------------
1 | package com.company.project.core;
2 |
3 | /**
4 | * 服务(业务)异常如“ 账号或密码错误 ”,该异常只做INFO级别的日志记录 @see WebMvcConfigurer
5 | */
6 | public class ServiceException extends RuntimeException {
7 | public ServiceException() {
8 | }
9 |
10 | public ServiceException(String message) {
11 | super(message);
12 | }
13 |
14 | public ServiceException(String message, Throwable cause) {
15 | super(message, cause);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-mybatis/src/main/java/com/demo/core/ServiceException.java:
--------------------------------------------------------------------------------
1 | package com.demo.core;
2 |
3 | /**
4 | * 服务(业务)异常如“ 账号或密码错误 ”,该异常只做INFO级别的日志记录 @see WebMvcConfigurer
5 | */
6 | public class ServiceException extends RuntimeException {
7 | public ServiceException() {
8 | }
9 |
10 | public ServiceException(String message) {
11 | super(message);
12 | }
13 |
14 | public ServiceException(String message, Throwable cause) {
15 | super(message, cause);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-client01/src/main/java/com/demo/JfClient01Application.java:
--------------------------------------------------------------------------------
1 | package com.demo;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
6 |
7 | @SpringBootApplication
8 | @EnableEurekaClient
9 | public class JfClient01Application {
10 | public static void main(String[] args) {
11 | SpringApplication.run(JfClient01Application.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-server/src/main/java/com/demo/EurekaServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.demo;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
6 |
7 | @SpringBootApplication
8 | @EnableEurekaServer
9 | public class EurekaServerApplication {
10 | public static void main(String[] args) {
11 | SpringApplication.run(EurekaServerApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/test/java/com/company/project/Tester.java:
--------------------------------------------------------------------------------
1 | package com.company.project;
2 |
3 |
4 | import com.company.project.Application;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.boot.test.context.SpringBootTest;
7 | import org.springframework.test.annotation.Rollback;
8 | import org.springframework.test.context.junit4.SpringRunner;
9 | import org.springframework.transaction.annotation.Transactional;
10 |
11 | /**
12 | * 单元测试继承该类即可
13 | */
14 | @RunWith(SpringRunner.class)
15 | @SpringBootTest(classes = Application.class)
16 | @Transactional
17 | @Rollback
18 | public abstract class Tester {}
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-mybatis/src/main/java/com/demo/JfMybatisApplication.java:
--------------------------------------------------------------------------------
1 | package com.demo;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
6 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
7 |
8 | @SpringBootApplication
9 | @EnableSwagger2
10 | @EnableEurekaClient
11 | public class JfMybatisApplication {
12 | public static void main(String[] args) {
13 | SpringApplication.run(JfMybatisApplication.class, args);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/company/project/Application.java:
--------------------------------------------------------------------------------
1 | package com.company.project;
2 |
3 | import org.mybatis.spring.annotation.MapperScan;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
7 |
8 | /**
9 | * @author Gahon
10 | */
11 | @SpringBootApplication
12 | @EnableSwagger2
13 | //@MapperScan("com.company.project.dao")
14 | public class Application {
15 | public static void main(String[] args) {
16 | SpringApplication.run(Application.class, args);
17 | }
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 9999
3 |
4 | spring:
5 | datasource:
6 | url: jdbc:mysql://localhost:3306/learning_test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&useSSL=false&allowPublicKeyRetrieval=true
7 | username: root
8 | password: 123456
9 |
10 | mybatis-plus:
11 | mapperLocations: classpath:mapper/*Mapper.xml
12 | global-config:
13 | banner: true
14 | db-config:
15 | id-type: auto
16 | tableUnderline: false
17 | # 逻辑已删除值(默认为 1)
18 | logic-delete-value: 1
19 | # 逻辑未删除值(默认为 0)
20 | logic-not-delete-value: 0
21 | configuration:
22 | map-underscore-to-camel-case: false
23 |
24 | logging:
25 | file: log/learning-test.log
26 | level:
27 | com.company.project.dao : debug
28 |
--------------------------------------------------------------------------------
/src/main/java/com/company/project/core/MybatisPlusConfig.java:
--------------------------------------------------------------------------------
1 | package com.company.project.core;
2 |
3 | import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
4 | import org.mybatis.spring.annotation.MapperScan;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | /**
9 | * @author ya
10 | * @date 2018/7/19 20:27
11 | */
12 | @Configuration
13 | @MapperScan("com.xxx.xxx")
14 | public class MybatisPlusConfig {
15 |
16 | /**
17 | * mybatis-plus分页插件
18 | * 文档:http://mp.baomidou.com
19 | */
20 | @Bean
21 | public PaginationInterceptor paginationInterceptor() {
22 | PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
23 | return paginationInterceptor;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/test/resources/generator/template/service-impl.ftl:
--------------------------------------------------------------------------------
1 | package ${basePackage}.service.impl;
2 |
3 | import ${basePackage}.dao.${modelNameUpperCamel}Mapper;
4 | import ${basePackage}.model.${modelNameUpperCamel};
5 | import ${basePackage}.service.${modelNameUpperCamel}Service;
6 | import ${basePackage}.core.AbstractService;
7 | import org.springframework.stereotype.Service;
8 | import org.springframework.transaction.annotation.Transactional;
9 |
10 | import javax.annotation.Resource;
11 |
12 |
13 | /**
14 | * @author ${author}
15 | * @data ${date}.
16 | */
17 | @Service
18 | @Transactional
19 | public class ${modelNameUpperCamel}ServiceImpl extends AbstractService<${modelNameUpperCamel}> implements ${modelNameUpperCamel}Service {
20 | @Resource
21 | private ${modelNameUpperCamel}Mapper ${modelNameLowerCamel}Mapper;
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-mybatis/src/main/java/com/demo/core/MybatisPlusConfig.java:
--------------------------------------------------------------------------------
1 | package com.demo.core;
2 |
3 | import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
4 | import org.mybatis.spring.annotation.MapperScan;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | /**
9 | * @author ya
10 | * @date 2018/7/19 20:27
11 | */
12 | @Configuration
13 | @MapperScan("com.xxx.xxx")
14 | public class MybatisPlusConfig {
15 |
16 | /**
17 | * mybatis-plus分页插件
18 | * 文档:http://mp.baomidou.com
19 | */
20 | @Bean
21 | public PaginationInterceptor paginationInterceptor() {
22 | PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
23 | return paginationInterceptor;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-mybatis/src/main/resources/application-dev.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8083
3 |
4 | spring:
5 | datasource:
6 | url: jdbc:mysql://localhost:3306/learning_test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT&useSSL=false&allowPublicKeyRetrieval=true
7 | username: root
8 | password: 123456
9 | application:
10 | name: service-mybatisPlus
11 |
12 | eureka:
13 | client:
14 | serviceUrl:
15 | defaultZone: http://localhost:8081/eureka/
16 |
17 | mybatis-plus:
18 | mapper-locations: classpath:mapper/*Mapper.xml
19 | global-config:
20 | db-config:
21 | id-type: auto
22 | table-underline: false
23 | logic-delete-value: 1
24 | logic-not-delete-value: 0
25 | configuration:
26 | map-underscore-to-camel-case: false
27 |
28 |
29 | logging:
30 | level:
31 | com.demo.dao: debug
32 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-mybatis/src/test/resources/generator/template/service-impl.ftl:
--------------------------------------------------------------------------------
1 | package ${basePackage}.service.impl;
2 |
3 | import ${basePackage}.dao.${modelNameUpperCamel}Mapper;
4 | import ${basePackage}.model.${modelNameUpperCamel};
5 | import ${basePackage}.service.${modelNameUpperCamel}Service;
6 | import ${basePackage}.core.AbstractService;
7 | import org.springframework.stereotype.Service;
8 | import org.springframework.transaction.annotation.Transactional;
9 |
10 | import javax.annotation.Resource;
11 |
12 |
13 | /**
14 | * @author ${author}
15 | * @data ${date}.
16 | */
17 | @Service
18 | @Transactional
19 | public class ${modelNameUpperCamel}ServiceImpl extends AbstractService<${modelNameUpperCamel}> implements ${modelNameUpperCamel}Service {
20 | @Resource
21 | private ${modelNameUpperCamel}Mapper ${modelNameLowerCamel}Mapper;
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/resources/mapper/TUserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | id, user_name, pass_word, mail, is_del, sasdasdasd
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-mybatis/src/main/resources/mapper/TUserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | id, user_name, pass_word, mail, is_del, sasdasdasd
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | jf.learning
7 | jf.maven
8 | 1.0-SNAPSHOT
9 |
10 |
11 | jf-server
12 | eureka-server
13 | 0.0.1-SNAPSHOT
14 | eureka-server
15 | Demo project for Spring Boot
16 |
17 |
18 |
19 | org.springframework.cloud
20 | spring-cloud-starter-netflix-eureka-server
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-client01/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | jf.learning
7 | jf.maven
8 | 1.0-SNAPSHOT
9 |
10 |
11 | eureka-client01
12 | jf-client01
13 | 0.0.1-SNAPSHOT
14 | jf-client01
15 | Demo project for Spring Boot
16 |
17 |
18 | 1.8
19 | Greenwich.SR1
20 |
21 |
22 |
23 |
24 | org.springframework.cloud
25 | spring-cloud-starter-netflix-eureka-server
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/main/java/com/company/project/core/ProjectConstant.java:
--------------------------------------------------------------------------------
1 | package com.company.project.core;
2 |
3 | /**
4 | * 项目常量
5 | * @author Gahon
6 | */
7 | public final class ProjectConstant {
8 | /**
9 | * 生成代码所在的基础包名称,可根据自己公司的项目修改(注意:这个配置修改之后需要手工修改src目录项目默认的包路径,使其保持一致,不然会找不到类)
10 | **/
11 | public static final String BASE_PACKAGE = "com.company.project";
12 | /**
13 | * 生成的Model所在包
14 | */
15 | public static final String MODEL_PACKAGE = BASE_PACKAGE + ".model";
16 | /**
17 | * 生成的Mapper所在包
18 | */
19 | public static final String MAPPER_PACKAGE = BASE_PACKAGE + ".dao";
20 | /**
21 | * 生成的Service所在包
22 | */
23 | public static final String SERVICE_PACKAGE = BASE_PACKAGE + ".service";
24 | /**
25 | * 生成的ServiceImpl所在包
26 | */
27 | public static final String SERVICE_IMPL_PACKAGE = SERVICE_PACKAGE + ".impl";
28 | /**
29 | * 生成的Controller所在包
30 | */
31 | public static final String CONTROLLER_PACKAGE = BASE_PACKAGE + ".controller";
32 | /**
33 | * Mapper插件基础接口的完全限定名
34 | */
35 | public static final String MAPPER_INTERFACE_REFERENCE = BASE_PACKAGE + ".core.Mapper";
36 | }
37 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-mybatis/src/main/java/com/demo/core/ProjectConstant.java:
--------------------------------------------------------------------------------
1 | package com.demo.core;
2 |
3 | /**
4 | * 项目常量
5 | * @author Gahon
6 | */
7 | public final class ProjectConstant {
8 |
9 | /**
10 | * 项目路径
11 | */
12 | public static final String PROJECT_PATH = "E:/Desktop/spring-cloud-learning-01/jf-mybatis";
13 | /**
14 | * 生成代码所在的基础包名称,可根据自己公司的项目修改(注意:这个配置修改之后需要手工修改src目录项目默认的包路径,使其保持一致,不然会找不到类)
15 | **/
16 | public static final String BASE_PACKAGE = "com.demo";
17 | /**
18 | * 生成的Model所在包
19 | */
20 | public static final String MODEL_PACKAGE = BASE_PACKAGE + ".model";
21 | /**
22 | * 生成的Mapper所在包
23 | */
24 | public static final String MAPPER_PACKAGE = BASE_PACKAGE + ".dao";
25 | /**
26 | * 生成的Service所在包
27 | */
28 | public static final String SERVICE_PACKAGE = BASE_PACKAGE + ".service";
29 | /**
30 | * 生成的ServiceImpl所在包
31 | */
32 | public static final String SERVICE_IMPL_PACKAGE = SERVICE_PACKAGE + ".impl";
33 | /**
34 | * 生成的Controller所在包
35 | */
36 | public static final String CONTROLLER_PACKAGE = BASE_PACKAGE + ".controller";
37 | /**
38 | * Mapper插件基础接口的完全限定名
39 | */
40 | public static final String MAPPER_INTERFACE_REFERENCE = BASE_PACKAGE + ".core.Mapper";
41 | }
42 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-mybatis/src/main/java/com/demo/configurer/MybatisConfigurer.java:
--------------------------------------------------------------------------------
1 | package com.demo.configurer;
2 |
3 |
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import tk.mybatis.spring.mapper.MapperScannerConfigurer;
7 |
8 | import java.util.Properties;
9 |
10 | import static com.demo.core.ProjectConstant.MAPPER_PACKAGE;
11 |
12 | /**
13 | * Mybatis & Mapper & PageHelper 配置
14 | * @author Gahon
15 | */
16 | @Configuration
17 | public class MybatisConfigurer {
18 |
19 | @Bean
20 | public MapperScannerConfigurer mapperScannerConfigurer() {
21 | MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
22 | // mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactoryBean");
23 | mapperScannerConfigurer.setBasePackage(MAPPER_PACKAGE);
24 |
25 | //配置通用Mapper,详情请查阅官方文档
26 |
27 | Properties properties = new Properties();
28 | // properties.setProperty("mappers", MAPPER_INTERFACE_REFERENCE); //4.0之后版本不需要,除非自定义mapper
29 |
30 | //insert、update是否判断字符串类型!='' 即 test="str != null"表达式内是否追加 and str != ''
31 | properties.setProperty("notEmpty", "false");
32 | //取回主键的方式
33 | properties.setProperty("IDENTITY", "MYSQL");
34 | //配置后会自动处理关键字,可以配的值和数据库有关。
35 | properties.setProperty("wrapKeyword", "`{0}`");
36 | mapperScannerConfigurer.setProperties(properties);
37 |
38 | return mapperScannerConfigurer;
39 | }
40 |
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/src/main/java/com/company/project/core/MessageResultUtils.java:
--------------------------------------------------------------------------------
1 | package com.company.project.core;
2 |
3 | import org.apache.commons.lang3.StringUtils;
4 |
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | /**
9 | * @version:1.0
10 | * @explain:
11 | * @Date: created in 15:56 2019/1/9
12 | */
13 | public class MessageResultUtils {
14 |
15 | /**
16 | * @param @param t
17 | * @param @param msgEnum
18 | * @param @return 设定文件
19 | * @return Map 返回类型
20 | * @throws
21 | * @Title: getResults
22 | */
23 | public static Map getResults(T t, CodeMsgEnum msgEnum) {
24 | Map modelMap = new HashMap();
25 | modelMap.put(CodeMsgEnum.STATUS, msgEnum.getCode());
26 | modelMap.put(CodeMsgEnum.BUSINESSSTATUS, msgEnum.getBunissCode());
27 | //modelMap.put(msgEnum.MESSAGE, msgEnum.getMsg());
28 | modelMap.put(CodeMsgEnum.MESSAGE, (StringUtils.isBlank(msgEnum.getMsg()) ? t : msgEnum.getMsg()));
29 | modelMap.put(CodeMsgEnum.ITEMS, t);
30 | return modelMap;
31 | }
32 |
33 | /**
34 | * @param @param msgEnum
35 | * @param @return 设定文件
36 | * @return Map 返回类型
37 | * @throws
38 | * @Title: getResults
39 | */
40 | public static Map getResults(CodeMsgEnum msgEnum) {
41 | return getResults(null, msgEnum);
42 | }
43 |
44 |
45 | public static Map returnResults(T resultData, Integer status, String businessStatus, String msg, T ext) {
46 | Map modelMap = new HashMap();
47 |
48 | modelMap.put("STATUS", status);
49 | modelMap.put("BUSINESSSTATUS", businessStatus);
50 | modelMap.put("MESSAGE", msg);
51 | modelMap.put("ITEMS", resultData);
52 | modelMap.put("EXT", ext);
53 | return modelMap;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/test/java/com/company/project/GeneratorSwagger2Model.java:
--------------------------------------------------------------------------------
1 | package com.company.project;
2 |
3 | import org.mybatis.generator.api.IntrospectedColumn;
4 | import org.mybatis.generator.api.IntrospectedTable;
5 | import org.mybatis.generator.api.PluginAdapter;
6 | import org.mybatis.generator.api.dom.java.Field;
7 | import org.mybatis.generator.api.dom.java.TopLevelClass;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * @author Gahon
13 | * description 根据数据库注释对实体类增加swagger2文档注解
14 | */
15 | public class GeneratorSwagger2Model extends PluginAdapter {
16 | public boolean validate(List list) {
17 | return true;
18 | }
19 |
20 | @Override
21 | public boolean modelFieldGenerated(Field field, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
22 | String classAnnotation = "@ApiModel(value=\"" + topLevelClass.getType().getShortName() + "\")";
23 | if (!topLevelClass.getAnnotations().contains(classAnnotation)) {
24 | topLevelClass.addAnnotation(classAnnotation);
25 | }
26 |
27 | String apiModelAnnotationPackage = properties.getProperty("apiModelAnnotationPackage");
28 | String apiModelPropertyAnnotationPackage = properties.getProperty("apiModelPropertyAnnotationPackage");
29 | if (null == apiModelAnnotationPackage) apiModelAnnotationPackage = "io.swagger.annotations.ApiModel";
30 | if (null == apiModelPropertyAnnotationPackage)
31 | apiModelPropertyAnnotationPackage = "io.swagger.annotations.ApiModelProperty";
32 |
33 | topLevelClass.addImportedType(apiModelAnnotationPackage);
34 | topLevelClass.addImportedType(apiModelPropertyAnnotationPackage);
35 |
36 | field.addAnnotation("@ApiModelProperty(value=\"" + introspectedColumn.getRemarks() + "\")");
37 | return super.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, modelClassType);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-mybatis/src/main/java/com/demo/core/MessageResultUtils.java:
--------------------------------------------------------------------------------
1 | package com.demo.core;
2 |
3 | import org.apache.commons.lang3.StringUtils;
4 |
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | /**
9 | * @version:1.0
10 | * @explain:
11 | * @Date: created in 15:56 2019/1/9
12 | */
13 | public class MessageResultUtils {
14 |
15 | /**
16 | * @param @param t
17 | * @param @param msgEnum
18 | * @param @return 设定文件
19 | * @return Map 返回类型
20 | * @throws
21 | * @Title: getResults
22 | */
23 | public static Map getResults(T t, CodeMsgEnum msgEnum) {
24 | Map modelMap = new HashMap();
25 | modelMap.put(CodeMsgEnum.STATUS, msgEnum.getCode());
26 | modelMap.put(CodeMsgEnum.BUSINESSSTATUS, msgEnum.getBunissCode());
27 | //modelMap.put(msgEnum.MESSAGE, msgEnum.getMsg());
28 | modelMap.put(CodeMsgEnum.MESSAGE, (StringUtils.isBlank(msgEnum.getMsg()) ? t : msgEnum.getMsg()));
29 | modelMap.put(CodeMsgEnum.ITEMS, t);
30 | return modelMap;
31 | }
32 |
33 | /**
34 | * @param @param msgEnum
35 | * @param @return 设定文件
36 | * @return Map 返回类型
37 | * @throws
38 | * @Title: getResults
39 | */
40 | public static Map getResults(CodeMsgEnum msgEnum) {
41 | return getResults(null, msgEnum);
42 | }
43 |
44 |
45 | public static Map returnResults(T resultData, Integer status, String businessStatus, String msg, T ext) {
46 | Map modelMap = new HashMap();
47 |
48 | modelMap.put("STATUS", status);
49 | modelMap.put("BUSINESSSTATUS", businessStatus);
50 | modelMap.put("MESSAGE", msg);
51 | modelMap.put("ITEMS", resultData);
52 | modelMap.put("EXT", ext);
53 | return modelMap;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/spring-cloud-learning-01/jf-mybatis/src/test/java/com/demo/GeneratorSwagger2Model.java:
--------------------------------------------------------------------------------
1 | package com.demo;
2 |
3 | import org.mybatis.generator.api.IntrospectedColumn;
4 | import org.mybatis.generator.api.IntrospectedTable;
5 | import org.mybatis.generator.api.PluginAdapter;
6 | import org.mybatis.generator.api.dom.java.Field;
7 | import org.mybatis.generator.api.dom.java.TopLevelClass;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * @author Gahon
13 | * description 根据数据库注释对实体类增加swagger2文档注解
14 | */
15 | public class GeneratorSwagger2Model extends PluginAdapter {
16 | public boolean validate(List list) {
17 | return true;
18 | }
19 |
20 | @Override
21 | public boolean modelFieldGenerated(Field field, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn, IntrospectedTable introspectedTable, ModelClassType modelClassType) {
22 | String classAnnotation = "@ApiModel(value=\"" + topLevelClass.getType().getShortName() + "\")";
23 | if (!topLevelClass.getAnnotations().contains(classAnnotation)) {
24 | topLevelClass.addAnnotation(classAnnotation);
25 | }
26 |
27 | String apiModelAnnotationPackage = properties.getProperty("apiModelAnnotationPackage");
28 | String apiModelPropertyAnnotationPackage = properties.getProperty("apiModelPropertyAnnotationPackage");
29 | if (null == apiModelAnnotationPackage) apiModelAnnotationPackage = "io.swagger.annotations.ApiModel";
30 | if (null == apiModelPropertyAnnotationPackage)
31 | apiModelPropertyAnnotationPackage = "io.swagger.annotations.ApiModelProperty";
32 |
33 | topLevelClass.addImportedType(apiModelAnnotationPackage);
34 | topLevelClass.addImportedType(apiModelPropertyAnnotationPackage);
35 |
36 | field.addAnnotation("@ApiModelProperty(value=\"" + introspectedColumn.getRemarks() + "\")");
37 | return super.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable, modelClassType);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/company/project/configurer/MybatisConfigurer.java:
--------------------------------------------------------------------------------
1 | package com.company.project.configurer;
2 |
3 |
4 | import com.github.pagehelper.PageHelper;
5 | import com.github.pagehelper.PageInterceptor;
6 | import org.apache.ibatis.plugin.Interceptor;
7 | import org.apache.ibatis.session.SqlSessionFactory;
8 | import org.mybatis.spring.SqlSessionFactoryBean;
9 | import org.springframework.context.annotation.Bean;
10 | import org.springframework.context.annotation.Configuration;
11 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
12 | import org.springframework.core.io.support.ResourcePatternResolver;
13 | import tk.mybatis.spring.mapper.MapperScannerConfigurer;
14 | import javax.sql.DataSource;
15 | import java.util.Properties;
16 |
17 | import static com.company.project.core.ProjectConstant.MAPPER_PACKAGE;
18 | import static com.company.project.core.ProjectConstant.MODEL_PACKAGE;
19 |
20 | /**
21 | * Mybatis & Mapper & PageHelper 配置
22 | * @author Gahon
23 | */
24 | @Configuration
25 | public class MybatisConfigurer {
26 |
27 | @Bean
28 | public MapperScannerConfigurer mapperScannerConfigurer() {
29 | MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
30 | // mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactoryBean");
31 | mapperScannerConfigurer.setBasePackage(MAPPER_PACKAGE);
32 |
33 | //配置通用Mapper,详情请查阅官方文档
34 |
35 | Properties properties = new Properties();
36 | // properties.setProperty("mappers", MAPPER_INTERFACE_REFERENCE); //4.0之后版本不需要,除非自定义mapper
37 |
38 | //insert、update是否判断字符串类型!='' 即 test="str != null"表达式内是否追加 and str != ''
39 | properties.setProperty("notEmpty", "false");
40 | //取回主键的方式
41 | properties.setProperty("IDENTITY", "MYSQL");
42 | //配置后会自动处理关键字,可以配的值和数据库有关。
43 | properties.setProperty("wrapKeyword", "`{0}`");
44 | mapperScannerConfigurer.setProperties(properties);
45 |
46 | return mapperScannerConfigurer;
47 | }
48 |
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/src/main/java/com/company/project/core/Query.java:
--------------------------------------------------------------------------------
1 | package com.company.project.core;
2 |
3 | import cn.hutool.core.util.ObjectUtil;
4 | import cn.hutool.core.util.StrUtil;
5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 | import lombok.Getter;
7 |
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 | /**
12 | * @Author:xpj
13 | * @version:1.0
14 | * @explain:
15 | * @Date: created in 12:27 2019/1/11
16 | */
17 | public class Query extends Page {
18 | private static final String PAGE = "page";
19 | private static final String pageSize = "pageSize";
20 | private static final String ORDER_BY_FIELD = "orderByField";
21 | private static final String IS_ASC = "isAsc";
22 |
23 | @Getter
24 | private Map condition;
25 |
26 | public Query setCondition(Map condition) {
27 | this.condition = condition;
28 | return this;
29 | }
30 |
31 | @Override
32 | public Map