Skip to content

Commit

Permalink
Base dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
niziming committed Jul 6, 2022
1 parent 9fdec65 commit ec85603
Show file tree
Hide file tree
Showing 59 changed files with 3,489 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
本系统采用三层结构,确定系统的Java作为编程语言,View层采用JSP,Spring 作为整个项目的整合核心管理所有 Bean 的生命周期行为,Dao层采用MyBatis,MySQL作为数据库,SpringMVC 的 Controller作为整个应用的控制器。整个系统要操作方便、易于维护、灵活使用。
本系统采用以上方法,基本实现了用户模块、景点模块、酒店模块、论坛模块、定制模块、留言回复功能,及相应模块的后台管理功能等。

## 2019年春
我在2019年毕业时用SSM架构写了这个前后端都在一起的web项目, 如今参加工作几年后回头看感觉这个项目当时做得跟屎一样.
如今会利用下空闲时间重构此项目.

### 项目结构

- ssm2019
2019年的单体前后端统一的项目
- trip-web-server-server
2022年重新重构的一个前后端分离的动态旅游网站项目
-


## 2019年春
我在2019年毕业时用SSM架构写了这个前后端都在一起的web项目, 如今参加工作几年后回头看感觉这个项目做的实在是无法直视.所有的前后端交互的都是阻塞同步的.
如今会利用下空闲时间重构此项目.

## 以下为2019年的项目文档内容

Expand Down
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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.3.2.RELEASE</version>
<!--<version>2.2.4.RELEASE</version>-->
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>cn.zm</groupId>
<artifactId>tripweb</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>ssm2019</module>
<module>trip-web-server</module>
</modules>

</project>
2 changes: 1 addition & 1 deletion ssm2019/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
</dependencies>

<build>
<finalName>trip-web</finalName>
<finalName>trip-web-server</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
Expand Down
85 changes: 85 additions & 0 deletions trip-web-server/base-module/common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>base-module</artifactId>
<groupId>cn.zm</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>common</artifactId>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<hutool.version>5.3.10</hutool.version>
<knife4j.version>2.0.8</knife4j.version>
<mysql.version>8.0.27</mysql.version>
<fastjson.version>1.2.58</fastjson.version>
<hibernate-validator.version>5.2.4.Final</hibernate-validator.version>
</properties>

<dependencies>
<dependency>
<groupId>cn.zm</groupId>
<artifactId>knife4j</artifactId>
</dependency>

<!-- commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<!--<version>${commons-lang3.version}</version>-->
</dependency>

<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>

<!-- web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>

<!--Actuator:springboot程序监控器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- hutool 工具 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>

<!-- aop -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>


<!-- SpringMVC校验 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cn.zm.common.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* @author Mr_W
* @date 2021/2/18 12:37
* @description: 当入参验证分组和该分组一致时设置为 null
*/
@Documented
@Target(FIELD)
@Retention(RUNTIME)
public @interface SetNull {

Class<?> group();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package cn.zm.common.aspect;

import cn.zm.common.annotation.SetNull;
import cn.zm.common.base.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.time.Duration;
import java.time.Instant;

/**
* @author Mr_W
* @date 2021/2/18 9:22
* @description dto 参数切面
*/
@Aspect
@Slf4j
@Component
public class DataTransferObjectAspect {
@Pointcut("execution(public * com.*.*.*.web.*.*(..))")
public void pointcut() {}

@Around("pointcut()")
public Object proceed(ProceedingJoinPoint p) throws Throwable {
Instant now = Instant.now();
MethodSignature signature = (MethodSignature) p.getSignature();
Method method = signature.getMethod();
Annotation[][] methodAnnotations = method.getParameterAnnotations();
for (int i = 0; i < methodAnnotations.length; i++) {
for (Annotation annotation : methodAnnotations[i]) {
if (annotation instanceof Validated) {
// 如果有分组
if (((Validated) annotation).value().length != 0) {
p.getArgs()[i] = buildParams(p.getArgs()[i], ((Validated) annotation).value()[0]);
}
}
}
}
log.debug("入参构建完毕, 用时: [{}] ms", Duration.between(now, Instant.now()).toMillis());
return p.proceed();
}

/**
* 构建入参
* @param obj 原始入参
* @return 构建后的入参
*/
private Object buildParams(Object obj, Class<?> type) {
for (Field field : obj.getClass().getDeclaredFields()) {
for (Annotation annotation : field.getAnnotations()) {
if (annotation instanceof SetNull) {
try {
Method groupMethod = annotation.annotationType().getDeclaredMethod("group");
Class<?> group = (Class<?>) groupMethod.invoke(annotation);
if (type.isAssignableFrom(group)) {
field.setAccessible(true);
field.set(obj, null);
field.setAccessible(false);
}
} catch (NoSuchMethodException e) {
log.error("没有 groups 方法", e);
throw ServiceException.serviceException("服务器异常", e).build();
} catch (IllegalAccessException | InvocationTargetException e) {
log.error("groups 方法执行失败", e);
throw ServiceException.serviceException("服务器异常", e).build();
}
}
}
}
return obj;
}

// @Around("pointcut()")
// public Object proceed(ProceedingJoinPoint p) throws Throwable {
// Instant now = Instant.now();
// MethodSignature signature = (MethodSignature) p.getSignature();
// Method method = signature.getMethod();
// Annotation[][] methodAnnotations = method.getParameterAnnotations();
// for (int i = 0; i < methodAnnotations.length; i++) {
// for (Annotation annotation : methodAnnotations[i]) {
// if (annotation instanceof Validated) {
// // 如果有分组
// if (((Validated) annotation).value().length != 0) {
// p.getArgs()[i] = buildParams(p.getArgs()[i], ((Validated) annotation).value()[0]);
// }
// }
// }
// }
// LOGGER.debug("入参构建完毕, 用时: [{}] ms", Duration.between(now, Instant.now()).toMillis());
// return proceed(p);
// }
//
// /**
// * 构建入参
// * @param obj 原始入参
// * @return 构建后的入参
// */
// private Object buildParams(Object obj, Class<?> type) {
// for (Field field : obj.getClass().getDeclaredFields()) {
// for (Annotation annotation : field.getAnnotations()) {
// if (annotation.annotationType().getName().contains("javax.validation.constraints")) {
// try {
// Method groups = annotation.annotationType().getDeclaredMethod("groups");
// Class<?> group = ((Class<?>[]) groups.invoke(annotation))[0];
// if (!type.isAssignableFrom(group)) {
// field.setAccessible(true);
// field.set(obj, null);
// field.setAccessible(false);
// }
// } catch (NoSuchMethodException e) {
// LOGGER.error("没有 groups 方法", e);
// throw new ServiceException("服务器异常");
// } catch (IllegalAccessException | InvocationTargetException e) {
// LOGGER.error("groups 方法执行失败", e);
// throw new ServiceException("服务器异常");
// }
// }
// }
// }
// return obj;
// }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cn.zm.common.base;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

@Data
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "基础条件依赖", description = "基础条件依赖")
public class BaseEntity {
@ApiModelProperty(value = "页数")
private String page;
@ApiModelProperty(value="长度")
private String size;
@ApiModelProperty(value="排序资源")
private String orderByColumn;
@ApiModelProperty(value="正倒序")
private boolean isDesc;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cn.zm.common.base;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Child<T> {
String id;
List<T> child;
}
Loading

0 comments on commit ec85603

Please sign in to comment.