aop
parent
262aeece40
commit
8f64eb53fd
|
@ -138,6 +138,16 @@
|
|||
<artifactId>h2</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- aop 依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<!-- 用于日志切面中,以 json 格式打印出入参 -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.february.mybatisplus.apect;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 切面类
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
@Documented
|
||||
public @interface WebLog {
|
||||
/**
|
||||
* 日志描述信息
|
||||
* @return
|
||||
**/
|
||||
String description() default "";
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.february.mybatisplus.apect;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* AOP日志
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class WebLogAspect {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(WebLogAspect.class);
|
||||
private static final Gson gson = new Gson(); // 用于重复使用Gson实例
|
||||
private static final String LINE_SEPARATOR = System.lineSeparator();
|
||||
|
||||
@Pointcut("@annotation(com.february.mybatisplus.apect.WebLog)")
|
||||
public void webLog() {}
|
||||
|
||||
@Before("webLog()")
|
||||
public void doBefore(JoinPoint joinPoint) {
|
||||
// 开始打印请求日志
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (attributes != null) {
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
|
||||
// 获取 @WebLog 注解的描述信息
|
||||
String methodDescription;
|
||||
try {
|
||||
methodDescription = getAspectLogDescription(joinPoint);
|
||||
} catch (Exception e) {
|
||||
methodDescription = "无法获取方法描述信息";
|
||||
logger.error("获取方法描述信息时发生异常: ", e);
|
||||
}
|
||||
|
||||
// 打印请求相关参数
|
||||
logger.info("========================================== Start ==========================================");
|
||||
logger.info("URL : {}", request.getRequestURL().toString());
|
||||
logger.info("Description : {}", methodDescription);
|
||||
logger.info("HTTP Method : {}", request.getMethod());
|
||||
logger.info("Class Method : {}.{}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());
|
||||
logger.info("IP : {}", request.getRemoteAddr());
|
||||
logger.info("Request Args : {}", gson.toJson(joinPoint.getArgs()));
|
||||
}
|
||||
}
|
||||
|
||||
@After("webLog()")
|
||||
public void doAfter() {
|
||||
logger.info("=========================================== End ==========================================={}", LINE_SEPARATOR);
|
||||
}
|
||||
|
||||
@Around("webLog()")
|
||||
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
|
||||
long startTime = System.currentTimeMillis();
|
||||
Object result = proceedingJoinPoint.proceed();
|
||||
logger.info("Response Args : {}", gson.toJson(result));
|
||||
logger.info("Time-Consuming : {} ms", System.currentTimeMillis() - startTime);
|
||||
return result;
|
||||
}
|
||||
|
||||
private String getAspectLogDescription(JoinPoint joinPoint) throws ClassNotFoundException {
|
||||
String targetName = joinPoint.getTarget().getClass().getName();
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
Object[] arguments = joinPoint.getArgs();
|
||||
Class<?> targetClass = Class.forName(targetName);
|
||||
Method[] methods = targetClass.getMethods();
|
||||
for (Method method : methods) {
|
||||
if (method.getName().equals(methodName) && method.getParameterTypes().length == arguments.length) {
|
||||
WebLog webLog = method.getAnnotation(WebLog.class);
|
||||
if (webLog != null) {
|
||||
return webLog.description();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.february.mybatisplus.controller;
|
||||
|
||||
import com.february.mybatisplus.demo.Tadmin;
|
||||
import com.february.mybatisplus.apect.WebLog;
|
||||
import com.february.mybatisplus.demo.Admin;
|
||||
import com.february.mybatisplus.service.AdminService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -17,8 +18,9 @@ public class AdminController {
|
|||
private AdminService adminService;
|
||||
|
||||
@PostMapping("/loginAdmin")
|
||||
@WebLog(description = "登录")
|
||||
public String loginAdmin(@RequestParam("adminName")String adminName,@RequestParam("adminPassword")String adminPassword){
|
||||
Tadmin tadmin=adminService.loginAdmin(adminName,adminPassword);
|
||||
Admin tadmin=adminService.loginAdmin(adminName,adminPassword);
|
||||
if (tadmin!=null){
|
||||
return "登陆成功";
|
||||
}else {
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.february.mybatisplus.controller;
|
|||
|
||||
|
||||
|
||||
import com.february.mybatisplus.demo.Tcar;
|
||||
import com.february.mybatisplus.demo.Car;
|
||||
import com.february.mybatisplus.service.CarService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -27,7 +27,7 @@ public class CarController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
public ResponseEntity<?> add(@RequestBody Tcar tcar){
|
||||
public ResponseEntity<?> add(@RequestBody Car tcar){
|
||||
carService.add(tcar);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package com.february.mybatisplus.controller;
|
||||
|
||||
import com.february.mybatisplus.demo.Tuser;
|
||||
import com.february.mybatisplus.demo.User;
|
||||
import com.february.mybatisplus.service.UserService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
@ -18,7 +17,7 @@ public class UserController {
|
|||
private UserService userService;
|
||||
@PostMapping("/loginUser")
|
||||
public String loginUser(@RequestParam("userName")String userName,@RequestParam("userPassword")String userPassword){
|
||||
Tuser tuser=userService.loginUser(userName,userPassword);
|
||||
User tuser=userService.loginUser(userName,userPassword);
|
||||
if (tuser!=null){
|
||||
return "登陆成功";
|
||||
}else {
|
||||
|
|
|
@ -9,14 +9,12 @@ import lombok.Builder;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("t_admin")
|
||||
public class Tadmin {
|
||||
public class Admin {
|
||||
@TableId(value = "admin_id",type = IdType.AUTO)
|
||||
private Integer adminId;
|
||||
@TableField("admin_name")
|
|
@ -1,9 +1,6 @@
|
|||
package com.february.mybatisplus.demo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
@ -14,15 +11,16 @@ import lombok.NoArgsConstructor;
|
|||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("t_car")
|
||||
public class Tcar {
|
||||
|
||||
public class Car {
|
||||
//主键id
|
||||
@TableId(value = "car_id", type = IdType.AUTO)
|
||||
private Integer carId;
|
||||
//vin
|
||||
@TableField("`car_vin`")
|
||||
// @TableField(condition = SqlCondition))
|
||||
private String carVin;
|
||||
//车牌号
|
||||
@TableField("`car_bh`")
|
||||
@TableField(value = "car_bh",exist = true,condition = SqlCondition.LIKE)
|
||||
private String carBh;
|
||||
//车型id
|
||||
@TableField("car_type_id")
|
|
@ -14,7 +14,7 @@ import lombok.NoArgsConstructor;
|
|||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("t_city")
|
||||
public class Tcity {
|
||||
public class City {
|
||||
@TableId(value = "city_id",type = IdType.AUTO)
|
||||
private Integer cityId;
|
||||
@TableField("province_id")
|
|
@ -14,7 +14,7 @@ import lombok.NoArgsConstructor;
|
|||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("t_county")
|
||||
public class Tcounty {
|
||||
public class County {
|
||||
@TableId(value = "county_id",type = IdType.AUTO)
|
||||
private Integer countyId;
|
||||
@TableField("city_id")
|
|
@ -14,7 +14,7 @@ import lombok.NoArgsConstructor;
|
|||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("t_prcvince")
|
||||
public class Tprovince {
|
||||
public class Province {
|
||||
@TableId(value = "province_id",type = IdType.AUTO)
|
||||
private Integer provinceId;
|
||||
@TableField("province_name")
|
|
@ -14,7 +14,7 @@ import lombok.NoArgsConstructor;
|
|||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("t_user")
|
||||
public class Tuser {
|
||||
public class User {
|
||||
@TableId(value = "user_id",type = IdType.AUTO)
|
||||
private Integer userId;
|
||||
@TableField("user_name")
|
|
@ -1,7 +1,7 @@
|
|||
package com.february.mybatisplus.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.february.mybatisplus.demo.Tadmin;
|
||||
import com.february.mybatisplus.demo.Admin;
|
||||
|
||||
public interface AdminMapper extends BaseMapper<Tadmin> {
|
||||
public interface AdminMapper extends BaseMapper<Admin> {
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package com.february.mybatisplus.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.february.mybatisplus.demo.Tcar;
|
||||
import com.february.mybatisplus.demo.Car;
|
||||
|
||||
public interface CarMapper extends BaseMapper<Tcar> {
|
||||
public interface CarMapper extends BaseMapper<Car> {
|
||||
|
||||
void add(Tcar tcar);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.february.mybatisplus.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.february.mybatisplus.demo.Tuser;
|
||||
import com.february.mybatisplus.demo.User;
|
||||
|
||||
public interface UserMapper extends BaseMapper<Tuser> {
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.february.mybatisplus.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.february.mybatisplus.demo.Tadmin;
|
||||
import com.february.mybatisplus.demo.Admin;
|
||||
|
||||
public interface AdminService extends IService<Tadmin> {
|
||||
public interface AdminService extends IService<Admin> {
|
||||
|
||||
Tadmin loginAdmin(String adminName, String adminPassword);
|
||||
Admin loginAdmin(String adminName, String adminPassword);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
package com.february.mybatisplus.service;
|
||||
|
||||
import com.february.mybatisplus.demo.Tcar;
|
||||
import com.february.mybatisplus.mapper.CarMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.february.mybatisplus.demo.Car;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class CarService {
|
||||
@Autowired
|
||||
private CarMapper carMapper;
|
||||
public void add(Tcar tcar){
|
||||
carMapper.add(tcar);
|
||||
}
|
||||
|
||||
public interface CarService extends IService<Car> {
|
||||
|
||||
void add(Car tcar);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.february.mybatisplus.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.february.mybatisplus.demo.Tuser;
|
||||
import com.february.mybatisplus.demo.User;
|
||||
|
||||
public interface UserService extends IService<Tuser> {
|
||||
Tuser loginUser(String userName, String userPassword);
|
||||
public interface UserService extends IService<User> {
|
||||
User loginUser(String userName, String userPassword);
|
||||
}
|
||||
|
|
|
@ -2,17 +2,17 @@ package com.february.mybatisplus.service.impl;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.february.mybatisplus.demo.Tadmin;
|
||||
import com.february.mybatisplus.demo.Admin;
|
||||
import com.february.mybatisplus.mapper.AdminMapper;
|
||||
import com.february.mybatisplus.service.AdminService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Tadmin> implements AdminService {
|
||||
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
|
||||
@Override
|
||||
public Tadmin loginAdmin(String adminName, String adminPassword) {
|
||||
QueryWrapper<Tadmin> queryWrapper=new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(Tadmin::getAdminName,adminName).eq(Tadmin::getAdminPassword,adminPassword);
|
||||
public Admin loginAdmin(String adminName, String adminPassword) {
|
||||
QueryWrapper<Admin> queryWrapper=new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(Admin::getAdminName,adminName).eq(Admin::getAdminPassword,adminPassword);
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.february.mybatisplus.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.february.mybatisplus.demo.Car;
|
||||
import com.february.mybatisplus.mapper.CarMapper;
|
||||
import com.february.mybatisplus.service.CarService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 添加impl
|
||||
*
|
||||
* @author LiuJiaXin
|
||||
* @version 2023/11/23 - 20:35
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements CarService {
|
||||
|
||||
@Autowired
|
||||
private CarMapper carMapper;
|
||||
@Override
|
||||
public void add(Car tcar) {
|
||||
carMapper.insert(tcar);
|
||||
}
|
||||
}
|
|
@ -2,17 +2,17 @@ package com.february.mybatisplus.service.impl;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.february.mybatisplus.demo.Tuser;
|
||||
import com.february.mybatisplus.demo.User;
|
||||
import com.february.mybatisplus.mapper.UserMapper;
|
||||
import com.february.mybatisplus.service.UserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, Tuser> implements UserService {
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
||||
@Override
|
||||
public Tuser loginUser(String userName, String userPassword) {
|
||||
QueryWrapper<Tuser> tuserQueryWrapper = new QueryWrapper<>();
|
||||
tuserQueryWrapper.lambda().eq(Tuser::getUserName,userName).eq(Tuser::getUserPassword,userPassword);
|
||||
public User loginUser(String userName, String userPassword) {
|
||||
QueryWrapper<User> tuserQueryWrapper = new QueryWrapper<>();
|
||||
tuserQueryWrapper.lambda().eq(User::getUserName,userName).eq(User::getUserPassword,userPassword);
|
||||
return this.getOne(tuserQueryWrapper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,21 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-undertow</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
<!-- aop 依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<!-- 用于日志切面中,以 json 格式打印出入参 -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.february.merchant;
|
|||
|
||||
import com.february.common.security.annotation.EnableCustomConfig;
|
||||
import com.february.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.february.merchant.apect;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 切面类
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
@Documented
|
||||
public @interface WebLog {
|
||||
/**
|
||||
* 日志描述信息
|
||||
* @return
|
||||
**/
|
||||
String description() default "";
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.february.merchant.apect;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* AOP日志
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class WebLogAspect {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(WebLogAspect.class);
|
||||
private static final Gson gson = new Gson(); // 用于重复使用Gson实例
|
||||
private static final String LINE_SEPARATOR = System.lineSeparator();
|
||||
|
||||
@Pointcut("@annotation(com.february.merchant.apect.WebLog)")
|
||||
public void webLog() {}
|
||||
|
||||
@Before("webLog()")
|
||||
public void doBefore(JoinPoint joinPoint) {
|
||||
// 开始打印请求日志
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (attributes != null) {
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
|
||||
// 获取 @WebLog 注解的描述信息
|
||||
String methodDescription;
|
||||
try {
|
||||
methodDescription = getAspectLogDescription(joinPoint);
|
||||
} catch (Exception e) {
|
||||
methodDescription = "无法获取方法描述信息";
|
||||
logger.error("获取方法描述信息时发生异常: ", e);
|
||||
}
|
||||
|
||||
// 打印请求相关参数
|
||||
logger.info("========================================== Start ==========================================");
|
||||
logger.info("URL : {}", request.getRequestURL().toString());
|
||||
logger.info("Description : {}", methodDescription);
|
||||
logger.info("HTTP Method : {}", request.getMethod());
|
||||
logger.info("Class Method : {}.{}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());
|
||||
logger.info("IP : {}", request.getRemoteAddr());
|
||||
logger.info("Request Args : {}", gson.toJson(joinPoint.getArgs()));
|
||||
}
|
||||
}
|
||||
|
||||
@After("webLog()")
|
||||
public void doAfter() {
|
||||
logger.info("=========================================== End ==========================================={}", LINE_SEPARATOR);
|
||||
}
|
||||
|
||||
@Around("webLog()")
|
||||
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
|
||||
long startTime = System.currentTimeMillis();
|
||||
Object result = proceedingJoinPoint.proceed();
|
||||
logger.info("Response Args : {}", gson.toJson(result));
|
||||
logger.info("Time-Consuming : {} ms", System.currentTimeMillis() - startTime);
|
||||
return result;
|
||||
}
|
||||
|
||||
private String getAspectLogDescription(JoinPoint joinPoint) throws ClassNotFoundException {
|
||||
String targetName = joinPoint.getTarget().getClass().getName();
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
Object[] arguments = joinPoint.getArgs();
|
||||
Class<?> targetClass = Class.forName(targetName);
|
||||
Method[] methods = targetClass.getMethods();
|
||||
for (Method method : methods) {
|
||||
if (method.getName().equals(methodName) && method.getParameterTypes().length == arguments.length) {
|
||||
WebLog webLog = method.getAnnotation(WebLog.class);
|
||||
if (webLog != null) {
|
||||
return webLog.description();
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package com.february.merchant.controller;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import com.february.common.core.domain.Result;
|
||||
import com.february.merchant.apect.WebLog;
|
||||
import com.february.merchant.service.AddCarService;
|
||||
import com.february.system.domain.Tadmin;
|
||||
import com.february.system.domain.Tcar;
|
||||
|
@ -37,13 +38,14 @@ public class AddCarController {
|
|||
* 根据用户名获取用户信息
|
||||
*/
|
||||
@PostMapping("/findByadminName/{adminName}")
|
||||
@WebLog(description = "根据用户名获取用户信息")
|
||||
public Result<Tadmin> findByadminName(@PathVariable String adminName){
|
||||
log.info("功能名称:根据用户名获取用户信息,请求URI:{},请求方式:{},请求参数:{}"
|
||||
,request.getRequestURI(),request.getMethod(),adminName);
|
||||
//log.info("功能名称:根据用户名获取用户信息,请求URI:{},请求方式:{},请求参数:{}"
|
||||
//,request.getRequestURI(),request.getMethod(),adminName);
|
||||
Tadmin tadmin=addCarService.findByadminName(adminName);
|
||||
Result<Tadmin> result = Result.success(tadmin);
|
||||
log.info("功能名称:根据用户名获取用户信息,响应URI:{},相应方式:{},响应结果:{}"
|
||||
,request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(result));
|
||||
//log.info("功能名称:根据用户名获取用户信息,响应URI:{},相应方式:{},响应结果:{}"
|
||||
//,request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.hn.yuan;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* 启动类
|
||||
*
|
||||
* @author LiuJiaXin
|
||||
* @version 2023/11/23 - 0:06
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.hn.yuan.mapper")
|
||||
public class Apply {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Apply.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.hn.yuan.common.dao;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 实体类
|
||||
*
|
||||
* @author LiuJiaXin
|
||||
* @version 2023/11/22 - 21:53
|
||||
*/
|
||||
@Data
|
||||
public class BaseController {
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.hn.yuan.common.entily;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 类
|
||||
*
|
||||
* @author LiuJiaXin
|
||||
* @version 2023/11/22 - 21:55
|
||||
*/
|
||||
public class BaseEntity implements Serializable {
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.hn.yuan.common.entily;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Result
|
||||
*
|
||||
* @author LiuJiaXin
|
||||
* @version 2023/11/22 - 21:58
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Result {
|
||||
private String code;
|
||||
private Object data;
|
||||
private String msg;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
server:
|
||||
port: 9223
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://10.100.1.2:3306/car?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: wuzu123...
|
|
@ -0,0 +1,55 @@
|
|||
package com.february.merchant.springboot.apply;
|
||||
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.PackageConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
|
||||
/**
|
||||
* 启动类
|
||||
*
|
||||
* @author LiuJiaXin
|
||||
* @version 2023/11/22 - 19:06
|
||||
*/
|
||||
public class MysqlGenerator {
|
||||
public static void main(String[] args) {
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
//全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
String projectPath = System.getProperty("user.dir");
|
||||
gc.setOutputDir(projectPath + "/february-merchant-springboot/src/main/java");
|
||||
gc.setAuthor("XIAOCAO");
|
||||
gc.setOpen(false);
|
||||
gc.setFileOverride(true);
|
||||
gc.setServiceName("%Service");
|
||||
gc.setBaseResultMap(true);
|
||||
mpg.setGlobalConfig(gc);
|
||||
//数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setUrl("jdbc:mysql://10.100.1.2:3306/car?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
|
||||
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
||||
dsc.setUsername("root");
|
||||
dsc.setPassword("wuzu123...");
|
||||
mpg.setDataSource(dsc);
|
||||
//包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
pc.setParent("com.hn.yuan");
|
||||
mpg.setPackageInfo(pc);
|
||||
//策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setSuperControllerClass("com");
|
||||
strategy.setSuperEntityClass("com");
|
||||
|
||||
strategy.setEntityBuilderModel(true);
|
||||
strategy.setRestControllerStyle(true);
|
||||
|
||||
strategy.setInclude("chinas");
|
||||
mpg.setStrategy(strategy);
|
||||
//执行
|
||||
mpg.execute();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.february.merchant.springboot.demo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 省市区
|
||||
*
|
||||
* @author LiuJiaXin
|
||||
* @version 2023/11/22 - 14:43
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class chinas {
|
||||
private Integer id;
|
||||
private Integer code;
|
||||
private String name;
|
||||
private Integer pid;
|
||||
private String level;
|
||||
}
|
Loading…
Reference in New Issue