diff --git a/february-merchant-mybatis-plus/pom.xml b/february-merchant-mybatis-plus/pom.xml
index 7956727..52af634 100644
--- a/february-merchant-mybatis-plus/pom.xml
+++ b/february-merchant-mybatis-plus/pom.xml
@@ -138,6 +138,16 @@
h2
runtime
-
+
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
+
+
+ com.google.code.gson
+ gson
+ 2.8.5
+
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/apect/WebLog.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/apect/WebLog.java
new file mode 100644
index 0000000..d6bfbc9
--- /dev/null
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/apect/WebLog.java
@@ -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 "";
+}
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/apect/WebLogAspect.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/apect/WebLogAspect.java
new file mode 100644
index 0000000..7d00b53
--- /dev/null
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/apect/WebLogAspect.java
@@ -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 "";
+ }
+}
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/AdminController.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/AdminController.java
index b3d3324..9b71fbf 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/AdminController.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/AdminController.java
@@ -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 {
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/CarController.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/CarController.java
index 62524e5..05b7bdd 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/CarController.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/CarController.java
@@ -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();
}
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/UserController.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/UserController.java
index da205a5..f8c520f 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/UserController.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/UserController.java
@@ -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 {
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tadmin.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Admin.java
similarity index 93%
rename from february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tadmin.java
rename to february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Admin.java
index 904c271..8c1feaa 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tadmin.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Admin.java
@@ -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")
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tcar.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Car.java
similarity index 77%
rename from february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tcar.java
rename to february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Car.java
index 2cd411e..6d998df 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tcar.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Car.java
@@ -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")
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tcity.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/City.java
similarity index 96%
rename from february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tcity.java
rename to february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/City.java
index b2b2930..b2f7d7f 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tcity.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/City.java
@@ -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")
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tcounty.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/County.java
similarity index 96%
rename from february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tcounty.java
rename to february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/County.java
index 532abbb..50d17f6 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tcounty.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/County.java
@@ -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")
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tprovince.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Province.java
similarity index 95%
rename from february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tprovince.java
rename to february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Province.java
index 1c21755..346c39c 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tprovince.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Province.java
@@ -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")
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tuser.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/User.java
similarity index 97%
rename from february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tuser.java
rename to february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/User.java
index 337c100..39959d9 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tuser.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/User.java
@@ -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")
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/AdminMapper.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/AdminMapper.java
index a54e1da..f659b61 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/AdminMapper.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/AdminMapper.java
@@ -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 {
+public interface AdminMapper extends BaseMapper {
}
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/CarMapper.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/CarMapper.java
index 0c80dcc..3df7d29 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/CarMapper.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/CarMapper.java
@@ -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 {
+public interface CarMapper extends BaseMapper {
- void add(Tcar tcar);
}
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/UserMapper.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/UserMapper.java
index 5d3dc97..80ee683 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/UserMapper.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/UserMapper.java
@@ -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 {
+public interface UserMapper extends BaseMapper {
}
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/AdminService.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/AdminService.java
index e3ca8a3..edd6774 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/AdminService.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/AdminService.java
@@ -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 {
+public interface AdminService extends IService {
- Tadmin loginAdmin(String adminName, String adminPassword);
+ Admin loginAdmin(String adminName, String adminPassword);
}
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/CarService.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/CarService.java
index db2fda3..56bb9b7 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/CarService.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/CarService.java
@@ -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 {
+
+ void add(Car tcar);
}
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/UserService.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/UserService.java
index 667f737..e735f11 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/UserService.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/UserService.java
@@ -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 loginUser(String userName, String userPassword);
+public interface UserService extends IService {
+ User loginUser(String userName, String userPassword);
}
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/AdminServiceImpl.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/AdminServiceImpl.java
index 35105b7..e7c16e1 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/AdminServiceImpl.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/AdminServiceImpl.java
@@ -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 implements AdminService {
+public class AdminServiceImpl extends ServiceImpl implements AdminService {
@Override
- public Tadmin loginAdmin(String adminName, String adminPassword) {
- QueryWrapper queryWrapper=new QueryWrapper<>();
- queryWrapper.lambda().eq(Tadmin::getAdminName,adminName).eq(Tadmin::getAdminPassword,adminPassword);
+ public Admin loginAdmin(String adminName, String adminPassword) {
+ QueryWrapper queryWrapper=new QueryWrapper<>();
+ queryWrapper.lambda().eq(Admin::getAdminName,adminName).eq(Admin::getAdminPassword,adminPassword);
return this.getOne(queryWrapper);
}
}
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/CarServiceImpl.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/CarServiceImpl.java
new file mode 100644
index 0000000..1d6c7c8
--- /dev/null
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/CarServiceImpl.java
@@ -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 implements CarService {
+
+ @Autowired
+ private CarMapper carMapper;
+ @Override
+ public void add(Car tcar) {
+ carMapper.insert(tcar);
+ }
+}
diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/UserServiceImpl.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/UserServiceImpl.java
index 5be1b10..abe02a3 100644
--- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/UserServiceImpl.java
+++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/UserServiceImpl.java
@@ -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 implements UserService {
+public class UserServiceImpl extends ServiceImpl implements UserService {
@Override
- public Tuser loginUser(String userName, String userPassword) {
- QueryWrapper tuserQueryWrapper = new QueryWrapper<>();
- tuserQueryWrapper.lambda().eq(Tuser::getUserName,userName).eq(Tuser::getUserPassword,userPassword);
+ public User loginUser(String userName, String userPassword) {
+ QueryWrapper tuserQueryWrapper = new QueryWrapper<>();
+ tuserQueryWrapper.lambda().eq(User::getUserName,userName).eq(User::getUserPassword,userPassword);
return this.getOne(tuserQueryWrapper);
}
}
diff --git a/february-merchant-server/pom.xml b/february-merchant-server/pom.xml
index 73df278..03ca44a 100644
--- a/february-merchant-server/pom.xml
+++ b/february-merchant-server/pom.xml
@@ -93,7 +93,21 @@
org.springframework.boot
spring-boot-starter-undertow
-
+
+ com.google.code.gson
+ gson
+
+
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
+
+
+ com.google.code.gson
+ gson
+ 2.8.5
+
diff --git a/february-merchant-server/src/main/java/com/february/merchant/Main.java b/february-merchant-server/src/main/java/com/february/merchant/Main.java
index 95d31f5..d4053ae 100644
--- a/february-merchant-server/src/main/java/com/february/merchant/Main.java
+++ b/february-merchant-server/src/main/java/com/february/merchant/Main.java
@@ -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;
diff --git a/february-merchant-server/src/main/java/com/february/merchant/apect/WebLog.java b/february-merchant-server/src/main/java/com/february/merchant/apect/WebLog.java
new file mode 100644
index 0000000..c8fab55
--- /dev/null
+++ b/february-merchant-server/src/main/java/com/february/merchant/apect/WebLog.java
@@ -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 "";
+}
diff --git a/february-merchant-server/src/main/java/com/february/merchant/apect/WebLogAspect.java b/february-merchant-server/src/main/java/com/february/merchant/apect/WebLogAspect.java
new file mode 100644
index 0000000..4bdafce
--- /dev/null
+++ b/february-merchant-server/src/main/java/com/february/merchant/apect/WebLogAspect.java
@@ -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 "";
+ }
+}
diff --git a/february-merchant-server/src/main/java/com/february/merchant/controller/AddCarController.java b/february-merchant-server/src/main/java/com/february/merchant/controller/AddCarController.java
index fd65bda..b15f8fc 100644
--- a/february-merchant-server/src/main/java/com/february/merchant/controller/AddCarController.java
+++ b/february-merchant-server/src/main/java/com/february/merchant/controller/AddCarController.java
@@ -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 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 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;
}
diff --git a/february-merchant-springboot/src/main/java/com/hn/yuan/Apply.java b/february-merchant-springboot/src/main/java/com/hn/yuan/Apply.java
new file mode 100644
index 0000000..3b13354
--- /dev/null
+++ b/february-merchant-springboot/src/main/java/com/hn/yuan/Apply.java
@@ -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);
+ }
+}
diff --git a/february-merchant-springboot/src/main/java/com/hn/yuan/common/dao/BaseController.java b/february-merchant-springboot/src/main/java/com/hn/yuan/common/dao/BaseController.java
new file mode 100644
index 0000000..cd681f6
--- /dev/null
+++ b/february-merchant-springboot/src/main/java/com/hn/yuan/common/dao/BaseController.java
@@ -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 {
+}
diff --git a/february-merchant-springboot/src/main/java/com/hn/yuan/common/entily/BaseEntity.java b/february-merchant-springboot/src/main/java/com/hn/yuan/common/entily/BaseEntity.java
new file mode 100644
index 0000000..9f6c0ee
--- /dev/null
+++ b/february-merchant-springboot/src/main/java/com/hn/yuan/common/entily/BaseEntity.java
@@ -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 {
+}
diff --git a/february-merchant-springboot/src/main/java/com/hn/yuan/common/entily/Result.java b/february-merchant-springboot/src/main/java/com/hn/yuan/common/entily/Result.java
new file mode 100644
index 0000000..327d17f
--- /dev/null
+++ b/february-merchant-springboot/src/main/java/com/hn/yuan/common/entily/Result.java
@@ -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;
+
+
+}
diff --git a/february-merchant-springboot/src/main/resources/application.yml b/february-merchant-springboot/src/main/resources/application.yml
new file mode 100644
index 0000000..e7cdac6
--- /dev/null
+++ b/february-merchant-springboot/src/main/resources/application.yml
@@ -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...
diff --git a/february-merchant-springboot/src/test/java/com/february/merchant/springboot/apply/MysqlGenerator.java b/february-merchant-springboot/src/test/java/com/february/merchant/springboot/apply/MysqlGenerator.java
new file mode 100644
index 0000000..d1b9adf
--- /dev/null
+++ b/february-merchant-springboot/src/test/java/com/february/merchant/springboot/apply/MysqlGenerator.java
@@ -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();
+ }
+}
diff --git a/february-merchant-springboot/src/test/java/com/february/merchant/springboot/demo/chinas.java b/february-merchant-springboot/src/test/java/com/february/merchant/springboot/demo/chinas.java
new file mode 100644
index 0000000..7238a49
--- /dev/null
+++ b/february-merchant-springboot/src/test/java/com/february/merchant/springboot/demo/chinas.java
@@ -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;
+}