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

关于建设网站的书本建立网站有哪些步骤

关于建设网站的书本,建立网站有哪些步骤,可以免费建立网站吗,济南做网站的公司自定义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/496510.html

相关文章:

  • 网站内容建设需要注意哪些问题成都网站seo外包
  • 邯郸房产网签查询系统免费seo快速收录工具
  • 网页不能运行wordpress十堰seo优化方法
  • 独立站工具广州seo关键词优化外包
  • 互联网技术学校公司的seo是什么意思
  • asp.net网站开发菜鸟自己怎么创建一个网站
  • 网站制作制作网络营销的策划流程
  • 佛山自定义网站建设营销培训机构哪家最专业
  • html5网站案例江苏百度推广代理商
  • 深圳罗湖网站建设公司外贸推广平台排名
  • 南宁网站制作公司哪家好网址导航浏览器下载
  • 微网站如何做微信支付百度指数官网
  • 网站建设费是什么河南郑州最新事件
  • 网站建设如何报价数字营销策略有哪些
  • 网站模块 带采集app推广方案策划
  • 网站怎么做 吸引人微信客户管理
  • 做一个购物网站价格seo的推广技巧
  • 康体设备网站建设爱网站查询挖掘工具
  • 网站建设以后就业方向优化推广公司哪家好
  • 前端做网站需要学什么软件做公司网站需要多少钱
  • 网站案例模版谷歌play
  • 营销型网站建设专家代发新闻稿最大平台
  • 用源码怎么做网站谷歌官网注册入口
  • 哪个新闻网站好郑州seo顾问培训
  • 网站开发者模式有什么用免费注册网站有哪些
  • 做简单的html网站网站结构有哪几种
  • 中国域名网站站内关键词自然排名优化
  • vs用户登录注册网站建设代码seo信息查询
  • 亚马逊雨林有原始人吗seo课程培训入门
  • 新疆省建设厅网站百度指数需求图谱