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

苏州高端网站建设机构网站制作公司咨询工作内容

苏州高端网站建设机构,网站制作公司咨询工作内容,苏州代理记账,竹子建站官网目录 一、新增员工 二、查询分页数据 三、启用、禁用员工账户、编辑员工信息 一、新增员工 点击左上角新增员工 页面如下: 我们随便填数据 ,点击保存,请求的地址如下 返回前端可以看到请求方式为Post 在employeeController中编写对应的代…

目录

一、新增员工

二、查询分页数据

三、启用、禁用员工账户、编辑员工信息


一、新增员工

点击左上角新增员工

 页面如下:

我们随便填数据 ,点击保存,请求的地址如下

返回前端可以看到请求方式为Post

 在employeeController中编写对应的代码

    /** 新增员工*/@PostMappingpublic R<String> 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 R<String> 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 R<Page> page(int page, int pageSize, String name) {log.info("page:{}, pageSize:{}, name:{}", page, pageSize, name);// 构造分页器Page pageInfo = new Page(page, pageSize);// 构造条件构造器LambdaQueryWrapper<Employee> 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 R<Employee> 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 R<String> 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.yayakq.cn/news/183088/

相关文章:

  • 舟山公司网站建设php 网站进入后台
  • 徐州seo网站推广ssr和wordpress
  • 安宁网站建设做网站要多少
  • 非物质文化遗产网站怎么做2017做那个网站能致富
  • 下载类网站 建设方案wordpress繁体中文
  • 炫客网站建设开源电商网站建设价格
  • 深圳网络营销网站电子商务平台网站模板
  • 浙江省门户网站怎么做域名网站
  • 鞋网站建设永久免费域名注册网站
  • 做网站的收获北京定制网站价格
  • 现在 做网站 技术路线永清建设局网站
  • 网页制作工具可以发布网站吗柳州城市的城乡建设管理局网站
  • 河北中冶润丰建设股份有限公司网站医生在线咨询
  • 网站帮助中心设计花都网站推广
  • htm商城网站开发教务管理系统登录入口官网
  • 建行网站会员是什么河南建筑公司实力排名
  • 兰州建设网站广州做网站优化公司报价
  • 烟台企业网站建设外贸自建站多少钱一个
  • 手机界面设计网站外贸流程中的单证有哪些
  • 上海的室内设计公司站长工具seo综合查询腾讯
  • 我想网站建设樊城网站建设
  • 龙华o2o网站建设平面设计师资格证怎么考
  • 深圳网站建设 设计卓越中国施工企业管理协会
  • 扁平化蓝色网站哪些网站图片做海报好
  • 苏州实力做网站公司有哪些营销成功案例网站
  • 建设网站对企业有什么好处两学一做网站飘窗
  • 网站制作建设公司推荐网站功能设计的内容
  • 公司怎么建立自己网站网站可做2个首页吗
  • 济南哪里有做网站的做外贸怎样打开国外网站
  • 网站系统评测要怎么做呢网站开发入门培训机构