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

个人网站吗wordpress超精简主题

个人网站吗,wordpress超精简主题,mip网站实例,互联网网站建设彭聪学习地址#xff1a;https://www.bilibili.com/video/BV1TP411v7v6?p6spm_id_frompageDrivervd_sourcea6f7db332f104aff6fadf5b3542e5875 后端环境搭建 Entity 实体#xff0c;通常和数据库的表对应DTO 数据传输对象#xff0c;用于程序中各层之间传递数据 (前端…学习地址https://www.bilibili.com/video/BV1TP411v7v6?p6spm_id_frompageDrivervd_sourcea6f7db332f104aff6fadf5b3542e5875 后端环境搭建 Entity 实体通常和数据库的表对应DTO 数据传输对象用于程序中各层之间传递数据 (前端发过来)VO 视图对象为前端展示数据提供的对象返回前端POJO 普通java对象只有属性和对应的getter和setter Swagger使用 常用注解 一些优雅的方案 BeanUtils.copyProperties(a,b)将a对象上的值复制给b对象。 Budiler 在定义数据类的时候加上该注解在创建实例的时候可以使用链式调用。 Data Builder ApiOperation(value 查询返回数据) public class EmpPageVO {Integer count;ListEmployee data; } // 使用 EmpPageVO empPageVO EmpPageVO.builder().count(allCount).data(returnData).build();ThreadLocal每个线程都会创建一个互不影响可以将每次请求的用户信息存储起来后面需要用到直接取出来因为每个请求都是一个单独的线程互不影响。 定义类 // spring boot 每个请求都由一个线程处理 public class UserContext {public static ThreadLocalUserContextDTO threadLocal new ThreadLocal();public static void setCurrentUser(UserContextDTO user){threadLocal.set(user);}public static UserContextDTO getCurrentUser(){return threadLocal.get();}public static void removeCurrentUser(){threadLocal.remove();} }// 将用户信息存储 Slf4j Component(AuthInterceptor) public class AuthInterceptor implements HandlerInterceptor {Overridepublic boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handler) throws Exception {String url req.getRequestURL().toString();log.info(处理请求....{}, url);// TODO 前期不需要校验if(url ! null){// 登陆接口不需要校验return true;}String token req.getHeader(token);try {if(token ! null){Claims data JwtUtils.parseToken(token);UserContext.setCurrentUser((UserContextDTO) data); //将登陆用户存储起来return true;}else {throw new UserNotLoginException(token is not exists or expire);}} catch (Exception e){Result error Result.error(e.getMessage());res.addHeader(Content-Type, application/json);// 转位jsonres.getWriter().write(JSONObject.toJSONString(error));return false;}}; }//在后续service层可直接使用emp.setUpdateUser(UserContext.getCurrentUser().getUserId());公共字段自动填充 自动填充time,user 像每个表的createTime createUser updateTime updateUser在每一次增加或者修改的时候都会赋值为了避免冗余方便后期维护可以使用切面AOP精准拦截对应的方法然后加上对应的操作这样原本的create update方法就不用写setCreateTime, setUpdateTime这些了。 自定义注解 package com.sky.demo.annotaion;import com.sky.demo.constant.SqlActionType;import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;Retention(RetentionPolicy.RUNTIME) Target(ElementType.METHOD) public interface AutoFill {SqlActionType value(); }package com.sky.demo.constant;public enum SqlActionType {Update,Insert } 在需要用到的mapper上添注解 自定义切面类 package com.sky.demo.ascept;import com.sky.demo.constant.AutoFillConstant; import com.sky.demo.constant.SqlActionType; import com.sky.demo.utils.DateTimeFormat; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.stereotype.Component; import com.sky.demo.annotaion.AutoFill;import java.lang.reflect.Method;/*** aop用于给数据库创建 插入 自动注入 时间用户*/ Aspect Component Slf4j public class AutoFillAspect {/*** 切入点*/Pointcut(execution(* com.sky.demo.mapper.*.*(..)) annotation(com.sky.demo.annotaion.AutoFill))public void autoFillPointCut(){}/*** 前置通知*/Before(autoFillPointCut())public void autoFill(JoinPoint joinPoint){log.info(开始进行公共字段填充);// 获取当前被拦截的方法上的数据库操作类型MethodSignature signature (MethodSignature) joinPoint.getSignature();// 获取拦截mapper的注解AutoFill autoFill signature.getMethod().getAnnotation(AutoFill.class);// 获取注解的valueSqlActionType sqlActionType autoFill.value();// 获取到当前被拦截方法的参数-实体对象(categoryMapper.update(data))中的data修改其参数可以反馈到sql语句中Object[] args joinPoint.getArgs();if(args null || args.length 0){return;}Object entity args[0];// 准备赋值的数据String currentTime DateTimeFormat.getCurrentTime();if(sqlActionType SqlActionType.Insert){try {Method setCreateUser entity.getClass().getDeclaredMethod(AutoFillConstant.setCreateUser, Integer.class);Method setCreateTime entity.getClass().getDeclaredMethod(AutoFillConstant.setCreateTime, String.class);Method setUpdateUser entity.getClass().getDeclaredMethod(AutoFillConstant.setUpdateUser, Integer.class);Method setUpdateTime entity.getClass().getDeclaredMethod(AutoFillConstant.setUpdateTime, String.class);// 通过反射进行赋值setCreateUser.invoke(entity, 0);setCreateTime.invoke(entity, currentTime);setUpdateUser.invoke(entity, 0);setUpdateTime.invoke(entity, currentTime);}catch (Exception e){e.printStackTrace();}}else if(sqlActionType SqlActionType.Update) {try {Method setUpdateUser entity.getClass().getDeclaredMethod(AutoFillConstant.setUpdateUser, Integer.class);Method setUpdateTime entity.getClass().getDeclaredMethod(AutoFillConstant.setUpdateTime, String.class);setUpdateUser.invoke(entity, 0);setUpdateTime.invoke(entity, currentTime);}catch (Exception e){e.printStackTrace();}}// 根据不同的操作类型为对应的属性赋值} } 通过反射拿到每个实例对象(约定每个方法的第一个参数为实例对象)的setCreateUser等方法然后注入数据这样就完成对公共字段的自动填充。 自动处理page,pageSize 基础此思路继续开发一个拦截分页查询方法的切面类使其自动实现对page,pageSize等处理。 定义自定义注解 package com.sky.demo.annotaion;import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;Retention(RetentionPolicy.RUNTIME) Target(ElementType.METHOD) public interface AutoPage { } 在需要用到的地方使用注解 实现切面类 package com.sky.demo.ascept;import com.sky.demo.annotaion.AutoFill; import com.sky.demo.constant.AutoFillConstant; import com.sky.demo.constant.SqlActionType; import com.sky.demo.dto.PageDTO; import com.sky.demo.utils.DateTimeFormat; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.stereotype.Component;import java.lang.reflect.Method;Aspect Component Slf4j public class AutoPageAspect {/*** 切入点*/Pointcut(execution(* com.sky.demo.mapper.*.*(..)) annotation(com.sky.demo.annotaion.AutoPage))public void autoFillPointCut() {}/*** 前置通知*/Before(autoFillPointCut())public void autoPage(JoinPoint joinPoint) {log.info(分页查询开始进行公共字段填充);Object[] args joinPoint.getArgs();if (args null || args.length 0) {return;}PageDTO entity (PageDTO)args[0];try {Method setPage entity.getClass().getDeclaredMethod(AutoFillConstant.setPage, Integer.class);Method setPageSize entity.getClass().getDeclaredMethod(AutoFillConstant.setPageSize, Integer.class);Integer page entity.getPage() ! null ? (entity.getPage() 0 ? 1 : entity.getPage()) : 1;Integer pageSize entity.getPageSize() ! null ? entity.getPageSize() : 20;Integer start (page - 1) * pageSize;Integer end page * pageSize;// 通过反射进行赋值setPage.invoke(entity, start);setPageSize.invoke(entity, end);} catch (Exception e) {e.printStackTrace();}} } 如上通过强制转换将实例对象转为PageDTO约定每个分页的DTO都得继承该类然后通过反射注入即可。 这样就能自动将page,pageSize转为sql中limit正确的参数。
http://www.zqtcl.cn/news/739337/

相关文章:

  • 手机版免费申请微网站wordpress 跳转链接
  • 网站建设与管理好吗广州白云最新消息
  • 织梦动漫网站模版wordpress 页面文章列表
  • 东莞做网站沃德长沙市网站开发
  • 哪些网站做的最好厦门网站建设网站
  • 网站安全事件应急处置机制建设类似百度的网站
  • 内蒙古知名网站建设网站测速工具
  • 怎样建立网站赚钱怎么登录住建局官网
  • 建站自学网页转向功能网站
  • 网站都有什么费用做酒店网站有哪些目录
  • 本地郑州网站建设东莞网站优化中易
  • 动态域名可以建网站德州公司做网站
  • 深圳建设银行官方网站wordpress 添加qq
  • 甘肃第九建设集团公司网站网站对企业的好处
  • 论坛网站建设规划书公司网站建设与设计制作
  • 做棋牌游戏网站犯法吗如何进行搜索引擎的优化
  • 常见的网站首页布局有哪几种陈光锋网站运营推广新动向
  • 手机网站活动策划方案开一个设计公司
  • 宝塔建设网站教程visual studio 2010 网站开发教程
  • 做网站购买服务器做谷歌网站使用什么统计代码吗
  • 网站系统与网站源码的关系emlog轻松转wordpress
  • 网站的简介怎么在后台炒做吉林省住房城乡建设厅网站首页
  • 泉州易尔通网站建设国际酒店网站建设不好
  • 网页下载网站福田企业网站推广公司
  • 北京网站建设开发公司哪家好网站添加在线留言
  • 新建的网站怎么做seo优化平面广告创意设计
  • yy陪玩网站怎么做软件项目管理计划
  • 西安建网站价格低百度推广区域代理
  • 中英网站模板 照明公司注册在自贸区的利弊
  • 全球十大网站排名wordpress标题连接符