公共字段自动填充:AOP切面//反射
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.sky.annotation.AutoFill;
|
||||
import com.sky.dto.CategoryPageQueryDTO;
|
||||
import com.sky.entity.Category;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -17,11 +19,13 @@ public interface CategoryMapper {
|
||||
|
||||
@Insert("insert into category(type, name, sort, status, create_time, update_time, create_user, update_user) " +
|
||||
"values (#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
|
||||
@AutoFill(OperationType.INSERT)
|
||||
void insert(Category category);
|
||||
|
||||
@Delete("delete from category where id = #{id}")
|
||||
void deleteById(long id);
|
||||
|
||||
@AutoFill(OperationType.UPDATE)
|
||||
void update(Category category);
|
||||
|
||||
@Select("select * from category where type = #{type}")
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.sky.annotation.AutoFill;
|
||||
import com.sky.dto.EmployeePageQueryDTO;
|
||||
import com.sky.entity.Employee;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
@@ -25,6 +27,7 @@ public interface EmployeeMapper {
|
||||
*/
|
||||
@Insert("insert into employee (name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user) " +
|
||||
"values (#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
|
||||
@AutoFill(OperationType.INSERT)
|
||||
void insert(Employee employee);
|
||||
|
||||
/**
|
||||
@@ -38,6 +41,7 @@ public interface EmployeeMapper {
|
||||
* 根据主键动态修改属性
|
||||
* @param employee
|
||||
*/
|
||||
@AutoFill(OperationType.UPDATE)
|
||||
void update(Employee employee);
|
||||
|
||||
@Select("select * from employee where id = #{id}")
|
||||
|
||||
@@ -62,10 +62,10 @@ public class CategoryServiceImpl implements CategoryService {
|
||||
BeanUtils.copyProperties(categoryDTO, category);
|
||||
//补充属性
|
||||
category.setStatus(StatusConstant.DISABLE);
|
||||
category.setCreateTime(LocalDateTime.now());
|
||||
category.setUpdateTime(LocalDateTime.now());
|
||||
category.setCreateUser(BaseContext.getCurrentId());
|
||||
category.setUpdateUser(BaseContext.getCurrentId());
|
||||
//category.setCreateTime(LocalDateTime.now());
|
||||
//category.setUpdateTime(LocalDateTime.now());
|
||||
//category.setCreateUser(BaseContext.getCurrentId());
|
||||
//category.setUpdateUser(BaseContext.getCurrentId());
|
||||
|
||||
categoryMapper.insert(category);
|
||||
}
|
||||
@@ -116,10 +116,9 @@ public class CategoryServiceImpl implements CategoryService {
|
||||
Category category = new Category();
|
||||
BeanUtils.copyProperties(categoryDTO, category);
|
||||
//设置属性
|
||||
category.setUpdateTime(LocalDateTime.now());
|
||||
category.setUpdateUser(BaseContext.getCurrentId());
|
||||
//category.setUpdateTime(LocalDateTime.now());
|
||||
//category.setUpdateUser(BaseContext.getCurrentId());
|
||||
|
||||
BaseContext.removeCurrentId();
|
||||
categoryMapper.update(category);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,13 +80,12 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
//设置属性
|
||||
employee.setStatus(StatusConstant.ENABLE);
|
||||
employee.setPassword(DigestUtils.md5DigestAsHex(PasswordConstant.DEFAULT_PASSWORD.getBytes()));
|
||||
employee.setCreateTime(LocalDateTime.now());
|
||||
employee.setUpdateTime(LocalDateTime.now());
|
||||
//employee.setCreateTime(LocalDateTime.now());
|
||||
//employee.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
// 设置为当前登录用户的ID
|
||||
employee.setCreateUser(BaseContext.getCurrentId());
|
||||
employee.setUpdateUser(BaseContext.getCurrentId());
|
||||
BaseContext.removeCurrentId();
|
||||
//employee.setCreateUser(BaseContext.getCurrentId());
|
||||
//employee.setUpdateUser(BaseContext.getCurrentId());
|
||||
|
||||
employeeMapper.insert(employee);
|
||||
}
|
||||
@@ -144,10 +143,9 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
Employee employee = new Employee();
|
||||
BeanUtils.copyProperties(employeeDTO, employee);
|
||||
|
||||
employee.setUpdateTime(LocalDateTime.now());
|
||||
employee.setUpdateUser(BaseContext.getCurrentId());
|
||||
//employee.setUpdateTime(LocalDateTime.now());
|
||||
//employee.setUpdateUser(BaseContext.getCurrentId());
|
||||
|
||||
BaseContext.removeCurrentId();
|
||||
employeeMapper.update(employee);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user