当前位置: 首页 > news >正文

青州网站建设qzfuwuwordpress分类下文章排序

青州网站建设qzfuwu,wordpress分类下文章排序,百数低代码开发平台,智能建站软件哪个好[公共字段自动填充] 核心:在切面类中捕获需要填充公共字段的 Mapper 方法,方法上使用注解加以标识,通过反射拿到需要填充的字段赋值方法,进行赋值操作 1、自定义注解 AutoFill Target(ElementType.METHOD) Retention(RetentionPo…

[公共字段自动填充]

核心:在切面类中捕获需要填充公共字段的 Mapper 方法,方法上使用注解加以标识,通过反射拿到需要填充的字段赋值方法,进行赋值操作

1、自定义注解 AutoFill

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface AutoFill {//数据库操作类型:UPDATE INSERTOperationType value();
}

2、枚举对象类

public enum OperationType {/*** 更新操作*/UPDATE,/*** 插入操作*/INSERT
}

3、自定义切面 AutoFillAspect

@Aspect
@Component
@Slf4j
public class AutoFillAspect {/*** 切入点*/@Pointcut("execution(* com.sky.mapper.*.*(..)) && @annotation(com.sky.annotation.AutoFill)")public void autoFillPointCut(){}/*** 前置通知,在通知中进行公共字段的赋值*/@Before("autoFillPointCut()")public void autoFill(JoinPoint joinPoint){log.info("开始进行公共字段自动填充...");//获取到当前被拦截的方法上的数据库操作类型MethodSignature signature = (MethodSignature) joinPoint.getSignature();//方法签名对象AutoFill autoFill = signature.getMethod().getAnnotation(AutoFill.class);//获得方法上的注解对象OperationType operationType = autoFill.value();//获得数据库操作类型//获取到当前被拦截的方法的参数--实体对象Object[] args = joinPoint.getArgs();if(args == null || args.length == 0){return;}//约定好放在第一个参数位置Object entity = args[0];//准备赋值的数据LocalDateTime now = LocalDateTime.now();Long currentId = BaseContext.getCurrentId();//就是获取修改人的id值,不同项目不同的获取方法//根据当前不同的操作类型,为对应的属性通过反射来赋值if(operationType == OperationType.INSERT){//为4个公共字段赋值try {Method setCreateTime = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_CREATE_TIME, LocalDateTime.class);Method setCreateUser = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_CREATE_USER, Long.class);Method setUpdateTime = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_UPDATE_TIME, LocalDateTime.class);Method setUpdateUser = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_UPDATE_USER, Long.class);//通过反射为对象属性赋值setCreateTime.invoke(entity,now);setCreateUser.invoke(entity,currentId);setUpdateTime.invoke(entity,now);setUpdateUser.invoke(entity,currentId);} catch (Exception e) {e.printStackTrace();}}else if(operationType == OperationType.UPDATE){//为2个公共字段赋值try {Method setUpdateTime = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_UPDATE_TIME, LocalDateTime.class);Method setUpdateUser = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_UPDATE_USER, Long.class);//通过反射为对象属性赋值setUpdateTime.invoke(entity,now);setUpdateUser.invoke(entity,currentId);} catch (Exception e) {e.printStackTrace();}}}
}

4、在Mapper接口的方法上加入 AutoFill 注解

@Mapper
public interface CategoryMapper {/*** 插入数据* @param category*/@AutoFill(value = OperationType.INSERT)void insert(Category category);/*** 根据id修改分类* @param category*/@AutoFill(value = OperationType.UPDATE)void update(Category category);}
http://www.yayakq.cn/news/126516/

相关文章:

  • 中国建设银行网站密码是什么昆明小程序公司
  • 接单做网站怎么开价格南宁建网站
  • 台州自助建站在线咨询wordpress的用户管理实现原理
  • 企业做网站电话约见客户的对话7一12岁手工科技小制作
  • wordpress首页分辨率外贸网站seo怎么做
  • 查建筑公司网站吴中seo网站优化软件
  • 班级网站模板html武宁网站ui专业设计
  • 建立问答类的网站内涵 网站 源码
  • 个人网站多少钱外包公司有哪些
  • 邯郸网站建设咨询安联网络门户网站那个程序比较
  • 速效成交型网站平面设计软件大全免费
  • 外贸在什么网站做天津众业建设工程有限公司网站
  • html5网站演示大连企业网站模板
  • jsp网站开发实例pdf青岛李沧区城乡建设局网站
  • 海南网站建设及维护深圳网站建设服务哪家好
  • 阜宁企业做网站多少钱公司装修开工大吉贺词
  • 123手机浏览器wordpress商城主题 优化
  • 哪些网站是503错误代码wordpress模板企业
  • 旅游网站怎么做才能被关注香水推广软文
  • 我做网站编辑写文章很慢怎么办中国建筑招聘官方网站
  • 标准化信息网站建设与应用公司网页设计说明300
  • 黄埭做网站建设一个营销网站的费用
  • a5创业网站建设科协建设网站 方案
  • 电商网站制作项目描述crm管理系统功能
  • 做响应式网站图片需要做几版网站开发 教材
  • 网站代码优化调整陕西培训网站建设
  • 竞价网站单页面购物网站制作免费
  • 青岛正规网站设计公司个人网页设计作品简笔画
  • 网站301设置微信公众号怎么上架商品
  • 专业做国际网站的公司微信版网站开发