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

网站的建设建议广西住建领域培训考试系统

网站的建设建议,广西住建领域培训考试系统,郑州市政务公开,园林设计公司网站目录 一、新增员工 二、查询分页数据 三、启用、禁用员工账户、编辑员工信息 一、新增员工 点击左上角新增员工 页面如下#xff1a; 我们随便填数据 #xff0c;点击保存#xff0c;请求的地址如下 返回前端可以看到请求方式为Post 在employeeController中编写对应的代…目录 一、新增员工 二、查询分页数据 三、启用、禁用员工账户、编辑员工信息 一、新增员工 点击左上角新增员工 页面如下 我们随便填数据 点击保存请求的地址如下 返回前端可以看到请求方式为Post 在employeeController中编写对应的代码 /** 新增员工*/PostMappingpublic RString add(HttpServletRequest request, RequestBody Employee employee) {employee.setPassword(DigestUtils.md5DigestAsHex(123456.getBytes()));employee.setCreateTime(LocalDateTime.now());employee.setUpdateTime(LocalDateTime.now());Long empId (Long) request.getSession().getAttribute(employee);employee.setCreateUser(empId);employee.setUpdateUser(empId);employeeService.save(employee);return R.success(新增员工成功);} 这里我们可以发现对于createTime、updateTime、createUser、updateUser这几个字段其实是公共字段即几个表里都会有那么我们可以使用mybatis-plus进行公共字段填充就不需要每次写4行设置属性的代码了 Employee中公共字段我们需要添加TableField属性并且设置什么时候填充 Data public class Employee implements Serializable {private static final long serialVersionUID 1L;private Long id;private String username;private String name;private String password;private String phone;private String sex;private String idNumber;private Integer status;TableField(fill FieldFill.INSERT) // 插入时填充字段private LocalDateTime createTime;TableField(fill FieldFill.INSERT_UPDATE) // 插入和更新时填充字段private LocalDateTime updateTime;TableField(fill FieldFill.INSERT) // 插入时填充字段private Long createUser;TableField(fill FieldFill.INSERT_UPDATE) // 插入和更新时填充字段private Long updateUser;} 接下来编写一个MyMetaObjectHandler继承mybatis-plus中的MetaObjectHandler Slf4j Component public class MyMetaObjectHandler implements MetaObjectHandler {/** 插入字段自动填充*/Overridepublic void insertFill(MetaObject metaObject) {log.info(公共字段填充【insert】);log.info(metaObject.toString());metaObject.setValue(createTime, LocalDateTime.now());metaObject.setValue(updateTime, LocalDateTime.now());metaObject.setValue(createUser, BaseContext.getCurrentId());metaObject.setValue(updateUser, BaseContext.getCurrentId());}/** 更新字段自动填充*/Overridepublic void updateFill(MetaObject metaObject) {log.info(公共字段填充【update】);log.info(metaObject.toString());metaObject.setValue(updateTime, LocalDateTime.now());metaObject.setValue(updateUser, BaseContext.getCurrentId());} } 则添加员工的代码可简化为 /** 新增员工*/PostMappingpublic RString add(HttpServletRequest request, RequestBody Employee employee) {employee.setPassword(DigestUtils.md5DigestAsHex(123456.getBytes()));/** 使用MP公共字段自动填充*/employeeService.save(employee);return R.success(新增员工成功);} 二、查询分页数据 分页数据需要使用到Mybatis-plus的分页构造器 Configuration public class MybatisPlusConfig {Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor new MybatisPlusInterceptor();interceptor.addInnerInterceptor(new PaginationInnerInterceptor());return interceptor;} }页面发送的请求如下 当添加了搜索字段后 前端Element-UI需要分页数据进行展示我们返回分页信息 /** 返回分页查询的数据*/GetMapping(/page)public RPage page(int page, int pageSize, String name) {log.info(page:{}, pageSize:{}, name:{}, page, pageSize, name);// 构造分页器Page pageInfo new Page(page, pageSize);// 构造条件构造器LambdaQueryWrapperEmployee wrapper new LambdaQueryWrapper();// 构造过滤条件wrapper.like(!StringUtils.isEmpty(name), Employee::getName, name);// 构造排序条件wrapper.orderByDesc(Employee::getUpdateTime);// 查询employeeService.page(pageInfo, wrapper);return R.success(pageInfo);} 三、启用、禁用员工账户、编辑员工信息 对员工进行禁用后员工就无法登录管理后台了禁用实际上就是对应修改employee表中的status字段即更新。那么本质上还是更新数据可以和编辑功能一起写 编辑页面如下 很显然这里的数据是通过查询数据库进行回显的当我们点击编辑页面后会发送以下GET请求 我们需要在Controller中编写对应的方法处理请求由于类上已经加了RequestMapping(/employee)这里方法上直接写“/{id}”即可 /** 编辑员工的请求此时根据id返回一个employee进行回显*/GetMapping(/{id})public REmployee getById(PathVariable Long id) {log.info(根据id查询员工信息);Employee employee employeeService.getById(id);if(employee ! null) {return R.success(employee);} else return R.error(没有查询到员工信息);} 回显完成后我们还需要编写保存方法 /** 根据员工id修改信息通用性 编辑和禁用皆可使用*/PutMappingpublic RString update(HttpServletRequest request,RequestBody Employee employee) {log.info(修改的用户id为{}, employee.getId());Long empId (Long)request.getSession().getAttribute(employee);// Mp 公共字段自动填充 // employee.setUpdateTime(LocalDateTime.now()); // employee.setUpdateUser(empId);employeeService.updateById(employee);return R.success(更新员工成功);}
http://www.hkea.cn/news/14554111/

相关文章:

  • 网站建设静态部分实训总结福州建网站 做网页
  • 无锡网站关键词推广上海网络营销的企业
  • 知乎问答网站开发教程北京营销型网站建设培训班
  • 有哪些做问卷调查的网站用php做网站的新闻
  • 崇明集团网站建设wordpress带会员vip主题
  • 做网站需多少钱如何自己安装wordpress
  • 购物网站有哪些功能白云区建材网站建设推广
  • 做仿牌网站被封网站加一个会员登陆怎么做
  • 深圳网站建设托管wordpress title怎么设置
  • 青海建设兵团青岛战友网站域名备案要求
  • 南宁网站优化排名推广做网站1天转多钱
  • 盗网站后台源码总算把网站设计好了
  • 建站之星和凡科wordpress两个域名
  • 提升网站浏览量wordpress导出数据字典
  • 网站空间流量是什么wordpress修改联系我们页面
  • 重庆市工程建设招投标交易中心网站免费空间大的云盘
  • 电子商务网站建设各项费用预算是多少软文撰写公司
  • 如何规划企业网站wordpress全站cdn ssl
  • 公共资源中心网站建设河北辛集市网站建设
  • 算命网站搭建网络系统安全原则
  • 如何在百度提交自己的网站婚庆网站开发目的
  • 前端seo优化方案网站如何做谷歌优化
  • 肥城网站建设电话自己怎样免费建网站
  • 手工网站怎样做三角包如何在360网页上做公司网站
  • 创意个人网站设计免费销售网站模板下载
  • 芜湖市建设投资有限公司网站宣传渠道有哪些
  • 订单网站模块中国家装公司十大排名
  • 网站建设创业计划书模板范文手机如何做微商城网站设计
  • 更改网站的布局漳州网站开发找出博大科技
  • app开发 网站建设唐山市住房城乡建设部网站主页