.gitignore
New file @@ -0,0 +1,33 @@ HELP.md target/ !.mvn/wrapper/maven-wrapper.jar !**/src/main/**/target/ !**/src/test/**/target/ ### STS ### .apt_generated .classpath .factorypath .project .settings .springBeans .sts4-cache ### IntelliJ IDEA ### .idea *.iws *.iml *.ipr ### NetBeans ### /nbproject/private/ /nbbuild/ /dist/ /nbdist/ /.nb-gradle/ build/ !**/src/main/**/build/ !**/src/test/**/build/ ### VS Code ### .vscode/ pom.xml
New file @@ -0,0 +1,145 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.12.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>ResMeterManager</artifactId> <version>0.0.1-SNAPSHOT</version> <name>ResMeterManager</name> <description>ResMeterManager</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>6.0.6</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.5</version> </dependency> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.4</version> <classifier>jdk15</classifier> </dependency> <!--mybatis 及mybatis-plus--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.1.2</version> </dependency> <!--knife4j--> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-spring-boot-starter</artifactId> <version>2.0.2</version> <!--<version>2.0.6</version>--> <!--<exclusions> <exclusion> <groupId>org.springframework.plugin</groupId> <artifactId>spring-plugin-core</artifactId> </exclusion> </exclusions>--> </dependency> <!--连接池--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-extension</artifactId> <version>3.1.2</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.10</version> </dependency> <!--pageHelper分页--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.5</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!--必须是这个1.4.2版本!!!否则打成jar无法访问页面!!--> <version>1.4.2.RELEASE</version> <configuration> <!-- 工程主入口--> <mainClass>com.whyc.ResMeterManagerApplication</mainClass> <fork>true</fork> <includeSystemScope>true</includeSystemScope><!--添加此项--> </configuration> </plugin> </plugins> <!-- 指定资源文件的位置,否则maven打包的时候不会把文件打包进去,导致thymeleaf无法解析 --> <resources> <resource> <directory>src/main/resources</directory> </resource> <resource> <directory>src/main/webapp</directory> <targetPath>META-INF/resources</targetPath> <includes> <include>**/**</include> </includes> </resource> </resources> </build> </project> src/main/java/com/whyc/ResMeterManagerApplication.java
New file @@ -0,0 +1,15 @@ package com.whyc; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @SpringBootApplication @EnableWebMvc public class ResMeterManagerApplication { public static void main(String[] args) { SpringApplication.run(ResMeterManagerApplication.class, args); } } src/main/java/com/whyc/config/MybatisPlusConfig.java
New file @@ -0,0 +1,22 @@ package com.whyc.config; import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; import com.whyc.injector.CustomSqlInjector; import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration @MapperScan("com.whyc.mapper") public class MybatisPlusConfig { @Bean public CustomSqlInjector customSqlInjector(){ return new CustomSqlInjector(); } @Bean public PaginationInterceptor paginationInterceptor(){ return new PaginationInterceptor(); } } src/main/java/com/whyc/config/StaticResourceConfig.java
New file @@ -0,0 +1,76 @@ package com.whyc.config; import com.fasterxml.jackson.databind.ObjectMapper; import com.whyc.constant.YamlProperties; import org.springframework.boot.system.ApplicationHome; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import java.io.File; import java.text.SimpleDateFormat; import java.util.List; import java.util.TimeZone; /** * @Description : static resources Config * @date 2020/09/15 **/ @Configuration @EnableWebMvc public class StaticResourceConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { //这个是可行的,解析的时候path为*.html,校验路径admin下是否存在 registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/"); //项目jar同级目录下,图片能通过http方式访问到,很重要! ApplicationHome applicationHome = new ApplicationHome(getClass()); File jarFile = applicationHome.getDir(); //在jar包所在目录下生成一个upload文件夹用来存储上传的图片 /**文档存储路径*/ String baseDirPath; /**统一图片上传路径格式*/ String baseDirPath2;//人脸上传地址 if(YamlProperties.runModel == 1) { //开发路径 baseDirPath = jarFile.getParentFile().toString()+File.separator+"res_file"+File.separator; }else { //打包路径 baseDirPath = jarFile.toString()+File.separator+"res_file"+File.separator; } registry.addResourceHandler("/res_file/**").addResourceLocations("file:/"+baseDirPath); super.addResourceHandlers(registry); } @Bean public ObjectMapper jacksonObjectMapperCustomization() { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); TimeZone timeZone = TimeZone.getTimeZone("Asia/Shanghai"); format.setTimeZone(timeZone); Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder() .timeZone(timeZone) .dateFormat(format); return builder.build(); } @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { converters.removeIf(c -> c instanceof MappingJackson2HttpMessageConverter); converters.add(new MappingJackson2HttpMessageConverter(jacksonObjectMapperCustomization())); } } src/main/java/com/whyc/constant/YamlProperties.java
New file @@ -0,0 +1,48 @@ package com.whyc.constant; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; /** * Yaml配置参数 实体类 */ @Component public class YamlProperties { /** * 运行模式:dev,prod */ public static String profileType; /** * 系统类型 * 1:普通,没有多重校验 * 2:严格,有多重校验(登录,防重放,参数过滤) */ public static Integer systemType; /**系统运行模式*/ public static Integer runModel; @Value("${spring.profiles.active}") public void setProfileType(String profileType) { YamlProperties.profileType = profileType; } @Value("${system.type}") public void setSystemType(Integer systemType) { YamlProperties.systemType = systemType; } @Value("${configFile.type}") public void setRunModel(Integer runModel) { YamlProperties.runModel = runModel; } } src/main/java/com/whyc/dto/FileDirPath.java
New file @@ -0,0 +1,22 @@ package com.whyc.dto; import com.whyc.constant.YamlProperties; import org.springframework.boot.system.ApplicationHome; import java.io.File; public class FileDirPath { //当前项目在dev和prod模式下访问路径 public static String getFileDirName(){ String fileDirName = ""; ApplicationHome applicationHome = new ApplicationHome(FileDirPath.class); File jarFile = applicationHome.getDir(); if( 1 == YamlProperties.runModel){ fileDirName = jarFile.getParentFile().toString(); }else{ //打包版 fileDirName = jarFile.toString(); } return fileDirName; } } src/main/java/com/whyc/injector/CustomSqlInjector.java
New file @@ -0,0 +1,24 @@ package com.whyc.injector; import com.baomidou.mybatisplus.core.injector.AbstractMethod; import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector; import com.baomidou.mybatisplus.extension.injector.methods.additional.AlwaysUpdateSomeColumnById; import com.baomidou.mybatisplus.extension.injector.methods.additional.InsertBatchSomeColumn; import java.util.List; /** * 自定义sql注入器,使得mybatis-plus能自动识别执行 */ public class CustomSqlInjector extends DefaultSqlInjector { @Override public List<AbstractMethod> getMethodList(Class<?> mapperClass) { //这是默认的父类方法列表 List<AbstractMethod> methodList = super.getMethodList(mapperClass); //新增批量插入方法 methodList.add(new InsertBatchSomeColumn()); methodList.add(new AlwaysUpdateSomeColumnById()); return methodList; } } src/main/java/com/whyc/mapper/CustomMapper.java
New file @@ -0,0 +1,17 @@ package com.whyc.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import java.util.Collection; @SuppressWarnings("all") public interface CustomMapper<T> extends BaseMapper<T> { /** * 批量插入 * @param entityList * @return */ Integer insertBatchSomeColumn(Collection<T> entityList); } src/main/java/com/whyc/swagger/SwaggerConfig4Knife.java
New file @@ -0,0 +1,44 @@ package com.whyc.swagger; import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 @EnableKnife4j @ConditionalOnProperty(prefix = "knife",name = "enable",havingValue = "true") public class SwaggerConfig4Knife { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .groupName("内阻测试分析软件v1.0") .select() .apis(RequestHandlerSelectors.any()) .apis(RequestHandlerSelectors.basePackage("com.whyc.controller")) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("内阻测试分析软件v1.0") //大标题 title .contact(new Contact("whyc","todo","todo")) .description("内阻测试分析软件v1.0") //小标题 .version("1.0") //版本 // .termsOfServiceUrl("http://xxx.xxx.com") //终端服务程序 // .license("LICENSE") //链接显示文字 // .licenseUrl("http://xxx.xxx.com") //网站链接 .build(); } } src/main/resources/config/application-dev.yml
New file @@ -0,0 +1,68 @@ #系统类型:1(普通,无限制),2(严格-gw标准),3(严格-签名) system: type: 1 #服务端口号 server: port: 8093 servlet: context-path: /res session: cookie: name: ResMeterManager tomcat: max-http-form-post-size: 102400000 #数据库 spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://192.168.10.79:3360/db_res_meter?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true username: root password: lmx8688139 maxIdel: 60 initialPoolSize: 2 minPoolSize: 2 maxPoolSize: 500 servlet: multipart: max-file-size: 200MB max-request-size: 200MB mybatis-plus: typeAliasesPackage: com.whyc.pojo,com.whyc.dto mapper-locations: classpath:mapper/**/*Mapper.xml global-config: db-config: #主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID"; id-type: AUTO #驼峰下划线转换 table-underline: true #数据库大写下划线转换 capital-mode: true #mp2.3+ 全局表前缀 tb_ table-prefix: tb_ #刷新mapper 调试神器 # refresh-mapper: true configuration: #配置返回数据库(column下划线命名&&返回java实体是驼峰命名),自动匹配无需as(没开启这个,SQL需要写as: select user_id as userId) map-underscore-to-camel-case: true cache-enabled: false #mybatis日志输出 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl pagehelper: helper-dialect: mysql reasonable: true support-methods-arguments: true params: count=countSql knife: enable: true #Config文件读取 涉及License和FGCDFileDownload configFile: type: 1 #1:本地测试;2:打包jar src/main/resources/config/application-prod.yml
New file @@ -0,0 +1,63 @@ #系统类型:1(普通,无限制),2(严格-gw标准),3(严格-签名) system: type: 1 #服务端口号 server: port: 8093 servlet: context-path: /res session: cookie: name: ResMeterManager tomcat: max-http-form-post-size: 102400000 #数据库 spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3360/db_res_meter?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true&useSSL=false username: root password: lmx8688139 maxIdel: 60 initialPoolSize: 2 minPoolSize: 2 maxPoolSize: 500 servlet: multipart: max-file-size: 200MB max-request-size: 200MB mybatis-plus: typeAliasesPackage: com.whyc.pojo,com.whyc.dto mapper-locations: classpath:mapper/**/*Mapper.xml global-config: db-config: #主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID"; id-type: AUTO #驼峰下划线转换 table-underline: true #数据库大写下划线转换 capital-mode: true #mp2.3+ 全局表前缀 tb_ table-prefix: tb_ #刷新mapper 调试神器 # refresh-mapper: true configuration: #配置返回数据库(column下划线命名&&返回java实体是驼峰命名),自动匹配无需as(没开启这个,SQL需要写as: select user_id as userId) map-underscore-to-camel-case: true cache-enabled: false #mybatis日志输出 # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl pagehelper: helper-dialect: mysql reasonable: true support-methods-arguments: true params: count=countSql knife: enable: false #Config文件读取 涉及License和FGCDFileDownload configFile: type: 2 #1:本地测试;2:打包jar src/main/resources/config/application.yml
New file @@ -0,0 +1,8 @@ spring: profiles: # active: prod active: dev src/main/webapp/index.html
New file @@ -0,0 +1,10 @@ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> 123456 </body> </html> src/test/java/com/whyc/resmetermanager/ResMeterManagerApplicationTests.java
New file @@ -0,0 +1,13 @@ package com.whyc.resmetermanager; import org.junit.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class ResMeterManagerApplicationTests { @Test void contextLoads() { } }