├── .gitignore
├── README.MD
├── elastic-core
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── leno
│ │ │ ├── ElasticCoreApplication.java
│ │ │ ├── common
│ │ │ ├── BeanConfig.java
│ │ │ ├── ElasticControllerAdvice.java
│ │ │ ├── RestCodeEnum.java
│ │ │ ├── RestResult.java
│ │ │ └── SpringContextUtil.java
│ │ │ ├── controller
│ │ │ └── UserController.java
│ │ │ ├── model
│ │ │ └── request
│ │ │ │ └── UserRequest.java
│ │ │ └── service
│ │ │ ├── UserService.java
│ │ │ └── impl
│ │ │ └── UserServiceImpl.java
│ └── resources
│ │ ├── application.yml
│ │ └── elastic-logback.xml
│ └── test
│ └── java
│ └── com
│ └── leno
│ └── ElasticsCoreApplicationTests.java
├── elastic-dal
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── leno
│ │ └── elastic
│ │ ├── dal
│ │ ├── common
│ │ │ ├── BaseCriteria.java
│ │ │ ├── BaseQuery.java
│ │ │ ├── Criterion.java
│ │ │ └── PageResult.java
│ │ ├── mapper
│ │ │ ├── UserMapper.java
│ │ │ └── ext
│ │ │ │ └── UserExtMapper.java
│ │ ├── model
│ │ │ └── UserDO.java
│ │ └── query
│ │ │ └── UserQuery.java
│ │ └── manager
│ │ ├── UserManager.java
│ │ └── impl
│ │ └── UserManagerImpl.java
│ └── resources
│ └── mapper
│ ├── UserMapper.xml
│ └── ext
│ └── UserExtMapper.xml
├── elastic-generator
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── leno
│ │ └── mybatisgen
│ │ ├── ColumnInfo.java
│ │ ├── Main.java
│ │ ├── MyBatisGenConst.java
│ │ ├── MyBatisGenCore.java
│ │ └── enums
│ │ └── ColumnTypeEnum.java
│ └── resources
│ ├── db.config
│ ├── generate_tables.config
│ └── template
│ ├── do.txt
│ ├── manager.txt
│ ├── managerImpl.txt
│ ├── mapper-ext.txt
│ ├── mapper.txt
│ ├── query.txt
│ ├── sqlmap-ext.txt
│ └── sqlmap.txt
├── elastic-search
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── leno
│ │ └── search
│ │ ├── common
│ │ ├── ESClientDecorator.java
│ │ ├── EsSearchClient.java
│ │ ├── IESEntity.java
│ │ ├── LuSearchClient.java
│ │ ├── SearchClient.java
│ │ └── SimpleESEntity.java
│ │ ├── config
│ │ ├── ElasticsConfig.java
│ │ └── ElasticsProperties.java
│ │ ├── entity
│ │ ├── BaseEntity.java
│ │ ├── UserESEntity.java
│ │ ├── enums
│ │ │ └── ESQueryTypeEnum.java
│ │ └── request
│ │ │ ├── CommonSearchRequest.java
│ │ │ └── SearchWord.java
│ │ └── repository
│ │ ├── UserSearchRepository.java
│ │ └── impl
│ │ └── UserSearchRepositoryImpl.java
│ └── resources
│ └── conf
│ ├── jdbc.conf
│ └── user.sql
├── moyu_index_sync.sh
├── pom.xml
└── start.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/README.MD:
--------------------------------------------------------------------------------
1 | # elasticsearch 6.x DEMO
2 | ## 简述
3 | ### SpringBoot+elasticsearch6.x搭建的es全文搜索服务demo,主要技术:
4 | - 1、SpringBoot+Mybatis+Elasticsearch6.x框架
5 | - 2、使用RestHighLevelClient作为搜索java api
6 | - 3、使用LogStash同步mysql数据
7 |
8 | ## 环境安装
9 |
10 | * 创建需用同步数据的表 示例:
11 |
12 | ```CREATE TABLE user
13 | (
14 | user_id BIGINT AUTO_INCREMENT
15 | COMMENT '主键'
16 | PRIMARY KEY,
17 | user_name VARCHAR(30) DEFAULT '' NOT NULL
18 | COMMENT '用户名',
19 | sex INT DEFAULT '0' NOT NULL
20 | COMMENT '性别',
21 | login_name VARCHAR(20) DEFAULT '' NOT NULL
22 | COMMENT '登录名',
23 | login_pwd VARCHAR(30) DEFAULT '' NOT NULL
24 | COMMENT '密码',
25 | status INT DEFAULT '0' NOT NULL
26 | COMMENT '状态',
27 | gmt_create TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
28 | gmt_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
29 | );
30 |
31 | * elasticsearch安装
32 | ` brew install elasticsearch
33 | 安装完成之后检查一下elasticsearch状态,使用curl命令
34 | curl localhost:9200
35 | `
36 | * 中文分词器安装
37 | ` elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.x/elasticsearch-analysis-ik-6.x.zip `
38 |
"6.x表示对应的elasticsearch版本"
39 |
40 | * 创建索引和映射
41 | ```{
42 | "mappings":{
43 | "doc":{
44 | "properties":{
45 | "@timestamp":{
46 | "type":"date"
47 | },
48 | "@version":{
49 | "type":"text",
50 | "fields":{
51 | "keyword":{
52 | "type":"keyword",
53 | "ignore_above":256
54 | }
55 | }
56 | },
57 | "gmt_create":{
58 | "type":"date"
59 | },
60 | "gmt_modified":{
61 | "type":"date"
62 | },
63 | "login_name":{
64 | "type":"text",
65 | "fields":{
66 | "keyword":{
67 | "type":"keyword",
68 | "ignore_above":256
69 | }
70 | },
71 | "analyzer":"ik_max_word"
72 | },
73 | "login_pwd":{
74 | "type":"text",
75 | "fields":{
76 | "keyword":{
77 | "type":"keyword",
78 | "ignore_above":256
79 | }
80 | }
81 | },
82 | "sex":{
83 | "type":"long"
84 | },
85 | "status":{
86 | "type":"long"
87 | },
88 | "user_id":{
89 | "type":"long"
90 | },
91 | "user_name":{
92 | "type":"text",
93 | "fields":{
94 | "keyword":{
95 | "type":"keyword",
96 | "ignore_above":256
97 | }
98 | },
99 | "analyzer":"ik_max_word"
100 | }
101 | }
102 | }
103 | }
104 | }
105 |
106 | * 安装LogStash
107 | ` brew install LogStash`
108 |
109 | ## 使用方法
110 |
111 | * 同步数据脚本
112 | `sh moyu_index_sync.sh`
113 |
114 |
115 |
--------------------------------------------------------------------------------
/elastic-core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | elastic-core
7 | jar
8 |
9 | elastic-core
10 |
11 |
12 | com.leno
13 | elastic-demo
14 | 1.0-SNAPSHOT
15 |
16 |
17 |
18 |
19 |
20 | org.springframework.boot
21 | spring-boot-starter
22 |
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-aop
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-test
32 | test
33 |
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-starter-web
38 |
39 |
40 |
41 | com.leno
42 | elastic-dal
43 |
44 |
45 |
46 | com.leno
47 | elastic-search
48 |
49 |
50 |
51 | org.projectlombok
52 | lombok
53 |
54 |
55 |
56 | com.alibaba
57 | fastjson
58 |
59 |
60 |
61 | mysql
62 | mysql-connector-java
63 |
64 |
65 |
66 |
67 | elastics
68 |
69 |
70 | org.springframework.boot
71 | spring-boot-maven-plugin
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/elastic-core/src/main/java/com/leno/ElasticCoreApplication.java:
--------------------------------------------------------------------------------
1 | package com.leno;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ElasticCoreApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(ElasticCoreApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/elastic-core/src/main/java/com/leno/common/BeanConfig.java:
--------------------------------------------------------------------------------
1 | package com.leno.common;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | /**
7 | *
TODO
8 | *
9 | * @author: XianGuo
10 | * @date: 2018年02月07日
11 | */
12 | @Configuration
13 | public class BeanConfig {
14 |
15 | @Bean
16 | public SpringContextUtil getContext() {
17 | return new SpringContextUtil();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/elastic-core/src/main/java/com/leno/common/ElasticControllerAdvice.java:
--------------------------------------------------------------------------------
1 | package com.leno.common;
2 |
3 | import org.springframework.util.CollectionUtils;
4 | import org.springframework.validation.BindingResult;
5 | import org.springframework.validation.ObjectError;
6 | import org.springframework.web.bind.MethodArgumentNotValidException;
7 | import org.springframework.web.bind.annotation.ControllerAdvice;
8 | import org.springframework.web.bind.annotation.ExceptionHandler;
9 | import org.springframework.web.bind.annotation.ResponseBody;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * controller异常统一处理
15 | *
16 | * @author: XianGuo
17 | * @date: 2018年02月10日
18 | */
19 | @ControllerAdvice
20 | public class ElasticControllerAdvice {
21 |
22 | @ExceptionHandler(MethodArgumentNotValidException.class)
23 | @ResponseBody
24 | public Object handlerValidException(MethodArgumentNotValidException e) {
25 | RestResult result = RestResult.getFailResult(RestCodeEnum.PARAMS_ERROR);
26 | BindingResult bindingResult = e.getBindingResult();
27 | if (bindingResult == null || CollectionUtils.isEmpty(bindingResult.getAllErrors())) {
28 | return result;
29 | }
30 |
31 | List errors = bindingResult.getAllErrors();
32 | result.setDesc(errors.get(0).getDefaultMessage());
33 | return result;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/elastic-core/src/main/java/com/leno/common/RestCodeEnum.java:
--------------------------------------------------------------------------------
1 | package com.leno.common;
2 |
3 | /**
4 | * rest 状态枚举类
5 | *
6 | * @author: XianGuo
7 | * @date: 2018年02月10日
8 | */
9 | public enum RestCodeEnum {
10 | SUCCESS(200, "请求成功"), NOT_FOUND(500, "服务器错误"), PARAMS_ERROR(400, "请求参数错误");
11 |
12 | private Integer code;
13 | private String desc;
14 |
15 | RestCodeEnum(Integer code, String desc) {
16 | this.code = code;
17 | this.desc = desc;
18 | }
19 |
20 | public Integer getCode() {
21 | return code;
22 | }
23 |
24 | public String getDesc() {
25 | return desc;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/elastic-core/src/main/java/com/leno/common/RestResult.java:
--------------------------------------------------------------------------------
1 | package com.leno.common;
2 |
3 | import com.fasterxml.jackson.annotation.JsonInclude;
4 | import lombok.Data;
5 |
6 | import static com.leno.common.RestCodeEnum.SUCCESS;
7 |
8 | /**
9 | * rest api 结果
10 | *
11 | * @author: XianGuo
12 | * @date: 2018年02月10日
13 | */
14 | @Data
15 | public class RestResult {
16 |
17 | private int code;
18 |
19 | private String desc;
20 |
21 | @JsonInclude(JsonInclude.Include.NON_NULL)
22 | private T data;
23 |
24 | public void setRestCode(int code, String desc) {
25 | this.code = code;
26 | this.desc = desc;
27 | }
28 |
29 | public void setRestCodeEnum(RestCodeEnum restCodeEnum) {
30 | this.setRestCode(restCodeEnum.getCode(), restCodeEnum.getDesc());
31 | }
32 |
33 | public static RestResult getSuccessResult(T data) {
34 | RestResult restResult = new RestResult<>();
35 | restResult.setRestCodeEnum(SUCCESS);
36 | restResult.setData(data);
37 | return restResult;
38 | }
39 |
40 | public static RestResult getFailResult(int code, String desc) {
41 | RestResult restResult = new RestResult();
42 | restResult.setRestCode(code, desc);
43 | return restResult;
44 | }
45 |
46 | public static RestResult getFailResult(RestCodeEnum restCodeEnum) {
47 | return getFailResult(restCodeEnum.getCode(), restCodeEnum.getDesc());
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/elastic-core/src/main/java/com/leno/common/SpringContextUtil.java:
--------------------------------------------------------------------------------
1 | package com.leno.common;
2 |
3 | import org.springframework.beans.BeansException;
4 | import org.springframework.context.ApplicationContext;
5 | import org.springframework.context.ApplicationContextAware;
6 |
7 | /**
8 | * TODO
9 | *
10 | * @author: XianGuo
11 | * @date: 2018年02月07日
12 | */
13 | public class SpringContextUtil implements ApplicationContextAware {
14 |
15 | private static ApplicationContext act;
16 |
17 | @Override
18 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
19 | act = applicationContext;
20 | }
21 |
22 | public static T getBean(Class tClass) {
23 | return act.getBean(tClass);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/elastic-core/src/main/java/com/leno/controller/UserController.java:
--------------------------------------------------------------------------------
1 | package com.leno.controller;
2 |
3 | import com.leno.model.request.UserRequest;
4 | import com.leno.service.UserService;
5 | import lombok.extern.slf4j.Slf4j;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.validation.annotation.Validated;
8 | import org.springframework.web.bind.annotation.*;
9 |
10 | /**
11 | * TODO
12 | *
13 | * @author: XianGuo
14 | * @date: 2018年01月22日
15 | */
16 | @RestController
17 | @RequestMapping("/user")
18 | @Slf4j
19 | public class UserController {
20 |
21 | @Autowired
22 | private UserService userService;
23 |
24 | @PostMapping("/getUserList.json")
25 | public Object getUserList(@RequestBody @Validated UserRequest userRequest) {
26 | return userService.getUserList(userRequest);
27 | }
28 |
29 | @PostMapping("/searchMatch.json")
30 | public Object searchMatch(@RequestParam String userName) {
31 | return userService.searchMatchByName(userName);
32 | }
33 |
34 | @PostMapping("/searchTerm.json")
35 | public Object searchTerm(@RequestParam String userName) {
36 | return userService.searchTermByName(userName);
37 | }
38 |
39 | @PostMapping("/searchMatchPhrase.json")
40 | public Object searchMatchPhrase(@RequestParam String userName) {
41 | return userService.searchMatchPhraseByName(userName);
42 | }
43 |
44 | @GetMapping("/test")
45 | public Object log() {
46 | new Thread(() -> {
47 | for (int i = 0; i < 100000; i++) {
48 | log.info("info测试日志{}s", System.currentTimeMillis());
49 | log.warn("warn测试日志{}s", System.currentTimeMillis());
50 | log.error("error测试日志{}s", System.currentTimeMillis());
51 | }
52 | }).start();
53 | return "测试日志";
54 | }
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/elastic-core/src/main/java/com/leno/model/request/UserRequest.java:
--------------------------------------------------------------------------------
1 | package com.leno.model.request;
2 |
3 | import lombok.Data;
4 | import org.hibernate.validator.constraints.NotBlank;
5 |
6 | /**
7 | * 用户请求参数
8 | *
9 | * @author: XianGuo
10 | * @date: 2018年02月10日
11 | */
12 | @Data
13 | public class UserRequest {
14 |
15 | @NotBlank(message = "用户名不能为空")
16 | private String userName;
17 |
18 | @NotBlank(message = "登录名不能为空")
19 | private String loginName;
20 |
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/elastic-core/src/main/java/com/leno/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.leno.service;
2 |
3 | import com.leno.common.RestResult;
4 | import com.leno.elastic.dal.model.UserDO;
5 | import com.leno.model.request.UserRequest;
6 | import com.leno.search.entity.UserESEntity;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * 用户相关服务
12 | *
13 | * @author: XianGuo
14 | * @date: 2018年02月10日
15 | */
16 | public interface UserService {
17 |
18 | /**
19 | * 根据请求参数获取用户利比饿哦
20 | */
21 | RestResult> getUserList(UserRequest request);
22 |
23 | /**
24 | * 全文搜索
25 | */
26 | RestResult> searchMatchByName(String userName);
27 |
28 |
29 | /**
30 | * 精确搜索
31 | */
32 | RestResult> searchTermByName(String userName);
33 |
34 |
35 | /**
36 | * 紧邻搜索
37 | */
38 | RestResult> searchMatchPhraseByName(String userName);
39 | }
40 |
--------------------------------------------------------------------------------
/elastic-core/src/main/java/com/leno/service/impl/UserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.leno.service.impl;
2 |
3 | import com.leno.common.RestResult;
4 | import com.leno.elastic.dal.model.UserDO;
5 | import com.leno.elastic.dal.query.UserQuery;
6 | import com.leno.elastic.manager.UserManager;
7 | import com.leno.model.request.UserRequest;
8 | import com.leno.search.common.SearchClient;
9 | import com.leno.search.entity.UserESEntity;
10 | import com.leno.service.UserService;
11 | import org.elasticsearch.action.search.SearchRequest;
12 | import org.elasticsearch.index.query.QueryBuilders;
13 | import org.elasticsearch.search.builder.SearchSourceBuilder;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.stereotype.Service;
16 |
17 | import java.util.List;
18 |
19 | /**
20 | * 用户相关接口实现
21 | *
22 | * @author: XianGuo
23 | * @date: 2018年02月10日
24 | */
25 | @Service
26 | public class UserServiceImpl implements UserService {
27 |
28 | @Autowired
29 | private SearchClient searchClient;
30 |
31 | @Autowired
32 | private UserManager userManager;
33 |
34 | @Override
35 | public RestResult> getUserList(UserRequest request) {
36 | UserQuery userQuery = new UserQuery();
37 | userQuery.createCriteria().andStatusEqualTo(0)
38 | .andUserNameEqualTo(request.getUserName())
39 | .andLoginNameEqualTo(request.getLoginName());
40 | return RestResult.getSuccessResult(userManager.selectByQuery(userQuery));
41 | }
42 |
43 | @Override
44 | public RestResult> searchMatchByName(String userName) {
45 | SearchRequest searchRequest = new SearchRequest();
46 | searchRequest.indices("moyu_index2");
47 | SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
48 | searchSourceBuilder.query(QueryBuilders.matchQuery("user_name", userName));
49 | searchRequest.source(searchSourceBuilder);
50 | return RestResult.getSuccessResult(searchClient.search(searchRequest, UserESEntity.class));
51 | }
52 |
53 | @Override
54 | public RestResult> searchTermByName(String userName) {
55 | SearchRequest searchRequest = new SearchRequest();
56 | searchRequest.indices("moyu_index2");
57 | SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
58 | searchSourceBuilder.query(QueryBuilders.termQuery("user_name", userName));
59 | searchRequest.source(searchSourceBuilder);
60 | return RestResult.getSuccessResult(searchClient.search(searchRequest, UserESEntity.class));
61 | }
62 |
63 | @Override
64 | public RestResult> searchMatchPhraseByName(String userName) {
65 | SearchRequest searchRequest = new SearchRequest();
66 | searchRequest.indices("moyu_index2");
67 | SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
68 | searchSourceBuilder.query(QueryBuilders.matchPhraseQuery("user_name", userName));
69 | searchRequest.source(searchSourceBuilder);
70 | return RestResult.getSuccessResult(searchClient.search(searchRequest, UserESEntity.class));
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/elastic-core/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8020
3 | spring:
4 | data:
5 | elasticsearch:
6 | cluster-name: elasticsearch_xianguo
7 | cluster-nodes: localhost
8 | datasource:
9 | driverClassName: com.mysql.jdbc.Driver
10 | username: root
11 | password: alixian
12 | url: jdbc:mysql://localhost:3306/moyu_db?useUnicode=true&characterEncoding=utf-8&useSSL=true
13 | type: org.apache.tomcat.jdbc.pool.DataSource
14 | profiles:
15 | active: local
16 | application:
17 | name: elastic
18 | mybatis:
19 | mapper-locations: classpath*:/mapper/**/*Mapper.xml
20 | type-aliases-package: com.leno.elastic.dal.model
21 | logging:
22 | config: classpath:elastic-logback.xml
23 |
--------------------------------------------------------------------------------
/elastic-core/src/main/resources/elastic-logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | v
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | %date{yyyy-MM-dd HH:mm:ss} | %highlight(%-5level) | %boldYellow(%thread) | %boldGreen(%logger) |
34 | %msg | [%file:%line]%n
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | ${FILE_PATH}/info.log
43 |
44 |
45 | ${FILE_PATH}/info.%d{yyyy-MM-dd}.%i.log
46 |
47 | 100000
48 |
49 |
50 | 10MB
51 |
52 |
53 |
54 |
55 | ${PATTERN}
56 | UTF-8
57 |
58 |
59 |
60 |
61 |
62 | ${ERROR_FILE_PATH}/error.log
63 |
64 |
65 | ${ERROR_FILE_PATH}/error.%d{yyyy-MM-dd}.%i.log
66 |
67 | 100000
68 |
69 |
70 | 10MB
71 |
72 |
73 |
74 |
75 | ${PATTERN}
76 | UTF-8
77 |
78 |
79 | ERROR
80 | ACCEPT
81 | DENY
82 |
83 |
84 |
85 |
86 |
87 | ${WARN_FILE_PATH}/warn.log
88 |
89 |
90 | ${WARN_FILE_PATH}/warn.%d{yyyy-MM-dd}.%i.log
91 |
92 | 100000
93 |
94 |
95 | 10MB
96 |
97 |
98 |
99 |
100 | ${PATTERN}
101 | UTF-8
102 |
103 |
104 | WARN
105 | ACCEPT
106 | DENY
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/elastic-core/src/test/java/com/leno/ElasticsCoreApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.leno;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class ElasticsCoreApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/elastic-dal/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | elastic-dal
7 | jar
8 |
9 |
10 | com.leno
11 | elastic-demo
12 | 1.0-SNAPSHOT
13 |
14 |
15 |
16 |
17 |
18 | org.projectlombok
19 | lombok
20 |
21 |
22 |
23 | org.mybatis.spring.boot
24 | mybatis-spring-boot-starter
25 |
26 |
27 |
28 | commons-lang
29 | commons-lang
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/elastic-dal/src/main/java/com/leno/elastic/dal/common/BaseCriteria.java:
--------------------------------------------------------------------------------
1 | package com.leno.elastic.dal.common;
2 |
3 | import java.io.Serializable;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | /**
8 | * Created by XianGuo
9 | * Date: 2017-07-04 20:24
10 | */
11 | public class BaseCriteria implements Serializable {
12 | private static final long serialVersionUID = 1L;
13 | protected List criteria;
14 |
15 | protected BaseCriteria() {
16 | super();
17 | criteria = new ArrayList();
18 | }
19 |
20 | public boolean isValid() {
21 | return criteria.size() > 0;
22 | }
23 |
24 | public List getAllCriteria() {
25 | return criteria;
26 | }
27 |
28 | public List getCriteria() {
29 | return criteria;
30 | }
31 |
32 | protected void addCriterion(String condition) {
33 | if (condition == null) {
34 | throw new RuntimeException("Value for condition cannot be null");
35 | }
36 | criteria.add(new Criterion(condition));
37 | }
38 |
39 | protected void addCriterion(String condition, Object value, String property) {
40 | if (value == null) {
41 | throw new RuntimeException("Value for " + property + " cannot be null");
42 | }
43 | criteria.add(new Criterion(condition, value));
44 | }
45 |
46 | protected void addCriterion(String condition, Object value1, Object value2, String property) {
47 | if (value1 == null || value2 == null) {
48 | throw new RuntimeException("Between values for " + property + " cannot be null");
49 | }
50 | criteria.add(new Criterion(condition, value1, value2));
51 | }
52 | }
53 |
54 |
--------------------------------------------------------------------------------
/elastic-dal/src/main/java/com/leno/elastic/dal/common/BaseQuery.java:
--------------------------------------------------------------------------------
1 | package com.leno.elastic.dal.common;
2 |
3 | import java.io.Serializable;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | /**
8 | * Created by XianGuo
9 | * Date: 2017-07-04 20:28
10 | */
11 | public class BaseQuery implements Serializable {
12 | private static final long serialVersionUID = 1L;
13 |
14 | public static int DEFAULT_PAGE_SIZE = 20; // 默认页大小
15 | public static int MAX_PAGE_SIZE = 100; // 最大页大小
16 | public static int DEFAULT_PAGE = 1; // 默认分页
17 | /**
18 | * order by clause.
19 | */
20 | protected String orderByClause;
21 |
22 | /**
23 | * distinct
24 | */
25 | protected boolean distinct;
26 |
27 | /**
28 | * criteria list
29 | */
30 | protected List oredCriteria;
31 |
32 | /**
33 | * page
34 | */
35 | protected Integer pageOffset;
36 |
37 |
38 | /**
39 | * pageNo
40 | */
41 | protected Integer pageNo;
42 |
43 | /**
44 | * page size
45 | */
46 | protected Integer pageSize ;//= DEFAULT_PAGE_SIZE ;
47 |
48 | public BaseQuery() {
49 | oredCriteria = new ArrayList();
50 | }
51 |
52 | public void setOrderByClause(String orderByClause) {
53 | this.orderByClause = orderByClause;
54 | }
55 |
56 | public String getOrderByClause() {
57 | return orderByClause;
58 | }
59 |
60 | public void setDistinct(boolean distinct) {
61 | this.distinct = distinct;
62 | }
63 |
64 | public boolean isDistinct() {
65 | return distinct;
66 | }
67 |
68 | public List getOredCriteria() {
69 | return oredCriteria;
70 | }
71 |
72 | public void or(BaseCriteria criteria) {
73 | oredCriteria.add(criteria);
74 | }
75 |
76 |
77 | public void clear() {
78 | oredCriteria.clear();
79 | orderByClause = null;
80 | distinct = false;
81 | }
82 |
83 | public void clearPage(){
84 | this.pageSize = null;
85 | this.pageNo = null;
86 | this.pageOffset = null;
87 | }
88 |
89 | protected void calPageOffset(){
90 | if(null == pageSize || null == pageNo){
91 | pageOffset = null;
92 | }else{
93 | pageOffset = (pageNo -1)*pageSize;
94 | }
95 | }
96 |
97 | public boolean isValid() {
98 | for (int i = 0; i < oredCriteria.size(); i++) {
99 | if (oredCriteria.get(i).isValid()) {
100 | return true;
101 | }
102 | }
103 | return false;
104 | }
105 |
106 | public void setPageOffset(Integer pageOffset) {
107 | this.pageOffset = pageOffset;
108 | }
109 |
110 | public Integer getPageOffset() {
111 | return pageOffset;
112 | }
113 |
114 | public void setPageSize(Integer pageSize) {
115 | if(pageSize == null || pageSize <= 0){
116 | this.clearPage();
117 | }else if(pageSize > MAX_PAGE_SIZE){
118 | this.pageSize = MAX_PAGE_SIZE;
119 | }else {
120 | this.pageSize = pageSize;
121 | }
122 | this.calPageOffset();
123 | }
124 |
125 | public Integer getPageSize() {
126 | return pageSize;
127 | }
128 |
129 |
130 | public Integer getPageNo() {
131 | return pageNo;
132 | }
133 |
134 | public void setPageNo(Integer pageNo) {
135 | if(pageNo == null || pageNo ) {
73 | this.listValue = true;
74 | } else {
75 | this.singleValue = true;
76 | }
77 | }
78 |
79 | public Criterion(String condition, Object value) {
80 | this(condition, value, null);
81 | }
82 |
83 | public Criterion(String condition, Object value, Object secondValue, String typeHandler) {
84 | super();
85 | this.condition = condition;
86 | this.value = value;
87 | this.secondValue = secondValue;
88 | this.typeHandler = typeHandler;
89 | this.betweenValue = true;
90 | }
91 |
92 | public Criterion(String condition, Object value, Object secondValue) {
93 | this(condition, value, secondValue, null);
94 | }
95 |
96 |
97 | @Override
98 | public String toString() {
99 | if (isNoValue()) {
100 | return condition;
101 | } else if (isSingleValue()) {
102 | return condition + " " + this.getValue();
103 | } else if (isBetweenValue()) {
104 | return condition + " " + this.value + " and " + this.secondValue;
105 | } else if (isListValue()) {
106 | return condition + " in " + this.value;
107 | } else {
108 | return "invalid status";
109 | }
110 | }
111 | }
--------------------------------------------------------------------------------
/elastic-dal/src/main/java/com/leno/elastic/dal/common/PageResult.java:
--------------------------------------------------------------------------------
1 | package com.leno.elastic.dal.common;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | /**
7 | * Created by XianGuo
8 | * Date: 2017-07-04 20:27
9 | */
10 | public class PageResult implements Serializable {
11 | private static final long serialVersionUID = 1L;
12 |
13 | private List result;
14 |
15 | private int pageNo = BaseQuery.DEFAULT_PAGE;
16 |
17 | private int totalCount; // 总的数目
18 |
19 | private int pageSize = BaseQuery.DEFAULT_PAGE_SIZE; //每一页数目
20 |
21 | public List getResult() {
22 | return result;
23 | }
24 |
25 | public void setResult(List result) {
26 | this.result = result;
27 | }
28 |
29 | public int getPageNo() {
30 | return pageNo;
31 | }
32 |
33 | public void setPageNo(int pageNo) {
34 | this.pageNo = pageNo;
35 | }
36 |
37 | public int getTotalPage() {
38 | if(pageNo < 1){
39 | pageNo = BaseQuery.DEFAULT_PAGE;
40 | }
41 | return totalCount / pageSize + (totalCount % pageSize == 0 ? 0 : 1);
42 | }
43 |
44 |
45 | public int getTotalCount() {
46 | return totalCount;
47 | }
48 |
49 | public void setTotalCount(int totalCount) {
50 | this.totalCount = totalCount;
51 | }
52 |
53 | public int getPageSize() {
54 | return pageSize;
55 | }
56 |
57 |
58 | public void setPageSize(int pageSize) {
59 | this.pageSize = pageSize;
60 | }
61 | }
--------------------------------------------------------------------------------
/elastic-dal/src/main/java/com/leno/elastic/dal/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.leno.elastic.dal.mapper;
2 |
3 | import com.leno.elastic.dal.model.UserDO;
4 | import com.leno.elastic.dal.query.UserQuery;
5 |
6 | import java.util.List;
7 |
8 | import org.apache.ibatis.annotations.Mapper;
9 | import org.apache.ibatis.annotations.Param;
10 | import org.springframework.stereotype.Repository;
11 | /**
12 | * MyBatis Mapper for User.
13 | */
14 | @Mapper
15 | @Repository
16 | public interface UserMapper {
17 | /**
18 | * query count by query condition.
19 | */
20 | int countByQuery(UserQuery query);
21 |
22 | /**
23 | * delete by query condition.
24 | */
25 | int deleteByQuery(UserQuery query);
26 |
27 | /**
28 | * delete by primary key.
29 | */
30 | int deleteByPrimaryKey(UserDO record);
31 |
32 | /**
33 | * insert selective.
34 | */
35 | int insertSelective(UserDO record);
36 |
37 | /**
38 | * select by query condition.
39 | */
40 | List selectByQuery(UserQuery query);
41 |
42 | /**
43 | * select by primary key.
44 | */
45 | UserDO selectByPrimaryKey(Long id);
46 |
47 | /**
48 | * update by query condition selective.
49 | */
50 | int updateByQuerySelective(@Param("record") UserDO record, @Param("query") UserQuery query);
51 |
52 | /**
53 | * update by query condition.
54 | */
55 | int updateByQuery(@Param("record") UserDO record, @Param("query") UserQuery query);
56 |
57 | /**
58 | * update by primary key selective.
59 | */
60 | int updateByPrimaryKeySelective(UserDO record);
61 | }
--------------------------------------------------------------------------------
/elastic-dal/src/main/java/com/leno/elastic/dal/mapper/ext/UserExtMapper.java:
--------------------------------------------------------------------------------
1 | package com.leno.elastic.dal.mapper.ext;
2 |
3 | import com.leno.elastic.dal.mapper.UserMapper;
4 | import org.apache.ibatis.annotations.Mapper;
5 | import org.springframework.stereotype.Repository;
6 |
7 | /**
8 | * MyBatis Ext Mapper for User.
9 | */
10 |
11 | @Mapper
12 | @Repository
13 | public interface UserExtMapper extends UserMapper {
14 |
15 | }
--------------------------------------------------------------------------------
/elastic-dal/src/main/java/com/leno/elastic/dal/model/UserDO.java:
--------------------------------------------------------------------------------
1 | package com.leno.elastic.dal.model;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 | import lombok.Data;
6 |
7 | @Data
8 | public class UserDO implements Serializable {
9 |
10 | private static final long serialVersionUID = 1L;
11 |
12 | /**
13 | * 主键
14 | * user.user_id
15 | */
16 | private Long userId;
17 |
18 | /**
19 | * 用户名
20 | * user.user_name
21 | */
22 | private String userName;
23 |
24 | /**
25 | * 登录名
26 | * user.login_name
27 | */
28 | private String loginName;
29 |
30 | /**
31 | * 密码
32 | * user.login_pwd
33 | */
34 | private String loginPwd;
35 |
36 | /**
37 | * 状态
38 | * user.status
39 | */
40 | private Integer status;
41 |
42 | /**
43 | *
44 | * user.gmt_create
45 | */
46 | private Date gmtCreate;
47 |
48 | /**
49 | *
50 | * user.gmt_modified
51 | */
52 | private Date gmtModified;
53 |
54 | }
--------------------------------------------------------------------------------
/elastic-dal/src/main/java/com/leno/elastic/dal/query/UserQuery.java:
--------------------------------------------------------------------------------
1 | package com.leno.elastic.dal.query;
2 |
3 |
4 | import com.leno.elastic.dal.common.BaseCriteria;
5 | import com.leno.elastic.dal.common.BaseQuery;
6 | import org.apache.commons.lang.builder.ReflectionToStringBuilder;
7 | import org.apache.commons.lang.builder.ToStringStyle;
8 |
9 | import java.io.Serializable;
10 |
11 | import java.util.Date;
12 | import java.util.List;
13 |
14 | public class UserQuery extends BaseQuery implements Serializable {
15 | private static final long serialVersionUID = 1L;
16 |
17 | public UserQuery() {
18 | super();
19 | }
20 |
21 | public Criteria or() {
22 | Criteria criteria = createCriteriaInternal();
23 | super.oredCriteria.add(criteria);
24 | return criteria;
25 | }
26 |
27 | public Criteria createCriteria() {
28 | Criteria criteria = createCriteriaInternal();
29 | if (oredCriteria.size() == 0) {
30 | oredCriteria.add(criteria);
31 | }
32 | return criteria;
33 | }
34 |
35 | protected Criteria createCriteriaInternal() {
36 | Criteria criteria = new Criteria();
37 | return criteria;
38 | }
39 |
40 | /**
41 | * This class corresponds to the database table user
42 | */
43 | protected abstract static class GeneratedCriteria extends BaseCriteria {
44 |
45 | protected GeneratedCriteria() {
46 | super();
47 | }
48 |
49 | public Criteria andUserIdIsNull() {
50 | addCriterion("user_id is null");
51 | return (Criteria) this;
52 | }
53 |
54 | public Criteria andUserIdIsNotNull() {
55 | addCriterion("user_id is not null");
56 | return (Criteria) this;
57 | }
58 |
59 | public Criteria andUserIdEqualTo(Long value) {
60 | addCriterion("user_id =", value, "id");
61 | return (Criteria) this;
62 | }
63 |
64 | public Criteria andUserIdNotEqualTo(Long value) {
65 | addCriterion("user_id <>", value, "id");
66 | return (Criteria) this;
67 | }
68 |
69 | public Criteria anUserIdGreaterThan(Long value) {
70 | addCriterion("user_id >", value, "id");
71 | return (Criteria) this;
72 | }
73 |
74 | public Criteria andUserIdGreaterThanOrEqualTo(Long value) {
75 | addCriterion("user_id >=", value, "id");
76 | return (Criteria) this;
77 | }
78 |
79 | public Criteria andUserIdLessThan(Long value) {
80 | addCriterion("user_id <", value, "id");
81 | return (Criteria) this;
82 | }
83 |
84 | public Criteria andUserIdLessThanOrEqualTo(Long value) {
85 | addCriterion("user_id <=", value, "id");
86 | return (Criteria) this;
87 | }
88 |
89 | public Criteria andUserIdIn(List values) {
90 | addCriterion("user_id in", values, "id");
91 | return (Criteria) this;
92 | }
93 |
94 | public Criteria andUserIdNotIn(List values) {
95 | addCriterion("user_id not in", values, "id");
96 | return (Criteria) this;
97 | }
98 |
99 | public Criteria andUserIdBetween(Long value1, Long value2) {
100 | addCriterion("user_id between", value1, value2, "id");
101 | return (Criteria) this;
102 | }
103 |
104 | public Criteria andUserIdNotBetween(Long value1, Long value2) {
105 | addCriterion("user_id not between", value1, value2, "id");
106 | return (Criteria) this;
107 | }
108 |
109 | public Criteria andGmtCreateIsNull() {
110 | addCriterion("gmt_create is null");
111 | return (Criteria) this;
112 | }
113 |
114 | public Criteria andGmtCreateIsNotNull() {
115 | addCriterion("gmt_create is not null");
116 | return (Criteria) this;
117 | }
118 |
119 | public Criteria andGmtCreateEqualTo(Date value) {
120 | addCriterion("gmt_create =", value, "gmtCreate");
121 | return (Criteria) this;
122 | }
123 |
124 | public Criteria andGmtCreateNotEqualTo(Date value) {
125 | addCriterion("gmt_create <>", value, "gmtCreate");
126 | return (Criteria) this;
127 | }
128 |
129 | public Criteria andGmtCreateGreaterThan(Date value) {
130 | addCriterion("gmt_create >", value, "gmtCreate");
131 | return (Criteria) this;
132 | }
133 |
134 | public Criteria andGmtCreateGreaterThanOrEqualTo(Date value) {
135 | addCriterion("gmt_create >=", value, "gmtCreate");
136 | return (Criteria) this;
137 | }
138 |
139 | public Criteria andGmtCreateLessThan(Date value) {
140 | addCriterion("gmt_create <", value, "gmtCreate");
141 | return (Criteria) this;
142 | }
143 |
144 | public Criteria andGmtCreateLessThanOrEqualTo(Date value) {
145 | addCriterion("gmt_create <=", value, "gmtCreate");
146 | return (Criteria) this;
147 | }
148 |
149 | public Criteria andGmtCreateIn(List values) {
150 | addCriterion("gmt_create in", values, "gmtCreate");
151 | return (Criteria) this;
152 | }
153 |
154 | public Criteria andGmtCreateNotIn(List values) {
155 | addCriterion("gmt_create not in", values, "gmtCreate");
156 | return (Criteria) this;
157 | }
158 |
159 | public Criteria andGmtCreateBetween(Date value1, Date value2) {
160 | addCriterion("gmt_create between", value1, value2, "gmtCreate");
161 | return (Criteria) this;
162 | }
163 |
164 | public Criteria andGmtCreateNotBetween(Date value1, Date value2) {
165 | addCriterion("gmt_create not between", value1, value2, "gmtCreate");
166 | return (Criteria) this;
167 | }
168 |
169 | public Criteria andGmtModifiedIsNull() {
170 | addCriterion("gmt_modified is null");
171 | return (Criteria) this;
172 | }
173 |
174 | public Criteria andGmtModifiedIsNotNull() {
175 | addCriterion("gmt_modified is not null");
176 | return (Criteria) this;
177 | }
178 |
179 | public Criteria andGmtModifiedEqualTo(Date value) {
180 | addCriterion("gmt_modified =", value, "gmtModified");
181 | return (Criteria) this;
182 | }
183 |
184 | public Criteria andGmtModifiedNotEqualTo(Date value) {
185 | addCriterion("gmt_modified <>", value, "gmtModified");
186 | return (Criteria) this;
187 | }
188 |
189 | public Criteria andGmtModifiedGreaterThan(Date value) {
190 | addCriterion("gmt_modified >", value, "gmtModified");
191 | return (Criteria) this;
192 | }
193 |
194 | public Criteria andGmtModifiedGreaterThanOrEqualTo(Date value) {
195 | addCriterion("gmt_modified >=", value, "gmtModified");
196 | return (Criteria) this;
197 | }
198 |
199 | public Criteria andGmtModifiedLessThan(Date value) {
200 | addCriterion("gmt_modified <", value, "gmtModified");
201 | return (Criteria) this;
202 | }
203 |
204 | public Criteria andGmtModifiedLessThanOrEqualTo(Date value) {
205 | addCriterion("gmt_modified <=", value, "gmtModified");
206 | return (Criteria) this;
207 | }
208 |
209 | public Criteria andGmtModifiedIn(List values) {
210 | addCriterion("gmt_modified in", values, "gmtModified");
211 | return (Criteria) this;
212 | }
213 |
214 | public Criteria andGmtModifiedNotIn(List values) {
215 | addCriterion("gmt_modified not in", values, "gmtModified");
216 | return (Criteria) this;
217 | }
218 |
219 | public Criteria andGmtModifiedBetween(Date value1, Date value2) {
220 | addCriterion("gmt_modified between", value1, value2, "gmtModified");
221 | return (Criteria) this;
222 | }
223 |
224 | public Criteria andGmtModifiedNotBetween(Date value1, Date value2) {
225 | addCriterion("gmt_modified not between", value1, value2, "gmtModified");
226 | return (Criteria) this;
227 | }
228 |
229 | public Criteria andUserNameIsNull() {
230 | addCriterion("user_name is null");
231 | return (Criteria) this;
232 | }
233 |
234 | public Criteria andUserNameIsNotNull() {
235 | addCriterion("user_name is not null");
236 | return (Criteria) this;
237 | }
238 |
239 | public Criteria andUserNameEqualTo(String value) {
240 | addCriterion("user_name =", value, "userName");
241 | return (Criteria) this;
242 | }
243 |
244 | public Criteria andUserNameNotEqualTo(String value) {
245 | addCriterion("user_name <>", value, "userName");
246 | return (Criteria) this;
247 | }
248 |
249 | public Criteria andUserNameGreaterThan(String value) {
250 | addCriterion("user_name >", value, "userName");
251 | return (Criteria) this;
252 | }
253 |
254 | public Criteria andUserNameGreaterThanOrEqualTo(String value) {
255 | addCriterion("user_name >=", value, "userName");
256 | return (Criteria) this;
257 | }
258 |
259 | public Criteria andUserNameLessThan(String value) {
260 | addCriterion("user_name <", value, "userName");
261 | return (Criteria) this;
262 | }
263 |
264 | public Criteria andUserNameLessThanOrEqualTo(String value) {
265 | addCriterion("user_name <=", value, "userName");
266 | return (Criteria) this;
267 | }
268 |
269 | public Criteria andUserNameLike(String value) {
270 | addCriterion("user_name like", value, "userName");
271 | return (Criteria) this;
272 | }
273 |
274 | public Criteria andUserNameNotLike(String value) {
275 | addCriterion("user_name not like", value, "userName");
276 | return (Criteria) this;
277 | }
278 |
279 | public Criteria andUserNameIn(List values) {
280 | addCriterion("user_name in", values, "userName");
281 | return (Criteria) this;
282 | }
283 |
284 | public Criteria andUserNameNotIn(List values) {
285 | addCriterion("user_name not in", values, "userName");
286 | return (Criteria) this;
287 | }
288 |
289 | public Criteria andUserNameBetween(String value1, String value2) {
290 | addCriterion("user_name between", value1, value2, "userName");
291 | return (Criteria) this;
292 | }
293 |
294 | public Criteria andUserNameNotBetween(String value1, String value2) {
295 | addCriterion("user_name not between", value1, value2, "userName");
296 | return (Criteria) this;
297 | }
298 |
299 | public Criteria andLoginNameIsNull() {
300 | addCriterion("login_name is null");
301 | return (Criteria) this;
302 | }
303 |
304 | public Criteria andLoginNameIsNotNull() {
305 | addCriterion("login_name is not null");
306 | return (Criteria) this;
307 | }
308 |
309 | public Criteria andLoginNameEqualTo(String value) {
310 | addCriterion("login_name =", value, "loginName");
311 | return (Criteria) this;
312 | }
313 |
314 | public Criteria andLoginNameNotEqualTo(String value) {
315 | addCriterion("login_name <>", value, "loginName");
316 | return (Criteria) this;
317 | }
318 |
319 | public Criteria andLoginNameGreaterThan(String value) {
320 | addCriterion("login_name >", value, "loginName");
321 | return (Criteria) this;
322 | }
323 |
324 | public Criteria andLoginNameGreaterThanOrEqualTo(String value) {
325 | addCriterion("login_name >=", value, "loginName");
326 | return (Criteria) this;
327 | }
328 |
329 | public Criteria andLoginNameLessThan(String value) {
330 | addCriterion("login_name <", value, "loginName");
331 | return (Criteria) this;
332 | }
333 |
334 | public Criteria andLoginNameLessThanOrEqualTo(String value) {
335 | addCriterion("login_name <=", value, "loginName");
336 | return (Criteria) this;
337 | }
338 |
339 | public Criteria andLoginNameLike(String value) {
340 | addCriterion("login_name like", value, "loginName");
341 | return (Criteria) this;
342 | }
343 |
344 | public Criteria andLoginNameNotLike(String value) {
345 | addCriterion("login_name not like", value, "loginName");
346 | return (Criteria) this;
347 | }
348 |
349 | public Criteria andLoginNameIn(List values) {
350 | addCriterion("login_name in", values, "loginName");
351 | return (Criteria) this;
352 | }
353 |
354 | public Criteria andLoginNameNotIn(List values) {
355 | addCriterion("login_name not in", values, "loginName");
356 | return (Criteria) this;
357 | }
358 |
359 | public Criteria andLoginNameBetween(String value1, String value2) {
360 | addCriterion("login_name between", value1, value2, "loginName");
361 | return (Criteria) this;
362 | }
363 |
364 | public Criteria andLoginNameNotBetween(String value1, String value2) {
365 | addCriterion("login_name not between", value1, value2, "loginName");
366 | return (Criteria) this;
367 | }
368 |
369 | public Criteria andLoginPwdIsNull() {
370 | addCriterion("login_pwd is null");
371 | return (Criteria) this;
372 | }
373 |
374 | public Criteria andLoginPwdIsNotNull() {
375 | addCriterion("login_pwd is not null");
376 | return (Criteria) this;
377 | }
378 |
379 | public Criteria andLoginPwdEqualTo(String value) {
380 | addCriterion("login_pwd =", value, "loginPwd");
381 | return (Criteria) this;
382 | }
383 |
384 | public Criteria andLoginPwdNotEqualTo(String value) {
385 | addCriterion("login_pwd <>", value, "loginPwd");
386 | return (Criteria) this;
387 | }
388 |
389 | public Criteria andLoginPwdGreaterThan(String value) {
390 | addCriterion("login_pwd >", value, "loginPwd");
391 | return (Criteria) this;
392 | }
393 |
394 | public Criteria andLoginPwdGreaterThanOrEqualTo(String value) {
395 | addCriterion("login_pwd >=", value, "loginPwd");
396 | return (Criteria) this;
397 | }
398 |
399 | public Criteria andLoginPwdLessThan(String value) {
400 | addCriterion("login_pwd <", value, "loginPwd");
401 | return (Criteria) this;
402 | }
403 |
404 | public Criteria andLoginPwdLessThanOrEqualTo(String value) {
405 | addCriterion("login_pwd <=", value, "loginPwd");
406 | return (Criteria) this;
407 | }
408 |
409 | public Criteria andLoginPwdLike(String value) {
410 | addCriterion("login_pwd like", value, "loginPwd");
411 | return (Criteria) this;
412 | }
413 |
414 | public Criteria andLoginPwdNotLike(String value) {
415 | addCriterion("login_pwd not like", value, "loginPwd");
416 | return (Criteria) this;
417 | }
418 |
419 | public Criteria andLoginPwdIn(List values) {
420 | addCriterion("login_pwd in", values, "loginPwd");
421 | return (Criteria) this;
422 | }
423 |
424 | public Criteria andLoginPwdNotIn(List values) {
425 | addCriterion("login_pwd not in", values, "loginPwd");
426 | return (Criteria) this;
427 | }
428 |
429 | public Criteria andLoginPwdBetween(String value1, String value2) {
430 | addCriterion("login_pwd between", value1, value2, "loginPwd");
431 | return (Criteria) this;
432 | }
433 |
434 | public Criteria andLoginPwdNotBetween(String value1, String value2) {
435 | addCriterion("login_pwd not between", value1, value2, "loginPwd");
436 | return (Criteria) this;
437 | }
438 |
439 | public Criteria andStatusIsNull() {
440 | addCriterion("status is null");
441 | return (Criteria) this;
442 | }
443 |
444 | public Criteria andStatusIsNotNull() {
445 | addCriterion("status is not null");
446 | return (Criteria) this;
447 | }
448 |
449 | public Criteria andStatusEqualTo(Integer value) {
450 | addCriterion("status =", value, "status");
451 | return (Criteria) this;
452 | }
453 |
454 | public Criteria andStatusNotEqualTo(Integer value) {
455 | addCriterion("status <>", value, "status");
456 | return (Criteria) this;
457 | }
458 |
459 | public Criteria andStatusGreaterThan(Integer value) {
460 | addCriterion("status >", value, "status");
461 | return (Criteria) this;
462 | }
463 |
464 | public Criteria andStatusGreaterThanOrEqualTo(Integer value) {
465 | addCriterion("status >=", value, "status");
466 | return (Criteria) this;
467 | }
468 |
469 | public Criteria andStatusLessThan(Integer value) {
470 | addCriterion("status <", value, "status");
471 | return (Criteria) this;
472 | }
473 |
474 | public Criteria andStatusLessThanOrEqualTo(Integer value) {
475 | addCriterion("status <=", value, "status");
476 | return (Criteria) this;
477 | }
478 |
479 | public Criteria andStatusLike(Integer value) {
480 | addCriterion("status like", value, "status");
481 | return (Criteria) this;
482 | }
483 |
484 | public Criteria andStatusNotLike(Integer value) {
485 | addCriterion("status not like", value, "status");
486 | return (Criteria) this;
487 | }
488 |
489 | public Criteria andStatusIn(List values) {
490 | addCriterion("status in", values, "status");
491 | return (Criteria) this;
492 | }
493 |
494 | public Criteria andStatusNotIn(List values) {
495 | addCriterion("status not in", values, "status");
496 | return (Criteria) this;
497 | }
498 |
499 | public Criteria andStatusBetween(Integer value1, Integer value2) {
500 | addCriterion("status between", value1, value2, "status");
501 | return (Criteria) this;
502 | }
503 |
504 | public Criteria andStatusNotBetween(Integer value1, Integer value2) {
505 | addCriterion("status not between", value1, value2, "status");
506 | return (Criteria) this;
507 | }
508 |
509 | }
510 |
511 | /**
512 | * This class corresponds to the database table user
513 | */
514 | public static class Criteria extends GeneratedCriteria{
515 | protected Criteria() {
516 | super();
517 | }
518 | }
519 |
520 |
521 |
522 | @Override
523 | public String toString(){
524 | return ReflectionToStringBuilder.toString(this, ToStringStyle.DEFAULT_STYLE);
525 | }
526 | }
--------------------------------------------------------------------------------
/elastic-dal/src/main/java/com/leno/elastic/manager/UserManager.java:
--------------------------------------------------------------------------------
1 | package com.leno.elastic.manager;
2 |
3 | import com.leno.elastic.dal.common.PageResult;
4 | import com.leno.elastic.dal.model.UserDO;
5 | import com.leno.elastic.dal.query.UserQuery;
6 |
7 | import java.util.List;
8 |
9 |
10 | /**
11 | * Manager for User.
12 | */
13 | public interface UserManager {
14 | /**
15 | * query count by query condition.
16 | */
17 | int countByQuery(UserQuery query);
18 |
19 | /**
20 | * delete by query condition.
21 | */
22 | int deleteByQuery(UserQuery query);
23 |
24 | /**
25 | * delete by primary key.
26 | */
27 | int deleteByPrimaryKey(UserDO record);
28 |
29 | /**
30 | * insert selective.
31 | */
32 | long insertSelective(UserDO record);
33 |
34 | /**
35 | * select by query condition.
36 | */
37 | List selectByQuery(UserQuery query);
38 |
39 |
40 | /**
41 | * select by query condition with page.
42 | */
43 | PageResult selectByQueryWithPage(UserQuery query);
44 |
45 | /**
46 | * select by primary key.
47 | */
48 | UserDO selectByPrimaryKey(Long id);
49 |
50 | /**
51 | * update by query condition selective.
52 | */
53 | int updateByQuerySelective( UserDO record, UserQuery query);
54 |
55 | /**
56 | * update by query condition.
57 | */
58 | int updateByQuery(UserDO record, UserQuery query);
59 |
60 | /**
61 | * update by primary key selective.
62 | */
63 | int updateByPrimaryKeySelective(UserDO record);
64 | }
--------------------------------------------------------------------------------
/elastic-dal/src/main/java/com/leno/elastic/manager/impl/UserManagerImpl.java:
--------------------------------------------------------------------------------
1 | package com.leno.elastic.manager.impl;
2 |
3 | import com.leno.elastic.dal.common.PageResult;
4 | import com.leno.elastic.dal.model.UserDO;
5 | import com.leno.elastic.dal.query.UserQuery;
6 | import com.leno.elastic.dal.mapper.ext.UserExtMapper;
7 | import com.leno.elastic.manager.UserManager;
8 |
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.stereotype.Component;
11 |
12 | import java.util.List;
13 |
14 |
15 | /**
16 | * Manager for User.
17 | */
18 |
19 | @Component
20 | public class UserManagerImpl implements UserManager{
21 |
22 |
23 | @Autowired
24 | protected UserExtMapper userExtMapper;
25 | /**
26 | * query count by query condition.
27 | */
28 | @Override
29 | public int countByQuery(UserQuery query){
30 | return userExtMapper.countByQuery(query);
31 | }
32 |
33 | /**
34 | * delete by query condition.
35 | */
36 | @Override
37 | public int deleteByQuery(UserQuery query){
38 | return userExtMapper.deleteByQuery(query);
39 | }
40 |
41 | /**
42 | * delete by primary key.
43 | */
44 | @Override
45 | public int deleteByPrimaryKey(UserDO record){
46 | return userExtMapper.deleteByPrimaryKey(record);
47 | }
48 |
49 | /**
50 | * insert selective.
51 | */
52 | @Override
53 | public long insertSelective(UserDO record){
54 | return userExtMapper.insertSelective(record);
55 | }
56 |
57 | /**
58 | * select by query condition.
59 | */
60 | @Override
61 | public List selectByQuery(UserQuery query){
62 | return userExtMapper.selectByQuery(query);
63 | }
64 |
65 | /**
66 | * select by query condition with page.
67 | */
68 | @Override
69 | public PageResult selectByQueryWithPage(UserQuery query) {
70 | PageResult result = new PageResult();
71 | result.setPageSize(query.getPageSize());
72 | result.setPageNo(query.getPageNo());
73 | result.setTotalCount(this.countByQuery(query));
74 | result.setResult(this.selectByQuery(query));
75 | return result;
76 | }
77 |
78 | /**
79 | * select by primary key.
80 | */
81 | @Override
82 | public UserDO selectByPrimaryKey(Long id){
83 | return userExtMapper.selectByPrimaryKey(id);
84 | }
85 |
86 | /**
87 | * update by query condition selective.
88 | */
89 | @Override
90 | public int updateByQuerySelective( UserDO record, UserQuery query){
91 | return userExtMapper.updateByQuerySelective(record, query);
92 | }
93 |
94 | /**
95 | * update by query condition.
96 | */
97 | @Override
98 | public int updateByQuery( UserDO record, UserQuery query){
99 |
100 | return userExtMapper.updateByQuery(record, query);
101 | }
102 |
103 | /**
104 | * update by primary key selective.
105 | */
106 | @Override
107 | public int updateByPrimaryKeySelective(UserDO record){
108 | return userExtMapper.updateByPrimaryKeySelective(record);
109 | }
110 | }
--------------------------------------------------------------------------------
/elastic-dal/src/main/resources/mapper/UserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | and ${criterion.condition}
23 |
24 |
25 | and ${criterion.condition} #{criterion.value}
26 |
27 |
28 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
29 |
30 |
31 | and ${criterion.condition}
32 |
33 | #{listItem}
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | and ${criterion.condition}
53 |
54 |
55 | and ${criterion.condition} #{criterion.value}
56 |
57 |
58 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
59 |
60 |
61 | and ${criterion.condition}
62 |
63 | #{listItem}
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | user_id,gmt_create,gmt_modified,user_name,login_name,login_pwd,status
76 |
77 |
78 |
93 |
94 |
97 |
98 |
99 | delete from user where user_id = #{userId,jdbcType=BIGINT}
100 |
101 |
102 |
103 | delete from user
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 | SELECT LAST_INSERT_ID()
112 |
113 | insert into user
114 |
115 | gmt_create,gmt_modified,
116 |
117 | user_name,
118 |
119 |
120 | login_name,
121 |
122 |
123 | login_pwd,
124 |
125 |
126 | status,
127 |
128 |
129 |
130 | now(),now(),
131 |
132 | #{userName,jdbcType=VARCHAR},
133 |
134 |
135 | #{loginName,jdbcType=VARCHAR},
136 |
137 |
138 | #{loginPwd,jdbcType=VARCHAR},
139 |
140 |
141 | #{status,jdbcType=INTEGER},
142 |
143 |
144 |
145 |
146 |
152 |
153 |
154 | update user
155 |
156 | gmt_modified=now(),
157 |
158 | user_name = #{record.userName,jdbcType=VARCHAR},
159 |
160 |
161 | login_name = #{record.loginName,jdbcType=VARCHAR},
162 |
163 |
164 | login_pwd = #{record.loginPwd,jdbcType=VARCHAR},
165 |
166 |
167 | status = #{record.status,jdbcType=INTEGER},
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 | update user set
177 | user_name = #{record.userName,jdbcType=VARCHAR},
178 | login_name = #{record.loginName,jdbcType=VARCHAR},
179 | login_pwd = #{record.loginPwd,jdbcType=VARCHAR},
180 | status = #{record.status,jdbcType=INTEGER},
181 | gmt_modified = now()
182 |
183 |
184 |
185 |
186 |
187 |
188 | update user
189 |
190 | gmt_modified=now(),
191 |
192 | user_name = #{userName,jdbcType=VARCHAR},
193 |
194 |
195 | login_name = #{loginName,jdbcType=VARCHAR},
196 |
197 |
198 | login_pwd = #{loginPwd,jdbcType=VARCHAR},
199 |
200 |
201 | status = #{status,jdbcType=INTEGER},
202 |
203 |
204 | where user_id = #{userId,jdbcType=BIGINT}
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
--------------------------------------------------------------------------------
/elastic-dal/src/main/resources/mapper/ext/UserExtMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/elastic-generator/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | elastic-generator
7 | jar
8 |
9 | mybatis generator
10 |
11 |
12 | com.leno
13 | elastic-demo
14 | 1.0-SNAPSHOT
15 |
16 |
17 |
18 |
19 | org.apache.commons
20 | commons-lang3
21 |
22 |
23 | commons-collections
24 | commons-collections
25 |
26 |
27 | mysql
28 | mysql-connector-java
29 |
30 |
31 | org.apache.velocity
32 | velocity
33 |
34 |
35 | commons-io
36 | commons-io
37 |
38 |
39 | com.google.guava
40 | guava
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/elastic-generator/src/main/java/com/leno/mybatisgen/ColumnInfo.java:
--------------------------------------------------------------------------------
1 | package com.leno.mybatisgen;
2 |
3 | /**
4 | * Created by houenxun on 16/3/14.
5 | */
6 | public class ColumnInfo {
7 | private String name;
8 | private String calssName;
9 | private String typeName;
10 | private String precision;
11 | private String scale;
12 |
13 | public String getName() {
14 | return name;
15 | }
16 |
17 | public void setName(String name) {
18 | this.name = name;
19 | }
20 |
21 | public String getCalssName() {
22 | return calssName;
23 | }
24 |
25 | public void setCalssName(String calssName) {
26 | this.calssName = calssName;
27 | }
28 |
29 | public String getTypeName() {
30 | return typeName;
31 | }
32 |
33 | public void setTypeName(String typeName) {
34 | this.typeName = typeName;
35 | }
36 |
37 | public String getPrecision() {
38 | return precision;
39 | }
40 |
41 | public void setPrecision(String precision) {
42 | this.precision = precision;
43 | }
44 |
45 | public String getScale() {
46 | return scale;
47 | }
48 |
49 | public void setScale(String scale) {
50 | this.scale = scale;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/elastic-generator/src/main/java/com/leno/mybatisgen/Main.java:
--------------------------------------------------------------------------------
1 | package com.leno.mybatisgen;
2 |
3 |
4 | import org.apache.commons.collections.CollectionUtils;
5 |
6 | import java.net.URL;
7 | import java.nio.charset.StandardCharsets;
8 | import java.nio.file.Files;
9 | import java.nio.file.Paths;
10 | import java.util.List;
11 |
12 | /**
13 | * mybatisgen main.
14 | *
15 | * @author bleedfly.
16 | */
17 | public class Main {
18 |
19 | public static void main(String[] args) throws Exception {
20 | try {
21 |
22 | // 需要生成的表配置文件在generate_tables.config文件中,每每行一个表名
23 | URL url = Thread.currentThread().getContextClassLoader().getResource("generate_tables.config");
24 | if (url != null) {
25 | String path = url.getPath();
26 | List tables = Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8);
27 | if (CollectionUtils.isEmpty(tables)) {
28 | System.out.println("generate_tables.config is empty.");
29 | return;
30 | }
31 | MyBatisGenCore.batchGen(tables);
32 | System.out.print("all done");
33 | }
34 | } catch (Exception e) {
35 | e.printStackTrace();
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/elastic-generator/src/main/java/com/leno/mybatisgen/MyBatisGenConst.java:
--------------------------------------------------------------------------------
1 | package com.leno.mybatisgen;
2 |
3 | import java.io.File;
4 |
5 | @SuppressWarnings("all")
6 | public class MyBatisGenConst {
7 |
8 | /**
9 | * 项目名称
10 | */
11 | private static final String PROJECT_NAME = "elastic";
12 |
13 | /**
14 | * 组
15 | */
16 | private static final String GROUP_NAME = "leno";
17 |
18 | // module name
19 | private static final String MODULE_NAME = PROJECT_NAME + "-dal";
20 | // group name
21 | private static final String MODULE_GROUP_NAME = "com." + GROUP_NAME + "." + PROJECT_NAME;
22 | // 工作目录
23 | public static final String WORK_DIR = System.getProperty("user.dir") + File.separator;
24 | // module目录
25 | private static final String MODULE_DIR = WORK_DIR + MODULE_NAME + File.separator;
26 | // src 目录
27 | private static final String MODULE_CODE_DIR = MODULE_DIR + "src/main/java/com" + File.separator + GROUP_NAME + File.separator + PROJECT_NAME + File.separator;
28 |
29 |
30 | // dal
31 | public static final String MAIN_PACKAGE = MODULE_GROUP_NAME + ".dal";
32 | public static final String DO_PACKAGE = MAIN_PACKAGE + ".model";
33 | public static final String QUERY_PACKAGE = MAIN_PACKAGE + ".query";
34 |
35 | // mapper
36 | public static final String MAPPER_PACKAGE = MAIN_PACKAGE + ".mapper";
37 | public static final String MAPPER_EXT_PACKAGE = MAPPER_PACKAGE + ".ext";
38 |
39 |
40 | // manager
41 | public static final String MANAGER_PACKAGE = MODULE_GROUP_NAME + ".manager";
42 | public static final String MANAGER_IMPL_PACKAGE = MANAGER_PACKAGE + ".impl";
43 |
44 |
45 | public static final String TABLE_PREFIX = "cc_";
46 | public static final String QUERY_PREFIX = "Query";
47 | public static final String MAPPER_SUFFIX = "Mapper";
48 | public static final String MANAGER_SUFFIX = "Manager";
49 | public static final String MANAGER_IMPL_SUFFIX = "ManagerImpl";
50 | public static final String MAPPER_EXT_SUFFIX = "ExtMapper";
51 | public static final String DO_SUFFIX = "DO";
52 |
53 |
54 | // mapper xml 输出目录
55 | public static final String MAPPER_XML_DIR = MODULE_DIR + "src/main/resources/mapper/";
56 | // mapper-ext xml 输出目录
57 | public static final String MAPPER_EXT_XML_DIR = MODULE_DIR + "src/main/resources/mapper/ext/";
58 | // do/model 输出目录
59 | public static final String MAPPER_DO_DIR = MODULE_CODE_DIR + "dal/model";
60 | // query 输出目录
61 | public static final String MAPPER_QUERY_DIR = MODULE_CODE_DIR + "dal/query";
62 | // mapper java 输出目录
63 | public static final String MAPPER_JAVA_DIR = MODULE_CODE_DIR + "dal/mapper";
64 |
65 | public static final String MANAGER_JAVA_DIR = MODULE_CODE_DIR + "manager";
66 | public static final String MANAGER_IMPL_JAVA_DIR = MANAGER_JAVA_DIR + "/impl";
67 |
68 | // mapper-ext java 输出目录
69 | public static final String MAPPER_EXT_JAVA_DIR = MODULE_CODE_DIR + "dal/mapper/ext";
70 | // java数据对象类模板
71 | public static final String DO_TEMPLATE = ClassLoader.getSystemResource("template/do.txt").getPath();// "resources/template/do.txt";
72 | // query 模板
73 | public static final String QUERY_TEMPLATE = ClassLoader.getSystemResource("template/query.txt").getPath();
74 | // sqlmap模板
75 | public static final String SQLMAP_TEMPLATE = ClassLoader.getSystemResource("template/sqlmap.txt").getPath();
76 | // mapper模板
77 | public static final String MAPPER_TEMPLATE = ClassLoader.getSystemResource("template/mapper.txt").getPath();
78 | // manager模板
79 | public static final String MANAGER_TEMPLATE = ClassLoader.getSystemResource("template/manager.txt").getPath();
80 | // manager impl 模板
81 | public static final String MANAGER_IMPL_TEMPLATE = ClassLoader.getSystemResource("template/managerImpl.txt").getPath();
82 |
83 | // mapper-ext模板
84 | public static final String MAPPER_EXT_TEMPLATE = ClassLoader.getSystemResource("template/mapper-ext.txt").getPath();
85 | // sqlmap-ext模板
86 | public static final String SQLMAP_EXT_TEMPLATE = ClassLoader.getSystemResource("template/sqlmap-ext.txt").getPath();
87 |
88 | public static final String COMMON_COLUMN_STR = "gmt_create,gmt_modified,";
89 |
90 | // jdbc result set metadata collumn name
91 | public static final String RSMD_COLUMN_NAME = "rsmdColumnName";
92 | public static final String RSMD_COLUMN_CLASS_NAME = "columnClassName";
93 | public static final String RSMD_COLUMN_TYPE_NAME = "columnTypeName";
94 | public static final String RSMD_COLUMN_PRECISION = "Precision";
95 | public static final String RSMD_COLUMN_SCALE = "Scale";
96 | public static final String RSMD_COLUMN_PRIMARY_KEY = "PrimaryKey";
97 | public static final String RSMD_COLUMN_REMARKS = "Remarks";
98 |
99 | public static final String COLUMN_NAME = "COLUMN_NAME";
100 |
101 | // velocity param
102 | public static final String VP_LIST = "list";
103 | public static final String VP_QUERY_PREFIX = "queryPrefix";
104 | public static final String VP_DO_SUFFIX = "doSuffix";
105 | public static final String VP_MAPPER_SUFFIX = "mapperSuffix";
106 | public static final String VP_MANAGER_SUFFIX = "managerSuffix";
107 |
108 | public static final String VP_MANAGER_IMPL_SUFFIX = "managerImplSuffix";
109 | public static final String VP_MAPPER_EXT_SUFFIX = "extMapperSuffix";
110 | public static final String VP_CLASS_NAME = "className";
111 | public static final String VP_MAPPER_PROPERTY_NAME = "mapperPropertyName";
112 | public static final String VP_MAIN_PACKAGE = "mainPackage";
113 | public static final String VP_DO_PACKAGE = "doPackage";
114 | public static final String VP_QUERY_PACKAGE = "queryPackage";
115 | public static final String VP_MAPPER_PACKAGE = "mapperPackage";
116 | public static final String VP_MANAGER_PACKAGE = "managerPackage";
117 | public static final String VP_MANAGER_IMPL_PACKAGE = "managerImplPackage";
118 | public static final String VP_MAPPER_EXT_PACKAGE = "mapperExtPackage";
119 | public static final String VP_JAVA_TYPE = "javaType";
120 | public static final String VP_PROP_NAME = "propName";
121 | public static final String VP_GET_METHOD = "getMethod";
122 |
123 | public static final String VP_SET_METHOD = "setMethod";
124 | public static final String VP_COLUMN_NAME = "columnName";
125 | public static final String VP_COLUMN_REMARKS = "columnRemarks";
126 | public static final String VP_TABLE_NAME = "tableName";
127 | public static final String VP_JDBC_TYPE = "jdbcType";
128 | public static final String VP_COLS = "cols";
129 | public static final String VP_COLS_WITHOUT_COMMON_COLUMNS = "colsWithoutCommColumns";
130 | public static final String VP_SERIAL_VERSION_UID = "serialVersionUID";
131 |
132 | public static final String VP_SERIAL_VERSION_UID2 = "serialVersionUID2";
133 | public static final String VP_PRIMARY_KEY = "primaryKey";
134 | public static final String VP_PROP_PRIMARY_KEY = "propPrimaryKey";
135 |
136 | //分库分表 表后缀regex
137 | public static final String SHARDING_SUFFIX_REG = "_[\\d]{4}";
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/elastic-generator/src/main/java/com/leno/mybatisgen/MyBatisGenCore.java:
--------------------------------------------------------------------------------
1 | package com.leno.mybatisgen;
2 |
3 | import org.apache.commons.lang3.StringUtils;
4 | import org.apache.commons.lang3.math.NumberUtils;
5 | import org.apache.velocity.VelocityContext;
6 | import org.apache.velocity.app.Velocity;
7 |
8 | import java.io.*;
9 | import java.nio.file.Files;
10 | import java.nio.file.Path;
11 | import java.nio.file.Paths;
12 | import java.sql.Connection;
13 | import java.sql.ResultSet;
14 | import java.sql.Statement;
15 | import java.sql.DatabaseMetaData;
16 | import java.sql.ResultSetMetaData;
17 | import java.sql.SQLException;
18 | import java.sql.DriverManager;
19 | import java.util.ArrayList;
20 | import java.util.HashMap;
21 | import java.util.List;
22 | import java.util.Map;
23 | import java.util.regex.Pattern;
24 | import java.util.Properties;
25 |
26 | /**
27 | * mybatisgen generate core.
28 | *
29 | * @author bleedfly.
30 | */
31 | class MyBatisGenCore {
32 |
33 | /**
34 | * 根据表名获取字段信息
35 | *
36 | * @param cn 数据库连接
37 | * @param table 数据库表名
38 | * @return 列infoList
39 | * @throws Exception 抛出错误
40 | */
41 | private static List