chenwen 2 years ago
parent
commit
9289652974

+ 39 - 0
.classpath

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java">
+		<attributes>
+			<attribute name="test" value="true"/>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
+		<attributes>
+			<attribute name="test" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+			<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

+ 37 - 0
.project

@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>zl-opd-server</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.wst.common.project.facet.core.builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.wst.validation.validationbuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
+		<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+		<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+		<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
+	</natures>
+</projectDescription>

+ 102 - 0
pom.xml

@@ -0,0 +1,102 @@
+<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>
+  <groupId>com.hb</groupId>
+  <artifactId>zl-opd-server</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <packaging>war</packaging>
+  
+  <properties>
+		<java.version>17</java.version>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <spring-boot.version>3.0.0</spring-boot.version>
+  </properties>
+  
+  <dependencies>
+	  <dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-web</artifactId>
+			<exclusions>
+				<exclusion>
+					<groupId>org.springframework.boot</groupId>
+					<artifactId>spring-boot-starter-tomcat</artifactId>
+				</exclusion>
+			</exclusions>
+		</dependency>
+
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-tomcat</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		
+		<dependency>
+		    <groupId>mysql</groupId>
+		    <artifactId>mysql-connector-java</artifactId>
+		    <version>5.1.25</version>
+		</dependency>
+		
+		<dependency>
+		    <groupId>org.springframework.boot</groupId>
+		    <artifactId>spring-boot-starter-validation</artifactId>
+		</dependency>
+		
+		 <dependency>
+		    <groupId>org.aspectj</groupId>
+		    <artifactId>aspectjweaver</artifactId>
+		</dependency>
+		
+		<dependency>
+		    <groupId>com.hb</groupId>
+		    <artifactId>xframework6-spring-boot3-starter</artifactId>
+		    <version>0.0.1-SNAPSHOT</version>
+		</dependency>
+  </dependencies>
+	
+  <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-dependencies</artifactId>
+                <version>${spring-boot.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+  
+  <build>
+		<plugins>
+			<!-- 明确配置编译插件可以指定一些参数,如jdk编译级别 。默认的可能编译级别较低。-->
+			<plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.8.1</version>
+                <configuration>
+                    <source>${java.version}</source>
+                    <target>${java.version}</target>
+                    <encoding>${project.build.sourceEncoding}</encoding>
+                </configuration>
+            </plugin>
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+				<version>${spring-boot.version}</version>
+                <configuration>
+                    <mainClass>com.hb.proj.Application</mainClass>
+                </configuration>
+			</plugin>
+			
+			<!-- 明确配置打包插件可以指定一些参数。默认的插件版本可能级别较低,导致pom有错误提示。-->
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-war-plugin</artifactId>
+				<version>3.3.2</version>
+				<configuration>
+					<failOnMissingWebXml>false</failOnMissingWebXml>
+				</configuration>
+			</plugin>
+
+		</plugins>
+	</build>
+</project>

+ 16 - 0
src/main/java/com/hb/proj/Application.java

@@ -0,0 +1,16 @@
+package com.hb.proj;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ImportResource;
+
+
+@ImportResource("classpath:transaction.xml")
+@SpringBootApplication
+public class Application {
+
+	public static void main(String[] args) {
+		SpringApplication.run(Application.class, args);
+	}
+
+}

+ 49 - 0
src/main/java/com/hb/proj/CustomMethodArgumentResolver.java

@@ -0,0 +1,49 @@
+package com.hb.proj;
+import java.util.Iterator;
+
+import org.springframework.core.MethodParameter;
+import org.springframework.web.bind.support.WebDataBinderFactory;
+import org.springframework.web.context.request.NativeWebRequest;
+import org.springframework.web.method.support.HandlerMethodArgumentResolver;
+import org.springframework.web.method.support.ModelAndViewContainer;
+
+import com.hb.proj.utils.RequestParams;
+import com.hb.xframework.util.SessionThreadLocal;
+import com.hb.xframework.util.SessionUser;
+
+public class CustomMethodArgumentResolver implements
+		HandlerMethodArgumentResolver {
+
+	@Override
+	public boolean supportsParameter(MethodParameter parameter) {
+		if(parameter.getParameterType().isAssignableFrom(SessionUser.class)){
+			return true;
+		}
+		if(parameter.getParameterType().isAssignableFrom(RequestParams.class)){
+			return true;
+		}
+		return false;
+	}
+
+	@Override
+	public Object resolveArgument(MethodParameter parameter,
+			ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
+			WebDataBinderFactory binderFactory) throws Exception {
+		if(parameter.getParameterType().isAssignableFrom(SessionUser.class)){
+			return SessionThreadLocal.getSessionUser();
+		}
+		if(parameter.getParameterType().equals(RequestParams.class)){
+			 RequestParams reqParams=new RequestParams();
+			 Iterator<String> paramNames=webRequest.getParameterNames();
+			 String pn=null;
+			 while(paramNames.hasNext()){
+				 pn=paramNames.next();
+				 reqParams.put(pn, webRequest.getParameter(pn));
+			 }
+			 
+			return reqParams;
+		}
+		return null;
+	}
+
+}

+ 63 - 0
src/main/java/com/hb/proj/RequestValidateExceptionHandler.java

@@ -0,0 +1,63 @@
+package com.hb.proj;
+
+import java.util.Set;
+
+import jakarta.validation.ConstraintViolation;
+import jakarta.validation.ConstraintViolationException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.validation.BindException;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.FieldError;
+import org.springframework.web.HttpRequestMethodNotSupportedException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+import com.hb.proj.utils.RespVO;
+import com.hb.proj.utils.RespVOBuilder;
+
+@RestControllerAdvice
+public class RequestValidateExceptionHandler {
+	
+	private static final Logger logger=LoggerFactory.getLogger(RequestValidateExceptionHandler.class);
+
+	//处理请求参数格式错误 @RequestParam上validate失败后抛出的异常是javax.validation.ConstraintViolationException
+	@ExceptionHandler(ConstraintViolationException.class)
+	public RespVO constraintViolationExceptionHandler(ConstraintViolationException e) {
+		//e.printStackTrace();
+		Set<ConstraintViolation<?>> constraintViolations=e.getConstraintViolations();
+		StringBuilder error=new StringBuilder();
+		for(ConstraintViolation<?> itm : constraintViolations) {
+			//System.out.println(itm.getInvalidValue()+":"+itm.getPropertyPath()+":"+itm.getMessage());
+			error.append(itm.getMessage()+";");
+		}
+		//jdk8  写法:String message = e.getConstraintViolations().stream().map(ConstraintViolation::getMessage).collect(Collectors.joining());
+		return RespVOBuilder.error(error.toString());//
+	}
+	
+	@ExceptionHandler(BindException.class)
+	public RespVO validationExceptionHandler(BindException e) {
+		//e.printStackTrace();
+		BindingResult bindingResult = e.getBindingResult();
+		StringBuilder error=new StringBuilder();
+		for (FieldError fieldError : bindingResult.getFieldErrors()) {
+			error.append(fieldError.getDefaultMessage()+";");
+		}
+		return RespVOBuilder.error(error.toString());
+	}
+	
+	@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
+	public RespVO methodUnsupportExceptionHandler(HttpRequestMethodNotSupportedException e) {
+		logger.error("不支持该请求方式",e);
+		return RespVOBuilder.error("不支持该请求方式");
+		
+	}
+	
+	@ExceptionHandler(Exception.class)
+	public RespVO otherExceptionHandler(Exception e) {
+		logger.error("服务出错",e);
+		return RespVOBuilder.error("服务出错");
+		
+	}
+}

+ 13 - 0
src/main/java/com/hb/proj/ServletInitializer.java

@@ -0,0 +1,13 @@
+package com.hb.proj;
+
+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(Application.class);
+	}
+
+}

+ 56 - 0
src/main/java/com/hb/proj/SpringMvcConfigurer.java

@@ -0,0 +1,56 @@
+package com.hb.proj;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.Ordered;
+import org.springframework.format.FormatterRegistry;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+import org.springframework.web.method.support.HandlerMethodArgumentResolver;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class SpringMvcConfigurer implements WebMvcConfigurer {
+
+	@Override
+	public void addResourceHandlers(ResourceHandlerRegistry registry) {
+		registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
+		WebMvcConfigurer.super.addResourceHandlers(registry);
+	}
+	
+	@Override
+	public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
+		resolvers.add(new CustomMethodArgumentResolver());
+		WebMvcConfigurer.super.addArgumentResolvers(resolvers);
+	}
+
+	@Override
+	public void addFormatters(FormatterRegistry registry) {
+		registry.addConverter(new StringToDateConverter());
+		WebMvcConfigurer.super.addFormatters(registry);
+	}
+	
+    @Bean
+    public FilterRegistrationBean<CorsFilter> corsFilter() {
+        // 跨域配置
+        CorsConfiguration configuration = new CorsConfiguration();
+        configuration.setAllowedOrigins(Arrays.asList("*"));
+        configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "HEAD", "DELETE", "OPTION"));
+        configuration.setAllowedHeaders(Arrays.asList("*"));
+        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+        source.registerCorsConfiguration("/**", configuration);
+
+        // 有多个filter时此处可设置改CorsFilter的优先执行顺序,保证CorsFilter在其他过滤器之前执行(避免其他过滤器执行异常,导致CorsFilter没执行,从而导致跨域失效)
+        FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<>(new CorsFilter(source));
+        bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
+        return bean;
+    }
+
+
+}

+ 39 - 0
src/main/java/com/hb/proj/StringToDateConverter.java

@@ -0,0 +1,39 @@
+package com.hb.proj;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.util.StringUtils;
+
+public class StringToDateConverter implements Converter<String, Date> {
+
+	private static final String[] dateFormats= {"yyyy-MM-dd HH:mm:ss","yyyy-MM-dd","yyyy/MM/dd HH:mm:ss","yyyy/MM/dd"};
+	
+	@Override
+	public Date convert(String source) {
+		if (StringUtils.hasLength(source)) {
+	            return null;
+	    }
+		source = source.trim();
+		 try {
+	            SimpleDateFormat formatter;
+	            
+	            if (source.contains("-")) {
+	            	 formatter = new SimpleDateFormat(source.contains(":")?dateFormats[0]:dateFormats[1]);
+	                 return formatter.parse(source);
+	            } 
+	            else if (source.contains("/")) {
+	            	formatter = new SimpleDateFormat(source.contains(":")?dateFormats[2]:dateFormats[3]);
+	                return formatter.parse(source);
+	            }
+	            
+	            throw new RuntimeException(String.format("parser %s to Date fail,unknow format", source));
+	            
+	        } catch (Exception e) {
+	            throw new RuntimeException(String.format("parser %s to Date fail", source));
+	        }
+		
+	}
+
+}

+ 62 - 0
src/main/java/com/hb/proj/utils/JacksonUtils.java

@@ -0,0 +1,62 @@
+package com.hb.proj.utils;
+
+import java.util.List;
+import java.util.Map;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class JacksonUtils {
+
+	//private static final Logger logger = LoggerFactory.getLogger(JacksonUtils.class);
+	
+	private final static ObjectMapper mapper = new ObjectMapper();
+	
+	public static String getJSON(Object obj){
+		try {
+			return mapper.writeValueAsString(obj);
+		}
+		catch(Exception e) {
+    		throw new RuntimeException("jackson序列化对象时出错");
+    	}
+	}
+
+    public static <T> List<T>  getList(String json,Class<T> cls){
+    	try {
+    		return mapper.readValue(json, new TypeReference<List<T>>() {});
+    	}
+    	catch(Exception e) {
+    		throw new RuntimeException("jackson参数转换出错");
+    	}
+    	
+    }
+    
+    public static List<Map<String,Object>>  getMaps(String json){
+    	try {
+    		return mapper.readValue(json, new TypeReference<List<Map<String,Object>>>() {});
+    	}
+    	catch(Exception e) {
+    		throw new RuntimeException("jackson参数转换出错");
+    	}
+    	
+    }
+    
+    @SuppressWarnings("unchecked")
+	public static Map<String,Object>  getMap(String json){
+    	try {
+    		return mapper.readValue(json, Map.class);
+    	}
+    	catch(Exception e) {
+    		throw new RuntimeException("jackson参数转换出错");
+    	}
+    }
+    
+    public static <T> T  get(String json,Class<T> cls) {
+    	try {
+    		return mapper.readValue(json, cls);
+    	}
+    	catch(Exception e) {
+    		throw new RuntimeException("jackson参数转换出错");
+    	}
+    }
+}

+ 52 - 0
src/main/java/com/hb/proj/utils/LayGridResp.java

@@ -0,0 +1,52 @@
+package com.hb.proj.utils;
+
+
+public class LayGridResp {
+
+	private int  code;
+	
+	private int  count;
+	
+	private Object data;
+	
+	private Boolean success;
+	
+	public LayGridResp(int code,int count,Object data){
+		this.code=code;
+		this.success=code==0;
+		this.count=count;
+		this.data=data;
+	}
+
+	public int getCode() {
+		return code;
+	}
+
+	public void setCode(int code) {
+		this.code = code;
+	}
+
+	public int getCount() {
+		return count;
+	}
+
+	public void setCount(int count) {
+		this.count = count;
+	}
+
+	public Object getData() {
+		return data;
+	}
+
+	public void setData(Object data) {
+		this.data = data;
+	}
+
+	public Boolean getSuccess() {
+		return success;
+	}
+
+	public void setSuccess(Boolean success) {
+		this.success = success;
+	}
+}

+ 38 - 0
src/main/java/com/hb/proj/utils/MySessionUser.java

@@ -0,0 +1,38 @@
+package com.hb.proj.utils;
+
+import com.hb.xframework.util.SessionUser;
+
+public class MySessionUser extends SessionUser {
+
+	private String authOrgs;  //存储org的assistCode便于应用
+	
+	private String orgAssistCode; //用户单位assistCode
+	
+	private String userType;
+
+	public String getAuthOrgs() {
+		return authOrgs;
+	}
+
+	public void setAuthOrgs(String authOrgs) {
+		this.authOrgs = authOrgs;
+	}
+
+	public String getOrgAssistCode() {
+		return orgAssistCode;
+	}
+
+	public void setOrgAssistCode(String orgAssistCode) {
+		this.orgAssistCode = orgAssistCode;
+	}
+
+	public String getUserType() {
+		return userType;
+	}
+
+	public void setUserType(String userType) {
+		this.userType = userType;
+	}
+	
+	
+}

+ 40 - 0
src/main/java/com/hb/proj/utils/RequestParams.java

@@ -0,0 +1,40 @@
+package com.hb.proj.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class RequestParams {
+
+	
+	private Map<String, String> args;
+	
+	public RequestParams(){
+		this.args=new HashMap<String,String>();
+	}
+	
+	public RequestParams(Map<String,String> args){
+		this.args=args;
+	}
+
+	public RequestParams(int initialCapacity){
+		this.args=new HashMap<String,String>(initialCapacity);
+	}
+	
+	public String get(String key){
+		return args.get(key);
+	}
+	
+	public void put(String key,String value){
+		args.put(key, value);
+	}
+	
+	public Map<String,String> get(){
+		return args;
+	}
+	
+	public Map<String,Object> getObjectMap(){
+		Map<String,Object> addArgs=new HashMap<String,Object>();
+		addArgs.putAll(args);
+		return addArgs;
+	}
+}

+ 69 - 0
src/main/java/com/hb/proj/utils/RespVO.java

@@ -0,0 +1,69 @@
+package com.hb.proj.utils;
+
+public class RespVO {
+
+	private Boolean success;
+	
+	private Object  data;
+	
+	private String  error;
+	
+	private int code;  //兼容laygrid
+	
+	private String msg;  //兼容laygrid
+	
+	public RespVO() {
+		this.success=true;
+		this.code=0;
+	}
+	
+	public RespVO(Boolean success,Object  data,String  error) {
+		this.success=success;
+		this.data=data;
+		this.error=error;
+		this.msg=error;
+		this.code=success?0:1;
+	}
+
+	public Boolean getSuccess() {
+		return success;
+	}
+
+	public void setSuccess(Boolean success) {
+		this.success = success;
+	}
+
+	public Object getData() {
+		return data;
+	}
+
+	public void setData(Object data) {
+		this.data = data;
+	}
+
+	public String getError() {
+		return error;
+	}
+
+	public void setError(String error) {
+		this.error = error;
+	}
+
+	public int getCode() {
+		return code;
+	}
+
+	public void setCode(int code) {
+		this.code = code;
+	}
+
+	public String getMsg() {
+		return msg;
+	}
+
+	public void setMsg(String msg) {
+		this.msg = msg;
+	}
+	
+	
+}

+ 30 - 0
src/main/java/com/hb/proj/utils/RespVOBuilder.java

@@ -0,0 +1,30 @@
+package com.hb.proj.utils;
+
+public class RespVOBuilder {
+
+	public static RespVO  ok() {  //默认只设置success=true
+		return new RespVO();
+	}
+	
+	public static RespVO  ok(Object data) {
+		return new RespVO(true,data,null);
+	}
+	
+	public static RespVO  error(String error) {
+		return new RespVO(false,null,error);
+	}
+	
+	public static RespVO  error(String error,Object data) {
+		return new RespVO(false,data,error);
+	}
+	
+	public static LayGridResp getLayGridResp(int total,Object data){
+		if(data==null){
+			return new LayGridResp(0,0,null);
+		}
+		else{
+			return new LayGridResp(0,total,data);
+		}
+		
+	}
+}

+ 26 - 0
src/main/resources/application-dev.properties

@@ -0,0 +1,26 @@
+# 应用名称
+spring.application.name=MyTempProj
+
+# 应用服务 WEB 访问端口
+server.port=8080
+
+server.servlet.context-path=/myproj
+server.tomcat.uri-encoding=UTF-8
+server.servlet.encoding.charset=UTF-8
+server.servlet.encoding.enabled=true
+server.servlet.encoding.force=true
+spring.messages.encoding=UTF-8
+
+spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
+spring.jackson.time-zone=GMT+8
+
+#日志配置
+logging.level.com.hb.xframework=DEBUG
+
+#数据库连接池配置
+spring.datasource.url=jdbc:mysql://localhost:3306/earthquake_info
+spring.datasource.username=root
+spring.datasource.password=hb
+spring.datasource.driver-class-name=com.mysql.jdbc.Driver
+spring.datasource.type=com.hb.xframework.dao.util.HikariDataSourceWrap
+spring.datasource.dialect=MySQL

+ 28 - 0
src/main/resources/application-pro.properties

@@ -0,0 +1,28 @@
+# 应用名称
+spring.application.name=water
+
+# 应用服务 WEB 访问端口
+server.port=80
+
+server.servlet.context-path=/waterTank
+server.tomcat.uri-encoding=UTF-8
+server.servlet.encoding.charset=UTF-8
+server.servlet.encoding.enabled=true
+server.servlet.encoding.force=true
+spring.messages.encoding=UTF-8
+
+spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
+spring.jackson.time-zone=GMT+8
+
+#日志配置
+logging.level.com.hb.xframework=DEBUG
+
+#数据库连接池配置
+spring.datasource.url=jdbc:mysql://localhost:3306/jz_water_tank_made
+spring.datasource.username=root
+spring.datasource.password=hb
+spring.datasource.driver-class-name=com.mysql.jdbc.Driver
+spring.datasource.type=com.hb.xframework.dao.util.HikariDataSourceWrap
+spring.datasource.dialect=MySQL
+
+

+ 1 - 0
src/main/resources/application.properties

@@ -0,0 +1 @@
+spring.profiles.active=dev

+ 34 - 0
src/main/resources/transaction.xml

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+     xmlns:aop="http://www.springframework.org/schema/aop"    
+     xmlns:tx="http://www.springframework.org/schema/tx"
+     xmlns:context="http://www.springframework.org/schema/context"
+	 xsi:schemaLocation="http://www.springframework.org/schema/beans
+		http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+		http://www.springframework.org/schema/tx     
+        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd    
+		http://www.springframework.org/schema/aop     
+        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+		http://www.springframework.org/schema/context
+		http://www.springframework.org/schema/context/spring-context-3.0.xsd" >
+		
+	<!-- spring boot 会根据持久化引入的starter自动构建事务管理器,引入了jdbc-starter 事务管理器名称:transactionManager,不需要在本文件重复定义 -->	 
+   <tx:advice id="txAdvice" transaction-manager="transactionManager">  
+       <tx:attributes>  
+           <tx:method name="add*" 		propagation="REQUIRED" rollback-for="Exception"/>  
+           <tx:method name="create*" 	propagation="REQUIRED" rollback-for="Exception"/>  
+           <tx:method name="insert*" 	propagation="REQUIRED" rollback-for="Exception"/>  
+           <tx:method name="del*" 		propagation="REQUIRED" rollback-for="Exception"/> 
+           <tx:method name="save*" 		propagation="REQUIRED" rollback-for="Exception"/>  
+           <tx:method name="update*" 	propagation="REQUIRED" rollback-for="Exception"/>  <!-- rollback-for="Exception" -->
+           <tx:method name="*" 			read-only="true"/>
+      </tx:attributes>  
+    </tx:advice>  
+    
+      <!-- 声明式事务管理 -->  
+    <aop:config>  
+       <aop:advisor pointcut="(execution(* com.hb.proj.*.service.*.*(..)))" advice-ref="txAdvice" /> 
+       
+    </aop:config> 
+</beans>