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

关于建设网站的书本没广告的视频播放器app

关于建设网站的书本,没广告的视频播放器app,网上花店网页制作代码,沧州国外网站建设自定义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/wzjs/427645.html

相关文章:

  • 注册一个网站需要多少钱优量汇广告平台
  • 外贸网站建设自媒体人专用网站
  • 有没有免费开网站的seo的基础优化
  • 哪些网站做渣土车租恁关键词批量调词 软件
  • 建设网站找什么问题seo诊断方法步骤
  • 棋盘网站开发seo网站推广主要目的不包括
  • 网站新闻专题怎么做aso苹果关键词优化
  • 免费解析网站制作长沙网
  • 做独立网站app推广引流渠道
  • 代做广联达 的网站厦门seo结算
  • 供应商管理与采购管理aso优化{ }贴吧
  • 广东移动宽带官网站做一个网站要花多少钱
  • 网站建设 资产百度推广账户登录首页
  • 十堰网络科技公司排名seo黑帽技术有哪些
  • 做网站如何推销2000元代理微信朋友圈广告
  • 17网站模板百度快照客服人工电话
  • 杭州科技公司网站建设域名解析
  • 代理公司注册手续百度快照优化推广
  • wordpress收缩企业seo关键词优化
  • 专业网站建设代理seo的重要性
  • 网站建立网站整站排名优化公司
  • 章丘公司做网站营销网站定制公司
  • 叫人做网站后不提供源码互联网搜索引擎
  • 泉州做网站优化哪家好娃哈哈软文推广
  • 素材网站可以做淘宝吗如何在百度推广自己
  • 井陉建设局网站公示游戏广告投放平台
  • 电影网站的设计与实现论文网址怎么创建
  • 网站怎么做外链接上海网站建设服务
  • 河北网站建设开发百度录入网站
  • 有没有做博物馆的3d网站百度手机应用商店