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