From 4c1cc07824ff56f9dd65625616d6985d7c60ecb4 Mon Sep 17 00:00:00 2001 From: luhaotian <944536083@qq.com> Date: Mon, 19 Feb 2024 09:25:09 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 200 ++++++++++++++++++ .../JhqmPermissions01Application.java | 17 ++ .../permissions01/ServletInitializer.java | 13 ++ .../permissions01/config/JacksonConf.java | 32 +++ .../permissions01/config/SwaggerConfig.java | 38 ++++ .../jhqm/permissions01/config/WebConfig.java | 30 +++ .../demos/web/BasicController.java | 67 ++++++ .../demos/web/PathVariableController.java | 44 ++++ .../jhqm/permissions01/demos/web/User.java | 43 ++++ .../model/TUserMicroserviceAwUser.java | 37 ++++ .../model/TUserMicroserviceQmList.java | 112 ++++++++++ src/main/resources/application.properties | 45 ++++ src/main/resources/static/index.html | 6 + .../JhqmPermissions01ApplicationTests.java | 13 ++ 14 files changed, 697 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/com/example/drht/jhqm/permissions01/JhqmPermissions01Application.java create mode 100644 src/main/java/com/example/drht/jhqm/permissions01/ServletInitializer.java create mode 100644 src/main/java/com/example/drht/jhqm/permissions01/config/JacksonConf.java create mode 100644 src/main/java/com/example/drht/jhqm/permissions01/config/SwaggerConfig.java create mode 100644 src/main/java/com/example/drht/jhqm/permissions01/config/WebConfig.java create mode 100644 src/main/java/com/example/drht/jhqm/permissions01/demos/web/BasicController.java create mode 100644 src/main/java/com/example/drht/jhqm/permissions01/demos/web/PathVariableController.java create mode 100644 src/main/java/com/example/drht/jhqm/permissions01/demos/web/User.java create mode 100644 src/main/java/com/example/drht/jhqm/permissions01/model/TUserMicroserviceAwUser.java create mode 100644 src/main/java/com/example/drht/jhqm/permissions01/model/TUserMicroserviceQmList.java create mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/static/index.html create mode 100644 src/test/java/com/example/drht/jhqm/permissions01/JhqmPermissions01ApplicationTests.java diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2b172bd --- /dev/null +++ b/pom.xml @@ -0,0 +1,200 @@ + + + 4.0.0 + com.example.drht.jhqm.permissions01 + jhqm_permissions01 + 0.0.1-SNAPSHOT + war + jhqm_permissions01 + jhqm_permissions01 + + 1.8 + UTF-8 + UTF-8 + 2.6.13 + false + 3.0.0 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.boot + spring-boot-starter-data-jdbc + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-starter-jdbc + + + + org.hibernate + hibernate-core + + + + org.hibernate + hibernate-entitymanager + + + + com.alibaba + druid-spring-boot-starter + 1.1.22 + + + + mysql + mysql-connector-java + runtime + + + + + org.projectlombok + lombok + true + + + + com.google.guava + guava + 30.1-jre + + + + com.alibaba + fastjson + 1.2.76 + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + com.google.code.gson + gson + 2.8.5 + + + + + org.slf4j + slf4j-api + 1.7.25 + compile + + + + io.springfox + springfox-boot-starter + ${swagger.version} + + + + cn.hutool + hutool-all + 5.3.9 + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + UTF-8 + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + com.example.drht.jhqm.permissions01.JhqmPermissions01Application + true + true + + + + repackage + + repackage + + + + + + + + + + nexus + Nexus Repository + http://nexus.derunht.cn/repository/maven-public/ + + true + + + true + always + + + + + + + nexus + Nexus Plugin Repository + http://nexus.derunht.cn/repository/maven-public/ + + true + + + true + always + + + + + diff --git a/src/main/java/com/example/drht/jhqm/permissions01/JhqmPermissions01Application.java b/src/main/java/com/example/drht/jhqm/permissions01/JhqmPermissions01Application.java new file mode 100644 index 0000000..9b0abf5 --- /dev/null +++ b/src/main/java/com/example/drht/jhqm/permissions01/JhqmPermissions01Application.java @@ -0,0 +1,17 @@ +package com.example.drht.jhqm.permissions01; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; + +@EnableAsync //支持异步须要开启的注解 +@EnableScheduling //开启定时任务的注解 +@SpringBootApplication +public class JhqmPermissions01Application { + + public static void main(String[] args) { + SpringApplication.run(JhqmPermissions01Application.class, args); + } + +} diff --git a/src/main/java/com/example/drht/jhqm/permissions01/ServletInitializer.java b/src/main/java/com/example/drht/jhqm/permissions01/ServletInitializer.java new file mode 100644 index 0000000..547f986 --- /dev/null +++ b/src/main/java/com/example/drht/jhqm/permissions01/ServletInitializer.java @@ -0,0 +1,13 @@ +package com.example.drht.jhqm.permissions01; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +public class ServletInitializer extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(JhqmPermissions01Application.class); + } + +} diff --git a/src/main/java/com/example/drht/jhqm/permissions01/config/JacksonConf.java b/src/main/java/com/example/drht/jhqm/permissions01/config/JacksonConf.java new file mode 100644 index 0000000..ac38e9a --- /dev/null +++ b/src/main/java/com/example/drht/jhqm/permissions01/config/JacksonConf.java @@ -0,0 +1,32 @@ +package com.example.drht.jhqm.permissions01.config; + +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; + +@Configuration +public class JacksonConf { + + /** + * 解决js精度丢失问题 + * */ + /** + * Jackson全局转化long类型为String,解决jackson序列化时long类型缺失精度问题 + * + * @return Jackson2ObjectMapperBuilderCustomizer 注入的对象 + */ + @Bean + public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() { + Jackson2ObjectMapperBuilderCustomizer cunstomizer = new Jackson2ObjectMapperBuilderCustomizer() { + + @Override + public void customize(Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) { + jacksonObjectMapperBuilder.serializerByType(Long.class, ToStringSerializer.instance); + + } + }; + return cunstomizer; + } +} diff --git a/src/main/java/com/example/drht/jhqm/permissions01/config/SwaggerConfig.java b/src/main/java/com/example/drht/jhqm/permissions01/config/SwaggerConfig.java new file mode 100644 index 0000000..1997a7c --- /dev/null +++ b/src/main/java/com/example/drht/jhqm/permissions01/config/SwaggerConfig.java @@ -0,0 +1,38 @@ +package com.example.drht.jhqm.permissions01.config; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +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.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; +//@EnableWebMvc + +@Configuration //配置类 +@EnableSwagger2// 开启Swagger2的自动配置 +public class SwaggerConfig { + + @Bean + public Docket api() { + return new Docket(DocumentationType.OAS_30) + .select() + .apis(RequestHandlerSelectors.withClassAnnotation(Api.class)) + .apis(RequestHandlerSelectors.basePackage("com.example.drht.jhqm.permissions01.config")) + .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) + .build() + .apiInfo(apiInfo()); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("swagger 文档标题") + .description("swagger 文档描述") + .version("1.0 swagger 文档版本") + .build(); + } + +} diff --git a/src/main/java/com/example/drht/jhqm/permissions01/config/WebConfig.java b/src/main/java/com/example/drht/jhqm/permissions01/config/WebConfig.java new file mode 100644 index 0000000..03b8e5e --- /dev/null +++ b/src/main/java/com/example/drht/jhqm/permissions01/config/WebConfig.java @@ -0,0 +1,30 @@ +package com.example.drht.jhqm.permissions01.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + /** + * 配置跨域 + * */ + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*") + .allowedMethods("*") + .allowedHeaders("*"); + } + + + /** + * 配置默认资源请求路径 + * */ + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/**") + .addResourceLocations("classpath:/static/"); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/drht/jhqm/permissions01/demos/web/BasicController.java b/src/main/java/com/example/drht/jhqm/permissions01/demos/web/BasicController.java new file mode 100644 index 0000000..e0df6f6 --- /dev/null +++ b/src/main/java/com/example/drht/jhqm/permissions01/demos/web/BasicController.java @@ -0,0 +1,67 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.drht.jhqm.permissions01.demos.web; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @author theonefx + */ +@Controller +public class BasicController { + + // http://127.0.0.1:8080/hello?name=lisi + @RequestMapping("/hello") + @ResponseBody + public String hello(@RequestParam(name = "name", defaultValue = "unknown user") String name) { + return "Hello " + name; + } + + // http://127.0.0.1:8080/user + @RequestMapping("/user") + @ResponseBody + public User user() { + User user = new User(); + user.setName("theonefx"); + user.setAge(666); + return user; + } + + // http://127.0.0.1:8080/save_user?name=newName&age=11 + @RequestMapping("/save_user") + @ResponseBody + public String saveUser(User u) { + return "user will save: name=" + u.getName() + ", age=" + u.getAge(); + } + + // http://127.0.0.1:8080/html + @RequestMapping("/html") + public String html() { + return "index.html"; + } + + @ModelAttribute + public void parseUser(@RequestParam(name = "name", defaultValue = "unknown user") String name + , @RequestParam(name = "age", defaultValue = "12") Integer age, User user) { + user.setName("zhangsan"); + user.setAge(18); + } +} diff --git a/src/main/java/com/example/drht/jhqm/permissions01/demos/web/PathVariableController.java b/src/main/java/com/example/drht/jhqm/permissions01/demos/web/PathVariableController.java new file mode 100644 index 0000000..3a95420 --- /dev/null +++ b/src/main/java/com/example/drht/jhqm/permissions01/demos/web/PathVariableController.java @@ -0,0 +1,44 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.drht.jhqm.permissions01.demos.web; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @author theonefx + */ +@Controller +public class PathVariableController { + + // http://127.0.0.1:8080/user/123/roles/222 + @RequestMapping(value = "/user/{userId}/roles/{roleId}", method = RequestMethod.GET) + @ResponseBody + public String getLogin(@PathVariable("userId") String userId, @PathVariable("roleId") String roleId) { + return "User Id : " + userId + " Role Id : " + roleId; + } + + // http://127.0.0.1:8080/javabeat/somewords + @RequestMapping(value = "/javabeat/{regexp1:[a-z-]+}", method = RequestMethod.GET) + @ResponseBody + public String getRegExp(@PathVariable("regexp1") String regexp1) { + return "URI Part : " + regexp1; + } +} diff --git a/src/main/java/com/example/drht/jhqm/permissions01/demos/web/User.java b/src/main/java/com/example/drht/jhqm/permissions01/demos/web/User.java new file mode 100644 index 0000000..9b98dbd --- /dev/null +++ b/src/main/java/com/example/drht/jhqm/permissions01/demos/web/User.java @@ -0,0 +1,43 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.drht.jhqm.permissions01.demos.web; + +/** + * @author theonefx + */ +public class User { + + private String name; + + private Integer age; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } +} diff --git a/src/main/java/com/example/drht/jhqm/permissions01/model/TUserMicroserviceAwUser.java b/src/main/java/com/example/drht/jhqm/permissions01/model/TUserMicroserviceAwUser.java new file mode 100644 index 0000000..36ba19e --- /dev/null +++ b/src/main/java/com/example/drht/jhqm/permissions01/model/TUserMicroserviceAwUser.java @@ -0,0 +1,37 @@ +package com.example.drht.jhqm.permissions01.model; + +import lombok.Data; + +import javax.persistence.*; +import java.util.Objects; +@Data +@Entity +@Table(name = "t_user_microservice_aw_user", schema = "jinhaiqimengdb", catalog = "") +public class TUserMicroserviceAwUser { + @Id + @Column(name = "id") + private Long id; + @Basic + @Column(name = "user_name") + private String userName; + @Basic + @Column(name = "user_sex") + private String userSex; + @Basic + @Column(name = "user_phone") + private String userPhone; + @Basic + @Column(name = "new_time") + private Long newTime; + @Basic + @Column(name = "updata_time") + private Long updataTime; + @Basic + @Column(name = "user_pw") + private String userPw; + @Basic + @Column(name = "user_img") + private String userImg; + + +} diff --git a/src/main/java/com/example/drht/jhqm/permissions01/model/TUserMicroserviceQmList.java b/src/main/java/com/example/drht/jhqm/permissions01/model/TUserMicroserviceQmList.java new file mode 100644 index 0000000..5bf2e25 --- /dev/null +++ b/src/main/java/com/example/drht/jhqm/permissions01/model/TUserMicroserviceQmList.java @@ -0,0 +1,112 @@ +package com.example.drht.jhqm.permissions01.model; + +import lombok.Data; + +import javax.persistence.*; +import java.util.Objects; +@Data +@Entity +@Table(name = "t_user_microservice_qm_list", schema = "jinhaiqimengdb", catalog = "") +public class TUserMicroserviceQmList { + @Id + @Column(name = "id") + private Long id; + @Basic + @Column(name = "user_id") + private Long userId; + @Basic + @Column(name = "us_study") + private String usStudy; + @Basic + @Column(name = "us_study_id") + private Long usStudyId; + @Basic + @Column(name = "us_adds") + private String usAdds; + @Basic + @Column(name = "us_linkman") + private String usLinkman; + @Basic + @Column(name = "us_linkman_code") + private String usLinkmanCode; + @Basic + @Column(name = "us_state") + private String usState; + @Basic + @Column(name = "firm_code") + private String firmCode; + @Basic + @Column(name = "firm_log") + private String firmLog; + @Basic + @Column(name = "firm_img") + private String firmImg; + @Basic + @Column(name = "firm_name") + private String firmName; + @Basic + @Column(name = "firm_referral") + private String firmReferral; + @Basic + @Column(name = "us_type") + private String usType; + @Basic + @Column(name = "new_time") + private Long newTime; + @Basic + @Column(name = "updata_time") + private Long updataTime; + @Basic + @Column(name = "role_id") + private Long roleId; + @Basic + @Column(name = "role_name") + private String roleName; + @Basic + @Column(name = "user_token") + private String userToken; + @Basic + @Column(name = "qm_scale_type") + private String qmScaleType; + @Basic + @Column(name = "qm_city") + private String qmCity; + @Basic + @Column(name = "qm_industry") + private String qmIndustry; + @Basic + @Column(name = "qm_province") + private String qmProvince; + @Basic + @Column(name = "qm_topic") + private String qmTopic; + @Basic + @Column(name = "qm_institution") + private Long qmInstitution; + @Basic + @Column(name = "current_id") + private Long currentId; + @Basic + @Column(name = "current_name") + private String currentName; + @Basic + @Column(name = "current_type") + private String currentType; + @Basic + @Column(name = "join_role") + private String joinRole; + @Basic + @Column(name = "join_id") + private Long joinId; + @Basic + @Column(name = "is_sham") + private String isSham; + @Basic + @Column(name = "sham_code") + private String shamCode; + @Basic + @Column(name = "sham_name") + private String shamName; + + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..e8cbcbc --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,45 @@ +# 应用服务 WEB 访问端口 +server.port=8080 + +spring.mvc.async.request-timeout=100000 + + +logging.file.path=/logs +logging.file.name=tools.log +# 这里的 com.example.logt 是我的测试项目的包名 +# 这里是指的单个日志文件最大大小 默认为10MB +logging.file.max-size=20MB +# 这里是日志文件最长保存天数 不配置的话为无限制 永远存储 单位为天 +logging.file.max-history=15 + +spring.servlet.multipart.max-file-size=50MB +spring.servlet.multipart.max-request-size=50MB + +spring.datasource.druid.db-type=com.alibaba.druid.pool.DruidDataSource +#spring.datasource.druid.url=jdbc:mysql://localhost:3306/bgl_test2?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=false +spring.datasource.druid.url=jdbc:mysql://120.46.194.248:13306/jinhaiqimengdb?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2b8&useSSL=false +#spring.datasource.druid.url=jdbc:mysql://localhost:3306/bgl_test?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%8&useSSL=false +spring.datasource.druid.username=userMicroservice_user +spring.datasource.druid.password=Zf4mm=K5N33&ju2$ +spring.datasource.druid.driver-class-name=com.mysql.cj.jdbc.Driver +spring.jpa.database=mysql +spring.jpa.show-sql=false +spring.jpa.generate-ddl=true +spring.jpa.hibernate.ddl-auto=update +spring.jpa.open-in-view=false +#spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect +spring.jpa.database-platform=org.hibernate.dialect.MySQL57InnoDBDialect +spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext + +spring.redis.database=5 +#spring.redis.host=39.100.237.119 +spring.redis.host=120.46.171.171 +spring.redis.port=6379 +spring.redis.password=bcd4@g2wp*PZv#&U +spring.redis.timeout=40000ms + + +spring.mvc.pathmatch.matching-strategy=ant_path_matcher + +spring.jackson.date-format=yyyy-MM-dd HH:mm:ss +spring.jackson.time-zone=GMT+8 \ No newline at end of file diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html new file mode 100644 index 0000000..89bb8ba --- /dev/null +++ b/src/main/resources/static/index.html @@ -0,0 +1,6 @@ + + +

hello word!!!

+

this is a html page

+ + \ No newline at end of file diff --git a/src/test/java/com/example/drht/jhqm/permissions01/JhqmPermissions01ApplicationTests.java b/src/test/java/com/example/drht/jhqm/permissions01/JhqmPermissions01ApplicationTests.java new file mode 100644 index 0000000..96a9b47 --- /dev/null +++ b/src/test/java/com/example/drht/jhqm/permissions01/JhqmPermissions01ApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.drht.jhqm.permissions01; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class JhqmPermissions01ApplicationTests { + + @Test + void contextLoads() { + } + +}