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

威宁住房和城乡建设局网站wordpress is ssl

威宁住房和城乡建设局网站,wordpress is ssl,郑州平台制作,公众号开发商咨询电话自定义mybatis拦截器,在springboot项目中不起作用的解决方法 自定义mybatis拦截器,在若依springboot项目中不起作用的原因 找到 MyBatisConfig 配置类,引入自定义配置 在sqlSessionFactory中添加自定义拦截器,就可以正常使用了…

自定义mybatis拦截器,在springboot项目中不起作用的解决方法

自定义mybatis拦截器,在若依springboot项目中不起作用的原因

找到 MyBatisConfig 配置类,引入自定义配置
在这里插入图片描述
在sqlSessionFactory中添加自定义拦截器,就可以正常使用了
在这里插入图片描述

package com.lingxu.framework.config;import com.lingxu.common.core.domain.model.LoginUser;
import com.lingxu.common.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.binding.MapperMethod.ParamMap;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.plugin.*;
import org.springframework.stereotype.Component;import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;/*** mybatis拦截器,自动注入创建人、创建时间、修改人、修改时间* @Author scott* @Date  2019-01-19**/
@Slf4j
@Component
@Intercepts({ @Signature(type = Executor.class, method = "update", args = { MappedStatement.class, Object.class }) })
public class MybatisInterceptor implements Interceptor {@Overridepublic Object intercept(Invocation invocation) throws Throwable {MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];String sqlId = mappedStatement.getId();log.debug("------sqlId------" + sqlId);SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType();Object parameter = invocation.getArgs()[1];log.debug("------sqlCommandType------" + sqlCommandType);if (parameter == null) {return invocation.proceed();}if (SqlCommandType.INSERT == sqlCommandType) {LoginUser sysUser = this.getLoginUser();Field[] fields = this.getAllFields(parameter);assert fields != null;for (Field field : fields) {log.debug("------field.name------" + field.getName());try {if ("createBy".equals(field.getName())) {field.setAccessible(true);Object local_createBy = field.get(parameter);field.setAccessible(false);if (local_createBy == null || local_createBy.equals("")) {if (sysUser != null) {// 登录人账号field.setAccessible(true);field.set(parameter, sysUser.getUserId());field.setAccessible(false);}}}if ("createName".equals(field.getName())) {field.setAccessible(true);Object local_createBy = field.get(parameter);field.setAccessible(false);if (local_createBy == null || local_createBy.equals("")) {if (sysUser != null) {// 登录人账号field.setAccessible(true);field.set(parameter, sysUser.getUser().getNickName());field.setAccessible(false);}}}// 注入创建时间if ("createTime".equals(field.getName())) {field.setAccessible(true);Object local_createDate = field.get(parameter);field.setAccessible(false);if (local_createDate == null || local_createDate.equals("")) {field.setAccessible(true);field.set(parameter, new Date());field.setAccessible(false);}}} catch (Exception e) {}}}if (SqlCommandType.UPDATE == sqlCommandType) {LoginUser sysUser = this.getLoginUser();Field[] fields = null;if (parameter instanceof ParamMap) {ParamMap<?> p = (ParamMap<?>) parameter;//update-begin-author:scott date:20190729 for:批量更新报错issues/IZA3Q--if (p.containsKey("et")) {parameter = p.get("et");} else {parameter = p.get("param1");}//update-end-author:scott date:20190729 for:批量更新报错issues/IZA3Q-//update-begin-author:scott date:20190729 for:更新指定字段时报错 issues/#516-if (parameter == null) {return invocation.proceed();}//update-end-author:scott date:20190729 for:更新指定字段时报错 issues/#516-fields = this.getAllFields(parameter);} else {fields = this.getAllFields(parameter);}for (Field field : fields) {field.setAccessible(true);log.debug("------field.name------" + field.getName());try {if ("updateBy".equals(field.getName())) {//获取登录用户信息if (sysUser != null) {// 登录账号field.set(parameter, sysUser.getUserId());field.setAccessible(false);}}if ("updateTime".equals(field.getName())) {field.set(parameter, new Date());field.setAccessible(false);}} catch (Exception e) {e.printStackTrace();}}}return invocation.proceed();}@Overridepublic Object plugin(Object target) {return Plugin.wrap(target, this);}private LoginUser getLoginUser() {LoginUser userNow = null;try {
//			try catch避免线程任务出错userNow = SecurityUtils.getLoginUser() != null ? SecurityUtils.getLoginUser() : null;} catch (Exception e) {//e.printStackTrace();}return userNow;}/*** 获取类的所有属性,包括父类** @param object* @return*/public Field[] getAllFields(Object object) {Class<?> clazz = object.getClass();if(clazz==null){return  null;}List<Field> fieldList = new ArrayList<>();while (clazz != null) {fieldList.addAll(new ArrayList<>(Arrays.asList(clazz.getDeclaredFields())));clazz = clazz.getSuperclass();}Field[] fields = new Field[fieldList.size()];fieldList.toArray(fields);return fields;}}
http://www.dtcms.com/a/580874.html

相关文章:

  • 网站域名缴费wordpress怎么改登陆地址
  • 网站底备案号链接代码小程序登录入口qq浏览器
  • 电商网站建设功能个人网页免费域名注册入口
  • 网站建设所用系统没有文字的网站怎么优化
  • 站长工具seo综合查询隐私查询做网站功能
  • 扬州市广陵区建设局网站做代理稳妥的彩票网站有哪些
  • 软件下载类型网站怎么做建筑公司资质甲级乙级
  • 自己建站百度企业查询官网
  • 如皋建设网站wordpress中级教程
  • 正规轻电商网站模板做美足网站违法吗
  • 可以做本地生活服务的有哪些网站平面设计作品欣赏官网
  • 专业网站托管的公司免费咨询医院
  • 温州哪里有做网站怎么查公司企业邮箱
  • 什么叫网站维护整站优化提升排名
  • 广东联通通信建设有限公司 网站王烨画家
  • 金属网站模板石家庄做网站公司
  • 英文网站网站建设深圳网站备案
  • 商城网站开发技术有哪些外卖网站建设可行性分析
  • a5做网站wordpress文章导入公众号
  • 柳市网站建设公司做网站需要多大尺寸
  • 网站全面推广方案土地流转网站建设项目
  • 沈阳营商环境建设局网站重点建设专业 专题网站
  • 阿里云重新备案注销主体还是注销网站微信公众号优惠和网站绑定怎么做
  • 采集做网站企业网站使用不规范地图如何处罚
  • iis网站防盗链苏州网站优化维护
  • 企业做网站能赚钱么武昌做网站jw100
  • 申请建设网站经费申请软件编程毕业设计代做网站
  • 郑州建设网站报价小程序一年服务费多少钱
  • 青岛建设银行网站广东手机网站开发多少
  • 网站首页广告代码青岛百度推广优化怎么做的