├── .gitignore
├── README.md
├── doc
└── application-dev.yml
├── pom.xml
├── s.sh
├── soulcoder-core
├── pom.xml
└── src
│ └── main
│ └── java
│ └── tech
│ └── soulcoder
│ └── core
│ ├── Swagger2Config.java
│ ├── WebMVCConfig.java
│ └── dbconfig
│ ├── DruidConfigSoul.java
│ ├── DruidServletConfig.java
│ ├── MyBatisConfigSoul.java
│ └── MybatisPageHelperConfig.java
├── soulcoder-dao
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── tech
│ │ │ └── soulcoder
│ │ │ └── dao
│ │ │ ├── mapper
│ │ │ └── generator
│ │ │ │ ├── SoulUserDTOMapper.java
│ │ │ │ └── SoulUserMapper.java
│ │ │ └── pojo
│ │ │ └── generator
│ │ │ ├── SoulUser.java
│ │ │ ├── SoulUserDTO.java
│ │ │ └── SoulUserDTOExample.java
│ └── resources
│ │ ├── mapper
│ │ └── generator
│ │ │ └── SoulUserMapper.xml
│ │ └── tech
│ │ └── soulcoder
│ │ └── dao
│ │ └── mapper
│ │ └── generator
│ │ └── SoulUserDTOMapper.xml
│ └── test
│ ├── java
│ └── tech
│ │ └── soulcoder
│ │ └── test
│ │ └── GeneratorMain.java
│ └── resources
│ ├── generator.properties.exmple
│ └── generator.xml
├── soulcoder-model
└── pom.xml
├── soulcoder-service
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── tech
│ │ └── soulcoder
│ │ └── service
│ │ ├── TestService.java
│ │ └── impl
│ │ └── TestServiceImpl.java
│ └── test
│ └── java
│ └── tech
│ └── soulcoder
│ └── test
│ └── MyTest.java
├── soulcoder-utils
├── pom.xml
└── src
│ └── main
│ └── java
│ └── tech
│ └── soulcoder
│ ├── IPUtils.java
│ ├── RedisOperation.java
│ ├── SqlHelper.java
│ ├── StringUtil.java
│ ├── entity
│ ├── Action.java
│ ├── Action2.java
│ ├── Action3.java
│ ├── Action4.java
│ ├── Action5.java
│ ├── ActionWithException.java
│ ├── ActionWithException2.java
│ ├── ActionWithException3.java
│ ├── ActionWithException4.java
│ ├── ActionWithException5.java
│ ├── EqualsFunc.java
│ ├── FilterFunc.java
│ ├── Func.java
│ ├── Func2.java
│ ├── Func3.java
│ ├── Func4.java
│ ├── Func5.java
│ ├── FuncWithException.java
│ ├── FuncWithException2.java
│ ├── FuncWithException3.java
│ ├── FuncWithException4.java
│ ├── FuncWithException5.java
│ ├── Optional.java
│ ├── Optional2.java
│ ├── Optional3.java
│ ├── Optional4.java
│ └── Optional5.java
│ ├── expection
│ ├── CommonException.java
│ ├── CommonResponseModel.java
│ └── ReturnCodeModel.java
│ └── log
│ ├── LogAop.java
│ └── LogAuto.java
└── soulcoder-web
├── .gitignore
├── pom.xml
└── src
├── main
├── java
│ └── tech
│ │ └── soulcoder
│ │ ├── StartApplication.java
│ │ └── web
│ │ └── TestController.java
└── resources
│ ├── application.yml
│ ├── logback-dev.xml
│ └── logback-prod.xml
└── test
└── java
└── tech
└── soulcoder
└── mytest
├── BaseTest.java
└── MyTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 | .idea
4 | *.iws
5 | *.iml
6 | *.ipr
7 | /logs
8 | /soulcoder-web/src/main/resources/application-dev.yml
9 | /soulcoder-web/src/main/resources/application-prod.yml
10 | .DS_Store
11 | /soulcoder-dao/src/test/resources/generator.properties
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | https://gitee.com/fengyunlucode/soulcoder/ github 提交太卡了,还是用码云吧哈哈
2 |
3 | # 使用
4 |
5 | ```
6 | # git 拉去最新分支代码
7 |
8 | git pull
9 | git branch zzb
10 | # 拷贝配置文件到指定目录
11 | cp /www/wwwroot/zzb.soulcoder.tech/application.yml /www/wwwroot/zzb.soulcoder.tech/soulcoder/soulcoder-web/src/main/resources/application.yml
12 | cp /www/wwwroot/zzb.soulcoder.tech/application-prod.yml /www/wwwroot/zzb.soulcoder.tech/soulcoder/soulcoder-web/src/main/resources/application-prod.yml
13 | mvn clean
14 | mvn package -Dmaven.test.skip=true
15 | # 启动
16 | cd /www/wwwroot/zzb.soulcoder.tech/soulcoder/soulcoder-web/target/
17 | nohup java -jar -Xms258m -Xmx258m soulcoder.jar &
18 |
19 | ```
20 |
21 | # 配置文件
22 |
23 | parent
24 |
25 | ```
26 |
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-maven-plugin
32 | 1.3.0.RELEASE
33 |
34 | tech.soulcoder.StartApplication
35 | ZIP
36 |
37 |
38 |
39 |
40 | repackage
41 |
42 |
43 |
46 |
47 |
48 |
49 |
50 |
51 | ```
52 |
53 | web
54 |
55 | ```
56 |
57 |
58 | soulcoder
59 |
60 |
61 | org.springframework.boot
62 | spring-boot-maven-plugin
63 | 1.3.0.RELEASE
64 |
65 |
66 |
67 | ```
68 |
--------------------------------------------------------------------------------
/doc/application-dev.yml:
--------------------------------------------------------------------------------
1 | # 示例配置文件 在正式使用的时候copy到 /soulcoder-web/src/main/resources/ 下面
2 | server:
3 | port: 10002
4 |
5 | #log
6 | logging:
7 | config : classpath:logback-dev.xml
8 | level:
9 | org:
10 | springframework:
11 | web : INFO
12 |
13 | spring:
14 | datasource:
15 | soul:
16 | url : jdbc:mysql://127.0.0.1:3306/soulcoder?autoReconnect=true&useCompression=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
17 | username : lala
18 | password : lalala
19 | initialSize : 5
20 | maxActive : 20
21 | minIdle : 1
22 | maxWait : 30000
23 | timeBetweenEvictionRunsMillis : 60000
24 | minEvictableIdleTimeMillis : 300000
25 | poolPreparedStatements : true
26 | maxPoolPreparedStatementPerConnectionSize : 20
27 | filters : stat, wall, config
28 | redis:
29 | database : 0
30 | host : 127.0.0.1
31 | port : 6379
32 | password : 123
33 | timeout : 5000
34 | pool :
35 | max-active : 8
36 | # 连接池最大阻塞等待时间(使用负值表示没有限制)
37 | max-wait : -1
38 | # 连接池中的最大空闲连接
39 | max-idle : 8
40 | # 连接池中的最小空闲连接
41 | min-idle : 0
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | tech.soulcoder
7 | soulcoder
8 | 0.0.1-SNAPSHOT
9 |
10 | soulcoder-web
11 | soulcoder-core
12 | soulcoder-service
13 | soulcoder-utils
14 | soulcoder-model
15 | soulcoder-dao
16 |
17 | pom
18 |
19 | soulcoder
20 | soulcoder project for Spring Boot
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-parent
25 | 2.0.2.RELEASE
26 |
27 |
28 |
29 |
30 | 4.12
31 | 1.0.29
32 | 1.2.3
33 | 1.7.7
34 | 3.1.0
35 | 1.5.7.RELEASE
36 | 1.2.28
37 | 5.0.0
38 | 3.4
39 |
40 | 4.4.1
41 | 4.1
42 |
43 | 4.0.3
44 | UTF-8
45 | UTF-8
46 | 1.8
47 |
48 |
49 |
50 |
51 |
52 | io.netty
53 | netty-all
54 | 4.1.25.Final
55 |
56 |
57 |
58 | org.mybatis.generator
59 | mybatis-generator-core
60 | 1.3.7
61 |
62 |
63 |
64 | org.mybatis.spring.boot
65 | mybatis-spring-boot-starter
66 | 1.3.2
67 |
68 |
69 | mysql
70 | mysql-connector-java
71 | runtime
72 |
73 |
74 |
75 | com.github.pagehelper
76 | pagehelper
77 | 5.1.3
78 |
79 |
80 |
81 | com.alibaba
82 | druid-spring-boot-starter
83 | 1.1.0
84 |
85 |
86 |
87 |
88 |
89 |
90 | org.springframework.boot
91 | spring-boot-starter-thymeleaf
92 |
93 |
94 | org.springframework.boot
95 | spring-boot-starter-web
96 |
97 |
98 | org.springframework.boot
99 | spring-boot-starter-data-redis
100 |
101 |
102 | org.springframework.boot
103 | spring-boot-starter-actuator
104 |
105 |
106 | org.springframework.boot
107 | spring-boot-starter-aop
108 |
109 |
110 | org.springframework.boot
111 | spring-boot-starter-logging
112 |
113 |
114 | org.projectlombok
115 | lombok
116 | true
117 |
118 |
119 | org.springframework.boot
120 | spring-boot-starter-test
121 | test
122 |
123 |
124 | javax.servlet
125 | javax.servlet-api
126 | ${servlet.version}
127 |
128 |
129 | junit
130 | junit
131 | ${junit.version}
132 |
133 |
134 | org.slf4j
135 | slf4j-api
136 | ${slf4j.version}
137 |
138 |
139 | ch.qos.logback
140 | logback-access
141 | ${logback.version}
142 |
143 |
144 | ch.qos.logback
145 | logback-core
146 | ${logback.version}
147 |
148 |
149 | ch.qos.logback
150 | logback-classic
151 | ${logback.version}
152 |
153 |
154 | com.alibaba
155 | fastjson
156 | ${fastjson.version}
157 |
158 |
159 | org.apache.commons
160 | commons-lang3
161 | ${common.version}
162 |
163 |
164 | org.apache.httpcomponents
165 | httpclient
166 | ${httpclient.version}
167 |
168 |
169 | org.apache.httpcomponents
170 | httpmime
171 | ${httpclient.version}
172 |
173 |
174 | org.apache.httpcomponents
175 | httpasyncclient
176 | ${httpasyncclient.version}
177 |
178 |
179 | cn.hutool
180 | hutool-all
181 | ${hutool-all.version}
182 |
183 |
184 | com.google.code.gson
185 | gson
186 | 2.8.4
187 |
188 |
189 |
190 | org.apache.poi
191 | poi
192 | 3.15
193 |
194 |
195 |
196 | org.apache.poi
197 | poi-ooxml
198 | 3.15
199 |
200 |
201 | io.springfox
202 | springfox-swagger2
203 | 2.2.2
204 |
205 |
206 | io.springfox
207 | springfox-swagger-ui
208 | 2.2.2
209 |
210 |
211 |
212 |
213 |
214 |
215 | org.springframework.boot
216 | spring-boot-maven-plugin
217 | 1.3.0.RELEASE
218 |
219 | tech.soulcoder.StartApplication
220 | ZIP
221 |
222 |
223 |
224 |
225 | repackage
226 |
227 |
228 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
--------------------------------------------------------------------------------
/s.sh:
--------------------------------------------------------------------------------
1 | # git 拉去最新分支代码
2 | git pull
3 | git branch zzb
4 | # 拷贝配置文件到指定目录
5 | cp /www/wwwroot/zzb.soulcoder.tech/application.yml /www/wwwroot/zzb.soulcoder.tech/soulcoder/soulcoder-web/src/main/resources/application.yml
6 | cp /www/wwwroot/zzb.soulcoder.tech/application-prod.yml /www/wwwroot/zzb.soulcoder.tech/soulcoder/soulcoder-web/src/main/resources/application-prod.yml
7 | mvn clean
8 | mvn package -Dmaven.test.skip=true
9 | # 启动
10 | cd /www/wwwroot/zzb.soulcoder.tech/soulcoder/soulcoder-web/target/
11 | nohup java -jar -Xms258m -Xmx258m soulcoder.jar &
12 |
13 |
14 |
--------------------------------------------------------------------------------
/soulcoder-core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | soulcoder
7 | tech.soulcoder
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | soulcoder-core
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/soulcoder-core/src/main/java/tech/soulcoder/core/Swagger2Config.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.core;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.ComponentScan;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
7 | import springfox.documentation.builders.ApiInfoBuilder;
8 | import springfox.documentation.builders.PathSelectors;
9 | import springfox.documentation.builders.RequestHandlerSelectors;
10 | import springfox.documentation.service.ApiInfo;
11 | import springfox.documentation.spi.DocumentationType;
12 | import springfox.documentation.spring.web.plugins.Docket;
13 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
14 |
15 | @Configuration
16 | @EnableWebMvc
17 | @EnableSwagger2
18 | @ComponentScan(basePackages = {"tech.soulcoder.**"})
19 | public class Swagger2Config {
20 |
21 | @Bean
22 | public Docket createRestApi() {
23 | return new Docket(DocumentationType.SWAGGER_2)
24 | .apiInfo(apiInfo())
25 | .select()
26 | .apis(RequestHandlerSelectors.basePackage("tech.soulcoder"))
27 | .paths(PathSelectors.any())
28 | .build();
29 | }
30 |
31 | private ApiInfo apiInfo() {
32 | return new ApiInfoBuilder()
33 | .title("soulcoder APIs")
34 | .description("官网 www.soulcoder.tech")
35 | .termsOfServiceUrl("www.soulcoder.tech")
36 | .version("1.0")
37 | .build();
38 | }
39 |
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/soulcoder-core/src/main/java/tech/soulcoder/core/WebMVCConfig.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.core;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.web.servlet.config.annotation.CorsRegistry;
5 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
7 |
8 |
9 | /**
10 | * @author yunfeng.lu
11 | * @create 2017/11/7.
12 | */
13 | @Configuration
14 | public class WebMVCConfig implements WebMvcConfigurer {
15 | /**
16 | * 配置swagger 映射路径
17 | * @param registry
18 | */
19 | @Override
20 | public void addResourceHandlers(ResourceHandlerRegistry registry) {
21 | registry.addResourceHandler("swagger-ui.html")
22 | .addResourceLocations("classpath:/META-INF/resources/");
23 | registry.addResourceHandler("/webjars/**")
24 | .addResourceLocations("classpath:/META-INF/resources/webjars/");
25 |
26 | }
27 |
28 | /**
29 | * 跨域处理
30 | * @param registry
31 | */
32 | @Override
33 | public void addCorsMappings(CorsRegistry registry) {
34 | registry.addMapping("/**");
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/soulcoder-core/src/main/java/tech/soulcoder/core/dbconfig/DruidConfigSoul.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.core.dbconfig;
2 |
3 | import lombok.Data;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import com.alibaba.druid.pool.DruidDataSource;
8 | import javax.sql.DataSource;
9 | import java.sql.SQLException;
10 |
11 | /**
12 | * @author yunfeng.lu
13 | * @date 2018年06月11日16:19:32
14 | */
15 | @Data
16 | @Configuration
17 | @ConfigurationProperties(prefix = "spring.datasource.soul")
18 | public class DruidConfigSoul {
19 | public String onoff;
20 | public String url;
21 | public String username;
22 | public String password;
23 | public int initialSize;
24 | public int maxActive;
25 | public int minIdle;
26 | public long maxWait;
27 | public long timeBetweenEvictionRunsMillis;
28 | public long minEvictableIdleTimeMillis;
29 | public boolean poolPreparedStatements;
30 | public int maxPoolPreparedStatementPerConnectionSize;
31 | public String filters;
32 | public String connectionProperties;
33 |
34 | @Bean(name="druidDataSourceSoul")
35 | public DataSource druidDataSourceSoul() {
36 | DruidDataSource druidDataSource = new DruidDataSource();
37 | druidDataSource.setUrl(url);
38 | druidDataSource.setUsername(username);
39 | druidDataSource.setPassword(password);
40 | druidDataSource.setInitialSize(initialSize);
41 | druidDataSource.setMaxActive(maxActive);
42 | druidDataSource.setMinIdle(minIdle);
43 | druidDataSource.setMaxWait(maxWait);
44 | druidDataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
45 | druidDataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
46 | druidDataSource.setPoolPreparedStatements(poolPreparedStatements);
47 | druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
48 | druidDataSource.setConnectionProperties(connectionProperties);
49 | try {
50 | druidDataSource.setFilters("stat,slf4j");
51 | } catch (SQLException e) {
52 | e.printStackTrace();
53 | }
54 | try {
55 | druidDataSource.setFilters(filters);
56 | druidDataSource.init();
57 | } catch (SQLException e) {
58 | e.printStackTrace();
59 | }
60 | return druidDataSource;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/soulcoder-core/src/main/java/tech/soulcoder/core/dbconfig/DruidServletConfig.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.core.dbconfig;
2 | import com.alibaba.druid.support.http.StatViewServlet;
3 | import org.springframework.boot.web.servlet.ServletRegistrationBean;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.core.annotation.Order;
7 | /**
8 | * @author yunfeng.lu
9 | * @create 2017/12/28.
10 | */
11 | @Configuration
12 | public class DruidServletConfig {
13 | @Bean
14 | @Order
15 | public ServletRegistrationBean statViewServlet() {
16 | StatViewServlet servlet = new StatViewServlet();
17 | ServletRegistrationBean bean = new ServletRegistrationBean(servlet, "/druid/*");
18 | bean.addInitParameter("loginUsername", "lucode");
19 | bean.addInitParameter("loginPassword", "lucode123");
20 | return bean;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/soulcoder-core/src/main/java/tech/soulcoder/core/dbconfig/MyBatisConfigSoul.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.core.dbconfig;
2 | import com.github.pagehelper.PageInterceptor;
3 | import org.apache.ibatis.plugin.Interceptor;
4 | import org.apache.ibatis.session.SqlSessionFactory;
5 | import org.mybatis.spring.SqlSessionFactoryBean;
6 | import org.mybatis.spring.SqlSessionTemplate;
7 | import org.mybatis.spring.annotation.MapperScan;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.beans.factory.annotation.Qualifier;
10 | import org.springframework.context.annotation.Bean;
11 | import org.springframework.context.annotation.Configuration;
12 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
13 | import org.springframework.jdbc.datasource.DataSourceTransactionManager;
14 |
15 | import javax.sql.DataSource;
16 | /**
17 | * @author yunfeng.lu
18 | * @create 2017/12/28.
19 | */
20 | @MapperScan(basePackages = "tech.soulcoder.dao",
21 | sqlSessionFactoryRef = "sqlSessionFactorySoul",
22 | sqlSessionTemplateRef = "sqlSessionTemplateSoul")
23 | @Configuration
24 | public class MyBatisConfigSoul {
25 | /// 如果不集成 德鲁伊数据库连接池,需要使用普通的数据源,也在这里配置
26 | // @Autowired
27 | // @Qualifier("Soul")
28 | // private DataSource dataSourceSoul;
29 |
30 | /**
31 | * 德鲁伊数据源
32 | */
33 | private final DataSource druidDataSourceSoul;
34 |
35 | private final PageInterceptor pageHelper;
36 |
37 | @Autowired
38 | public MyBatisConfigSoul(@Qualifier("druidDataSourceSoul") DataSource druidDataSourceSoul, PageInterceptor pageHelper) {
39 | this.druidDataSourceSoul = druidDataSourceSoul;
40 | this.pageHelper = pageHelper;
41 | }
42 |
43 | @Bean("sqlSessionFactorySoul")
44 | public SqlSessionFactory sqlSessionFactorySoul() throws Exception {
45 |
46 | SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
47 | sqlSessionFactoryBean.setDataSource(druidDataSourceSoul);
48 | sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
49 | PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
50 | sqlSessionFactoryBean.setMapperLocations(
51 | resolver.getResources("classpath*:mapper/**/*.xml"));
52 |
53 | SqlSessionFactory sqlSessionFactory = null;
54 | try {
55 | sqlSessionFactory = sqlSessionFactoryBean.getObject();
56 | } catch (Exception e) {
57 | e.printStackTrace();
58 | System.exit(0);
59 | }
60 | org.apache.ibatis.session.Configuration configuration = sqlSessionFactory.getConfiguration();
61 | configuration.setMapUnderscoreToCamelCase(true);
62 | return sqlSessionFactoryBean.getObject();
63 | }
64 |
65 | @Bean("soulTransaction")
66 | public DataSourceTransactionManager transactionManager() throws Exception {
67 | return new DataSourceTransactionManager(druidDataSourceSoul);
68 | }
69 | @Bean
70 | public SqlSessionTemplate sqlSessionTemplateSoul() throws Exception {
71 | return new SqlSessionTemplate(sqlSessionFactorySoul());
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/soulcoder-core/src/main/java/tech/soulcoder/core/dbconfig/MybatisPageHelperConfig.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.core.dbconfig;
2 |
3 | import com.github.pagehelper.PageInterceptor;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | import java.util.Properties;
8 |
9 | /**
10 | * 分页
11 | * @author yunfeng.lu
12 | */
13 | @Configuration
14 | public class MybatisPageHelperConfig {
15 | @Bean
16 | public PageInterceptor pageHelper() {
17 | PageInterceptor pageHelper = new PageInterceptor();
18 | Properties p = new Properties();
19 | p.setProperty("offsetAsPageNum", "true");
20 | p.setProperty("rowBoundsWithCount", "true");
21 | p.setProperty("reasonable", "true");
22 | pageHelper.setProperties(p);
23 | return pageHelper;
24 | }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/soulcoder-dao/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | soulcoder
7 | tech.soulcoder
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | soulcoder-dao
13 |
14 |
15 |
--------------------------------------------------------------------------------
/soulcoder-dao/src/main/java/tech/soulcoder/dao/mapper/generator/SoulUserDTOMapper.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.dao.mapper.generator;
2 |
3 | import java.util.List;
4 | import org.apache.ibatis.annotations.Param;
5 | import tech.soulcoder.dao.pojo.generator.SoulUserDTO;
6 | import tech.soulcoder.dao.pojo.generator.SoulUserDTOExample;
7 |
8 | public interface SoulUserDTOMapper {
9 | long countByExample(SoulUserDTOExample example);
10 |
11 | int deleteByExample(SoulUserDTOExample example);
12 |
13 | int deleteByPrimaryKey(String id);
14 |
15 | int insert(SoulUserDTO record);
16 |
17 | int insertSelective(SoulUserDTO record);
18 |
19 | List selectByExample(SoulUserDTOExample example);
20 |
21 | SoulUserDTO selectByPrimaryKey(String id);
22 |
23 | int updateByExampleSelective(@Param("record") SoulUserDTO record, @Param("example") SoulUserDTOExample example);
24 |
25 | int updateByExample(@Param("record") SoulUserDTO record, @Param("example") SoulUserDTOExample example);
26 |
27 | int updateByPrimaryKeySelective(SoulUserDTO record);
28 |
29 | int updateByPrimaryKey(SoulUserDTO record);
30 | }
--------------------------------------------------------------------------------
/soulcoder-dao/src/main/java/tech/soulcoder/dao/mapper/generator/SoulUserMapper.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.dao.mapper.generator;
2 |
3 | import tech.soulcoder.dao.pojo.generator.SoulUser;
4 |
5 | public interface SoulUserMapper {
6 | /**
7 | * This method was generated by MyBatis Generator.
8 | * This method corresponds to the database table soul_user
9 | *
10 | * @mbg.generated
11 | */
12 | int deleteByPrimaryKey(String id);
13 |
14 | /**
15 | * This method was generated by MyBatis Generator.
16 | * This method corresponds to the database table soul_user
17 | *
18 | * @mbg.generated
19 | */
20 | int insert(SoulUser record);
21 |
22 | /**
23 | * This method was generated by MyBatis Generator.
24 | * This method corresponds to the database table soul_user
25 | *
26 | * @mbg.generated
27 | */
28 | int insertSelective(SoulUser record);
29 |
30 | /**
31 | * This method was generated by MyBatis Generator.
32 | * This method corresponds to the database table soul_user
33 | *
34 | * @mbg.generated
35 | */
36 | SoulUser selectByPrimaryKey(String id);
37 |
38 | /**
39 | * This method was generated by MyBatis Generator.
40 | * This method corresponds to the database table soul_user
41 | *
42 | * @mbg.generated
43 | */
44 | int updateByPrimaryKeySelective(SoulUser record);
45 |
46 | /**
47 | * This method was generated by MyBatis Generator.
48 | * This method corresponds to the database table soul_user
49 | *
50 | * @mbg.generated
51 | */
52 | int updateByPrimaryKey(SoulUser record);
53 | }
--------------------------------------------------------------------------------
/soulcoder-dao/src/main/java/tech/soulcoder/dao/pojo/generator/SoulUser.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.dao.pojo.generator;
2 |
3 | /**
4 | *
5 | * This class was generated by MyBatis Generator.
6 | * This class corresponds to the database table soul_user
7 | *
8 | * @mbg.generated do_not_delete_during_merge
9 | */
10 | public class SoulUser {
11 | /**
12 | *
13 | * This field was generated by MyBatis Generator.
14 | * This field corresponds to the database column soul_user.id
15 | *
16 | * @mbg.generated
17 | */
18 | private String id;
19 |
20 | /**
21 | *
22 | * This field was generated by MyBatis Generator.
23 | * This field corresponds to the database column soul_user.pwd
24 | *
25 | * @mbg.generated
26 | */
27 | private String pwd;
28 |
29 | /**
30 | * This method was generated by MyBatis Generator.
31 | * This method returns the value of the database column soul_user.id
32 | *
33 | * @return the value of soul_user.id
34 | *
35 | * @mbg.generated
36 | */
37 | public String getId() {
38 | return id;
39 | }
40 |
41 | /**
42 | * This method was generated by MyBatis Generator.
43 | * This method sets the value of the database column soul_user.id
44 | *
45 | * @param id the value for soul_user.id
46 | *
47 | * @mbg.generated
48 | */
49 | public void setId(String id) {
50 | this.id = id;
51 | }
52 |
53 | /**
54 | * This method was generated by MyBatis Generator.
55 | * This method returns the value of the database column soul_user.pwd
56 | *
57 | * @return the value of soul_user.pwd
58 | *
59 | * @mbg.generated
60 | */
61 | public String getPwd() {
62 | return pwd;
63 | }
64 |
65 | /**
66 | * This method was generated by MyBatis Generator.
67 | * This method sets the value of the database column soul_user.pwd
68 | *
69 | * @param pwd the value for soul_user.pwd
70 | *
71 | * @mbg.generated
72 | */
73 | public void setPwd(String pwd) {
74 | this.pwd = pwd;
75 | }
76 | }
--------------------------------------------------------------------------------
/soulcoder-dao/src/main/java/tech/soulcoder/dao/pojo/generator/SoulUserDTO.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.dao.pojo.generator;
2 |
3 | import java.io.Serializable;
4 |
5 | public class SoulUserDTO implements Serializable {
6 | private String id;
7 |
8 | private String pwd;
9 |
10 | private static final long serialVersionUID = 1L;
11 |
12 | public String getId() {
13 | return id;
14 | }
15 |
16 | public void setId(String id) {
17 | this.id = id == null ? null : id.trim();
18 | }
19 |
20 | public String getPwd() {
21 | return pwd;
22 | }
23 |
24 | public void setPwd(String pwd) {
25 | this.pwd = pwd == null ? null : pwd.trim();
26 | }
27 | }
--------------------------------------------------------------------------------
/soulcoder-dao/src/main/java/tech/soulcoder/dao/pojo/generator/SoulUserDTOExample.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.dao.pojo.generator;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class SoulUserDTOExample {
7 | protected String orderByClause;
8 |
9 | protected boolean distinct;
10 |
11 | protected List oredCriteria;
12 |
13 | public SoulUserDTOExample() {
14 | oredCriteria = new ArrayList();
15 | }
16 |
17 | public void setOrderByClause(String orderByClause) {
18 | this.orderByClause = orderByClause;
19 | }
20 |
21 | public String getOrderByClause() {
22 | return orderByClause;
23 | }
24 |
25 | public void setDistinct(boolean distinct) {
26 | this.distinct = distinct;
27 | }
28 |
29 | public boolean isDistinct() {
30 | return distinct;
31 | }
32 |
33 | public List getOredCriteria() {
34 | return oredCriteria;
35 | }
36 |
37 | public void or(Criteria criteria) {
38 | oredCriteria.add(criteria);
39 | }
40 |
41 | public Criteria or() {
42 | Criteria criteria = createCriteriaInternal();
43 | oredCriteria.add(criteria);
44 | return criteria;
45 | }
46 |
47 | public Criteria createCriteria() {
48 | Criteria criteria = createCriteriaInternal();
49 | if (oredCriteria.size() == 0) {
50 | oredCriteria.add(criteria);
51 | }
52 | return criteria;
53 | }
54 |
55 | protected Criteria createCriteriaInternal() {
56 | Criteria criteria = new Criteria();
57 | return criteria;
58 | }
59 |
60 | public void clear() {
61 | oredCriteria.clear();
62 | orderByClause = null;
63 | distinct = false;
64 | }
65 |
66 | protected abstract static class GeneratedCriteria {
67 | protected List criteria;
68 |
69 | protected GeneratedCriteria() {
70 | super();
71 | criteria = new ArrayList();
72 | }
73 |
74 | public boolean isValid() {
75 | return criteria.size() > 0;
76 | }
77 |
78 | public List getAllCriteria() {
79 | return criteria;
80 | }
81 |
82 | public List getCriteria() {
83 | return criteria;
84 | }
85 |
86 | protected void addCriterion(String condition) {
87 | if (condition == null) {
88 | throw new RuntimeException("Value for condition cannot be null");
89 | }
90 | criteria.add(new Criterion(condition));
91 | }
92 |
93 | protected void addCriterion(String condition, Object value, String property) {
94 | if (value == null) {
95 | throw new RuntimeException("Value for " + property + " cannot be null");
96 | }
97 | criteria.add(new Criterion(condition, value));
98 | }
99 |
100 | protected void addCriterion(String condition, Object value1, Object value2, String property) {
101 | if (value1 == null || value2 == null) {
102 | throw new RuntimeException("Between values for " + property + " cannot be null");
103 | }
104 | criteria.add(new Criterion(condition, value1, value2));
105 | }
106 |
107 | public Criteria andIdIsNull() {
108 | addCriterion("id is null");
109 | return (Criteria) this;
110 | }
111 |
112 | public Criteria andIdIsNotNull() {
113 | addCriterion("id is not null");
114 | return (Criteria) this;
115 | }
116 |
117 | public Criteria andIdEqualTo(String value) {
118 | addCriterion("id =", value, "id");
119 | return (Criteria) this;
120 | }
121 |
122 | public Criteria andIdNotEqualTo(String value) {
123 | addCriterion("id <>", value, "id");
124 | return (Criteria) this;
125 | }
126 |
127 | public Criteria andIdGreaterThan(String value) {
128 | addCriterion("id >", value, "id");
129 | return (Criteria) this;
130 | }
131 |
132 | public Criteria andIdGreaterThanOrEqualTo(String value) {
133 | addCriterion("id >=", value, "id");
134 | return (Criteria) this;
135 | }
136 |
137 | public Criteria andIdLessThan(String value) {
138 | addCriterion("id <", value, "id");
139 | return (Criteria) this;
140 | }
141 |
142 | public Criteria andIdLessThanOrEqualTo(String value) {
143 | addCriterion("id <=", value, "id");
144 | return (Criteria) this;
145 | }
146 |
147 | public Criteria andIdLike(String value) {
148 | addCriterion("id like", value, "id");
149 | return (Criteria) this;
150 | }
151 |
152 | public Criteria andIdNotLike(String value) {
153 | addCriterion("id not like", value, "id");
154 | return (Criteria) this;
155 | }
156 |
157 | public Criteria andIdIn(List values) {
158 | addCriterion("id in", values, "id");
159 | return (Criteria) this;
160 | }
161 |
162 | public Criteria andIdNotIn(List values) {
163 | addCriterion("id not in", values, "id");
164 | return (Criteria) this;
165 | }
166 |
167 | public Criteria andIdBetween(String value1, String value2) {
168 | addCriterion("id between", value1, value2, "id");
169 | return (Criteria) this;
170 | }
171 |
172 | public Criteria andIdNotBetween(String value1, String value2) {
173 | addCriterion("id not between", value1, value2, "id");
174 | return (Criteria) this;
175 | }
176 |
177 | public Criteria andPwdIsNull() {
178 | addCriterion("pwd is null");
179 | return (Criteria) this;
180 | }
181 |
182 | public Criteria andPwdIsNotNull() {
183 | addCriterion("pwd is not null");
184 | return (Criteria) this;
185 | }
186 |
187 | public Criteria andPwdEqualTo(String value) {
188 | addCriterion("pwd =", value, "pwd");
189 | return (Criteria) this;
190 | }
191 |
192 | public Criteria andPwdNotEqualTo(String value) {
193 | addCriterion("pwd <>", value, "pwd");
194 | return (Criteria) this;
195 | }
196 |
197 | public Criteria andPwdGreaterThan(String value) {
198 | addCriterion("pwd >", value, "pwd");
199 | return (Criteria) this;
200 | }
201 |
202 | public Criteria andPwdGreaterThanOrEqualTo(String value) {
203 | addCriterion("pwd >=", value, "pwd");
204 | return (Criteria) this;
205 | }
206 |
207 | public Criteria andPwdLessThan(String value) {
208 | addCriterion("pwd <", value, "pwd");
209 | return (Criteria) this;
210 | }
211 |
212 | public Criteria andPwdLessThanOrEqualTo(String value) {
213 | addCriterion("pwd <=", value, "pwd");
214 | return (Criteria) this;
215 | }
216 |
217 | public Criteria andPwdLike(String value) {
218 | addCriterion("pwd like", value, "pwd");
219 | return (Criteria) this;
220 | }
221 |
222 | public Criteria andPwdNotLike(String value) {
223 | addCriterion("pwd not like", value, "pwd");
224 | return (Criteria) this;
225 | }
226 |
227 | public Criteria andPwdIn(List values) {
228 | addCriterion("pwd in", values, "pwd");
229 | return (Criteria) this;
230 | }
231 |
232 | public Criteria andPwdNotIn(List values) {
233 | addCriterion("pwd not in", values, "pwd");
234 | return (Criteria) this;
235 | }
236 |
237 | public Criteria andPwdBetween(String value1, String value2) {
238 | addCriterion("pwd between", value1, value2, "pwd");
239 | return (Criteria) this;
240 | }
241 |
242 | public Criteria andPwdNotBetween(String value1, String value2) {
243 | addCriterion("pwd not between", value1, value2, "pwd");
244 | return (Criteria) this;
245 | }
246 | }
247 |
248 | public static class Criteria extends GeneratedCriteria {
249 |
250 | protected Criteria() {
251 | super();
252 | }
253 | }
254 |
255 | public static class Criterion {
256 | private String condition;
257 |
258 | private Object value;
259 |
260 | private Object secondValue;
261 |
262 | private boolean noValue;
263 |
264 | private boolean singleValue;
265 |
266 | private boolean betweenValue;
267 |
268 | private boolean listValue;
269 |
270 | private String typeHandler;
271 |
272 | public String getCondition() {
273 | return condition;
274 | }
275 |
276 | public Object getValue() {
277 | return value;
278 | }
279 |
280 | public Object getSecondValue() {
281 | return secondValue;
282 | }
283 |
284 | public boolean isNoValue() {
285 | return noValue;
286 | }
287 |
288 | public boolean isSingleValue() {
289 | return singleValue;
290 | }
291 |
292 | public boolean isBetweenValue() {
293 | return betweenValue;
294 | }
295 |
296 | public boolean isListValue() {
297 | return listValue;
298 | }
299 |
300 | public String getTypeHandler() {
301 | return typeHandler;
302 | }
303 |
304 | protected Criterion(String condition) {
305 | super();
306 | this.condition = condition;
307 | this.typeHandler = null;
308 | this.noValue = true;
309 | }
310 |
311 | protected Criterion(String condition, Object value, String typeHandler) {
312 | super();
313 | this.condition = condition;
314 | this.value = value;
315 | this.typeHandler = typeHandler;
316 | if (value instanceof List>) {
317 | this.listValue = true;
318 | } else {
319 | this.singleValue = true;
320 | }
321 | }
322 |
323 | protected Criterion(String condition, Object value) {
324 | this(condition, value, null);
325 | }
326 |
327 | protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
328 | super();
329 | this.condition = condition;
330 | this.value = value;
331 | this.secondValue = secondValue;
332 | this.typeHandler = typeHandler;
333 | this.betweenValue = true;
334 | }
335 |
336 | protected Criterion(String condition, Object value, Object secondValue) {
337 | this(condition, value, secondValue, null);
338 | }
339 | }
340 | }
--------------------------------------------------------------------------------
/soulcoder-dao/src/main/resources/mapper/generator/SoulUserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
9 |
10 |
11 |
12 |
13 |
17 | id, pwd
18 |
19 |
29 |
30 |
34 | delete from soul_user
35 | where id = #{id,jdbcType=VARCHAR}
36 |
37 |
38 |
42 | insert into soul_user (id, pwd)
43 | values (#{id,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR})
44 |
45 |
46 |
50 | insert into soul_user
51 |
52 |
53 | id,
54 |
55 |
56 | pwd,
57 |
58 |
59 |
60 |
61 | #{id,jdbcType=VARCHAR},
62 |
63 |
64 | #{pwd,jdbcType=VARCHAR},
65 |
66 |
67 |
68 |
69 |
73 | update soul_user
74 |
75 |
76 | pwd = #{pwd,jdbcType=VARCHAR},
77 |
78 |
79 | where id = #{id,jdbcType=VARCHAR}
80 |
81 |
82 |
86 | update soul_user
87 | set pwd = #{pwd,jdbcType=VARCHAR}
88 | where id = #{id,jdbcType=VARCHAR}
89 |
90 |
--------------------------------------------------------------------------------
/soulcoder-dao/src/main/resources/tech/soulcoder/dao/mapper/generator/SoulUserDTOMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | and ${criterion.condition}
17 |
18 |
19 | and ${criterion.condition} #{criterion.value}
20 |
21 |
22 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
23 |
24 |
25 | and ${criterion.condition}
26 |
27 | #{listItem}
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | and ${criterion.condition}
46 |
47 |
48 | and ${criterion.condition} #{criterion.value}
49 |
50 |
51 | and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
52 |
53 |
54 | and ${criterion.condition}
55 |
56 | #{listItem}
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | id, pwd
68 |
69 |
83 |
89 |
90 | delete from soul_user
91 | where id = #{id,jdbcType=VARCHAR}
92 |
93 |
94 | delete from soul_user
95 |
96 |
97 |
98 |
99 |
100 | insert into soul_user (id, pwd)
101 | values (#{id,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR})
102 |
103 |
104 | insert into soul_user
105 |
106 |
107 | id,
108 |
109 |
110 | pwd,
111 |
112 |
113 |
114 |
115 | #{id,jdbcType=VARCHAR},
116 |
117 |
118 | #{pwd,jdbcType=VARCHAR},
119 |
120 |
121 |
122 |
128 |
129 | update soul_user
130 |
131 |
132 | id = #{record.id,jdbcType=VARCHAR},
133 |
134 |
135 | pwd = #{record.pwd,jdbcType=VARCHAR},
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 | update soul_user
144 | set id = #{record.id,jdbcType=VARCHAR},
145 | pwd = #{record.pwd,jdbcType=VARCHAR}
146 |
147 |
148 |
149 |
150 |
151 | update soul_user
152 |
153 |
154 | pwd = #{pwd,jdbcType=VARCHAR},
155 |
156 |
157 | where id = #{id,jdbcType=VARCHAR}
158 |
159 |
160 | update soul_user
161 | set pwd = #{pwd,jdbcType=VARCHAR}
162 | where id = #{id,jdbcType=VARCHAR}
163 |
164 |
--------------------------------------------------------------------------------
/soulcoder-dao/src/test/java/tech/soulcoder/test/GeneratorMain.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.test;
2 |
3 | import org.mybatis.generator.api.ShellRunner;
4 |
5 | import java.io.File;
6 | import java.io.IOException;
7 |
8 | /**
9 | * GeneratorMain.class
10 | *
11 | * @author yunfeng.lu
12 | * @date 2018/7/9
13 | */
14 | public class GeneratorMain {
15 | // 本地 mysql jar包的路径 一般在你的 maven仓库里面找
16 | public static String mysqlJarPath = "/Applications/dev/maven_conf/repository/mysql/mysql-connector-java/5.1.29/mysql-connector-java-5.1.29.jar";
17 | // 这个只要放 相对路径就可以了
18 | public static String mapperXmlPath = "/soulcoder-dao/src/main/resources/tech/soulcoder/dao/mapper/generator";
19 | public static void main(String[] args) {
20 | args = new String[3];
21 | args[0] = "-configfile";
22 | GeneratorMain.class.getResource("/");
23 | String configRootPath = GeneratorMain.class.getResource("/").getPath();
24 | args[1] = configRootPath + "generator.xml";
25 | args[2] = "-overwrite";
26 | deleteXmlFiles();
27 | System.getProperties().put("mysql.driver.path",mysqlJarPath);
28 | ShellRunner.main(args);
29 | }
30 |
31 | // 删除原来的 文件 生成最新的
32 | public static void deleteXmlFiles() {
33 | try {
34 | File directory = new File("");
35 | String str = directory.getCanonicalPath() + mapperXmlPath;
36 | File file = new File(str);
37 | if (file.isDirectory() && null != file.listFiles() && file.listFiles().length > 0) {
38 | for (File f : file.listFiles()) {
39 | f.delete();
40 | }
41 | }
42 | } catch (IOException e) {
43 | e.printStackTrace();
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/soulcoder-dao/src/test/resources/generator.properties.exmple:
--------------------------------------------------------------------------------
1 | classPath=/Applications/dev/maven_conf/repository/mysql/mysql-connector-java/5.1.29/mysql-connector-java-5.1.29.jar
2 | jdbc_driver=com.mysql.jdbc.Driver
3 | jdbc_url=jdbc:mysql://127.0.0.1:3306/soulcoder?autoReconnect=true&useCompression=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
4 | jdbc_user=root
5 | jdbc_password=
--------------------------------------------------------------------------------
/soulcoder-dao/src/test/resources/generator.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
29 |
30 |
31 |
32 |
33 |
35 |
36 |
37 |
38 |
40 |
41 |
42 |
43 |
51 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/soulcoder-model/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | soulcoder
7 | tech.soulcoder
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | soulcoder-model
13 |
14 |
15 |
--------------------------------------------------------------------------------
/soulcoder-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | soulcoder
7 | tech.soulcoder
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | soulcoder-service
13 |
14 |
15 |
16 | tech.soulcoder
17 | soulcoder-dao
18 | 0.0.1-SNAPSHOT
19 |
20 |
21 | tech.soulcoder
22 | soulcoder-model
23 | 0.0.1-SNAPSHOT
24 | compile
25 |
26 |
27 | tech.soulcoder
28 | soulcoder-utils
29 | 0.0.1-SNAPSHOT
30 | compile
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/soulcoder-service/src/main/java/tech/soulcoder/service/TestService.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.service;
2 |
3 |
4 | import java.util.Map;
5 |
6 | public interface TestService {
7 |
8 | Map testDB();
9 | }
10 |
--------------------------------------------------------------------------------
/soulcoder-service/src/main/java/tech/soulcoder/service/impl/TestServiceImpl.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.service.impl;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.stereotype.Service;
6 | import tech.soulcoder.RedisOperation;
7 | import tech.soulcoder.dao.mapper.generator.SoulUserMapper;
8 | import tech.soulcoder.log.LogAuto;
9 | import tech.soulcoder.service.TestService;
10 |
11 | import java.util.HashMap;
12 | import java.util.Map;
13 |
14 | @Service
15 | public class TestServiceImpl implements TestService {
16 |
17 | private final SoulUserMapper soulUserMapper;
18 |
19 | private final RedisOperation redisOperation;
20 |
21 | @Autowired
22 | public TestServiceImpl(RedisOperation redisOperation, SoulUserMapper soulUserMapper) {
23 | this.redisOperation = redisOperation;
24 | this.soulUserMapper = soulUserMapper;
25 | }
26 |
27 | @Override
28 | @LogAuto
29 | public Map testDB() {
30 | redisOperation.setValue("haha","lalal");
31 | System.out.println(redisOperation.getValue("haha"));
32 |
33 | Map res=new HashMap<>();
34 | res.put("res",JSON.toJSONString(soulUserMapper.selectByPrimaryKey("1")));
35 | return res;
36 |
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/soulcoder-service/src/test/java/tech/soulcoder/test/MyTest.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder.test;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.test.context.SpringBootTest;
7 | import org.springframework.test.context.junit4.SpringRunner;
8 | import tech.soulcoder.service.TestService;
9 |
10 | @RunWith(SpringRunner.class)
11 | @SpringBootTest
12 | public class MyTest {
13 |
14 | @Autowired
15 | private TestService testService;
16 |
17 | @Test
18 | public void test(){
19 | System.out.println(testService.testDB());
20 |
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/soulcoder-utils/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | soulcoder
7 | tech.soulcoder
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | soulcoder-utils
13 |
14 |
15 | tech.soulcoder
16 | soulcoder-model
17 | 0.0.1-SNAPSHOT
18 | compile
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/soulcoder-utils/src/main/java/tech/soulcoder/IPUtils.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 |
5 | public class IPUtils {
6 | public static String getIpAddress(HttpServletRequest request) {
7 | String ip = request.getHeader("x-forwarded-for");
8 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
9 | ip = request.getHeader("Proxy-Client-IP");
10 | }
11 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
12 | ip = request.getHeader("WL-Proxy-Client-IP");
13 | }
14 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
15 | ip = request.getHeader("HTTP_CLIENT_IP");
16 | }
17 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
18 | ip = request.getHeader("HTTP_X_FORWARDED_FOR");
19 | }
20 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
21 | ip = request.getRemoteAddr();
22 | }
23 | return ip;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/soulcoder-utils/src/main/java/tech/soulcoder/RedisOperation.java:
--------------------------------------------------------------------------------
1 | package tech.soulcoder;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.dao.DataAccessException;
5 | import org.springframework.data.redis.connection.RedisConnection;
6 | import org.springframework.data.redis.core.RedisCallback;
7 | import org.springframework.data.redis.core.StringRedisTemplate;
8 | import org.springframework.data.redis.core.TimeoutUtils;
9 | import org.springframework.stereotype.Service;
10 |
11 | import java.util.List;
12 | import java.util.Map;
13 | import java.util.Set;
14 | import java.util.concurrent.TimeUnit;
15 |
16 | @Service
17 | public class RedisOperation {
18 | private static final long DEFAULT_REDIS_KEYS_TIMEOUT = 60*60*24*7;
19 | @Autowired
20 | private StringRedisTemplate stringRedisTemplate;
21 |
22 | /**
23 | * 字符串操作
24 | * @param key
25 | * @param value
26 | */
27 |
28 | public void setValue(String key, String value) {
29 | stringRedisTemplate.opsForValue().set(key, value);
30 | }
31 |
32 |
33 | public void setValue(String key, String value, Long timeout,TimeUnit unit) {
34 | stringRedisTemplate.opsForValue().set(key, value, timeout , unit);
35 | }
36 |
37 | /**
38 | * 字符串 kv 操作
39 | * @param key
40 | * @return
41 | */
42 |
43 | public String getValue(String key) {
44 | return stringRedisTemplate.opsForValue().get(key);
45 | }
46 |
47 | /**
48 | * Hash 值设置
49 | * @param key
50 | * @param value
51 | */
52 |
53 | public void setHashAll(String key, Map value) {
54 | stringRedisTemplate.opsForHash().putAll(key,value);
55 | }
56 |
57 | /**
58 | * Hash 值设置,并设置超时时间
59 | * @param key
60 | * @param value
61 | * @param timeout
62 | * @param unit
63 | */
64 |
65 | public void setHashAll(String key, Map value, Long timeout,TimeUnit unit) {
66 | stringRedisTemplate.opsForHash().putAll(key,value);
67 | stringRedisTemplate.expire(key,timeout,unit);
68 | }
69 |
70 | /**
71 | * 根据 key 获取 Hash 类型的 value
72 | * @param key
73 | * @return
74 | */
75 |
76 | public Map