医疗管理系统-检查项管理 2

简介: 医疗管理系统-检查项管理

4. 检查项分页

本项目所有分页功能都是基于ajax的异步请求来完成的,请求参数和后台响应数据格式都使用json数据

格式。

请求参数包括页码、每页显示记录数、查询条件。

请求参数的json格式为:{currentPage:1,pageSize:10,queryString:''oldlu''}

后台响应数据包括总记录数、当前页需要展示的数据集合。

响应数据的json格式为:{total:1000,rows:[]}(其他数据都可以通过currentPage,pageSize计算得到.如下图:

image.png

4.1 完善页面

4.1.1 定义分页相关模型数据

pagination: {//分页相关模型数据
currentPage: 1,//当前页码
pageSize:10,//每页显示的记录数
total:0,//总记录数
queryString:null//查询条件
},
dataList: [],//当前页要展示的分页列表数据
1234567

4.1.2 定义分页方法

在页面中提供了findPage方法用于分页查询,为了能够在checkitem.html页面加载后直接可以展示分页数据,可以在VUE提供的钩子函数created中调用findPage方法

//钩子函数,VUE对象初始化完成后自动执行
created() {
  this.findPage();
}
1234
//分页查询
findPage() {
//分页参数
var param = {
  currentPage:this.pagination.currentPage,//页码
  pageSize:this.pagination.pageSize,//每页显示的记录数
  queryString:this.pagination.queryString//查询条件
};
//请求后台
axios.post("/checkitem/findPage.do",param).then((response)=> {
    //为模型数据赋值,基于VUE的双向绑定展示到页面
    this.dataList = response.data.rows;
    this.pagination.total = response.data.total;
  });
}

注意:个人出现了报错,使用then()时使用ES5语法出现TypeError: Cannot set property 'total' of undefined at错误,改成ES6语法解决.

4.1.3 完善分页方法执行时机

除了在created钩子函数中调用findPage方法查询分页数据之外,当用户点击查询按钮或者点击分页条中的页码时也需要调用findPage方法重新发起查询请求。

为查询按钮绑定单击事件,调用findPage方法

<el-button @click="findPage()" class="dalfBut">查询</el-button>
1

分页条组件绑定current-change事件,此事件是分页条组件自己定义的事件,当页码改变时触发,对应的处理函数为handleCurrentChange

<el-pagination
    class="pagiantion"
    @current-change="handleCurrentChange"
    :current-page="pagination.currentPage"
    :page-size="pagination.pageSize"
    layout="total, prev, pager, next, jumper"
    :total="pagination.total">
</el-pagination>

定义handleCurrentChange方法

//切换页码
handleCurrentChange(currentPage) {
  //currentPage为切换后的页码
  this.pagination.currentPage = currentPage;
  this.findPage();
}
123456

4.2 后台代码

4.2.1 Controller

在CheckItemController中增加分页查询方法

//分页查询
@RequestMapping("/findPage")
public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
  //调用Service方法
  PageResult pageResult = checkItemService.pageQuery(queryPageBean);
  return pageResult;
}

4.2.2 服务接口

在CheckItemService服务接口中扩展分页查询方法

public PageResult pageQuery(QueryPageBean queryPageBean);
1

4.2.3 服务实现类

在CheckItemServiceImpl服务实现类中实现分页查询方法,基于Mybatis分页助手插件实现分页

public PageResult pageQuery(QueryPageBean queryPageBean) {
    //获取数据
    Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        //分页查询,基于mybatis框架提供的分页助手
        //基于线程绑定
        PageHelper.startPage(currentPage, pageSize);
        //调用Service方法
        Page<CheckItem> page = checkItemDao.selectByCondition(queryString);
        //通过Page对象获取
        long total = page.getTotal();
        List<CheckItem> rows = page.getResult();
        //封装返回值
        return new PageResult(total, rows);
}

4.2.4 Dao接口

在CheckItemDao接口中扩展分页查询方法

public Page<CheckItem> selectByCondition(String queryString);
1

注意:只有使用MyBatis的分页助手时,才可以使用Page作为返回对象(可以通过Page对象获取分页的相关信息)

4.2.5 Mapper映射文件

在CheckItemDao.xml文件中增加SQL定义

<select id="selectByCondition" parameterType="string" resultType="com.itheiheihei.pojo.CheckItem">
  select * from t_checkitem
  <if test="value != null and value.length > 0">
    where code = #{value} or name = #{value}
  </if>
</select>

5. 删除检查项

5.1 完善页面

为了防止用户误操作,点击删除按钮时需要弹出确认删除的提示,用户点击取消则不做任何操作,用户点击确定按钮再提交删除请求。

5.1.1 绑定单击事件

需要为删除按钮绑定单击事件,并且将当前行数据作为参数传递给处理函数

<el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</elbutton>
  • <template slot-scope="scope">:模板
  • slot-scope="scope"作用域插槽
  • scope.row:作用是获取当前数据条的对象
// 删除
handleDelete(row) {
  alert(row.id);
}
  • row.id获取数据条对象的id

5.1.2 弹出确认操作提示

用户点击删除按钮会执行handleDelete方法,此处需要完善handleDelete方法,弹出确认提示信息。ElementUI提供了$confirm方法实现确认提示信息弹框效果

// 删除
handleDelete(row) {
  //alert(row.id);
  this.$confirm("确认删除当前选中记录吗?","提示",{type:'warning'}).then(()=>{
  //点击确定按钮时只需此处代码
  alert('用户点击的是确定按钮');
  });
}

5.1.3 发送请求

如果用户点击确定按钮就需要发送ajax请求,并且将当前检查项的id作为参数提交到后台进行删除操作

// 删除
handleDelete(row) {
//alert(row.id);
this.$confirm("确认删除吗?","提示",{type:'warning'}).then(()=>{
//点击确定按钮时只需此处代码
//alert('用户点击的是确定按钮');
axios.get("/checkitem/delete.do?id=" + row.id).then((res)=> {
if(!res.data.flag){
//删除失败
this.$message.error(res.data.message);
}else{
//删除成功
this.$message({
message: res.data.message,
type: 'success'
});
//调用分页,获取最新分页数据
this.findPage();
}
});
});
}

5.2 后台代码

5.2.1 Controller

在CheckItemController中增加删除方法

//删除
@RequestMapping("/delete")
  public Result delete(Integer id){
  try {
    checkItemService.delete(id);
  }catch (RuntimeException e){
    return new Result(false,e.getMessage());
  }catch (Exception e){
    return new Result(false, MessageConstant.DELETE_CHECKITEM_FAIL);
  }
return new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS);
}

5.2.2 服务接口

在CheckItemService服务接口中扩展删除方法

public void delete(Integer id);
1

5.2.3 服务实现类

注意:不能直接删除,需要判断当前检查项是否和检查组关联,如果已经和检查组进行了关联则不允许删除

//删除
public void delete(Integer id) throws RuntimeException{
  //查询当前检查项是否和检查组关联
  long count = checkItemDao.findCountByCheckItemId(id);
  if(count > 0){
    //当前检查项被引用,不能删除
    throw new RuntimeException("当前检查项被引用,不能删除");
  }
  checkItemDao.deleteById(id);
}

5.2.4 Dao接口

在CheckItemDao接口中扩展方法findCountByCheckItemId和deleteById

public void deleteById(Integer id);
public long findCountByCheckItemId(Integer checkItemId);
12

5.2.5 Mapper映射文件

在CheckItemDao.xml中扩展SQL语句

<!--删除-->
<delete id="deleteById" parameterType="int">
  delete from t_checkitem where id = #{id}
</delete>
<!--根据检查项id查询中间关系表-->
<select id="findCountByCheckItemId" resultType="long" parameterType="int">
  select count(*) from t_checkgroup_checkitem where checkitem_id = #{checkitem_id}
</select>

6. 编辑检查项

6.1 完善页面

用户点击编辑按钮时,需要弹出编辑窗口并且将当前记录的数据进行回显,用户修改完成后点击确定按钮将修改后的数据提交到后台进行数据库操作。

6.1.1 绑定单击事件

需要为编辑按钮绑定单击事件,并且将当前行数据作为参数传递给处理函数

<el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</elbutton>
1
handleUpdate(row) {
  alert(row);
}

6.1.2 弹出编辑窗口回显数据

当前页面中的编辑窗口已经提供好了,默认处于隐藏状态。在handleUpdate方法中需要将编辑窗口展示出来,并且需要发送ajax请求查询当前检查项数据用于回显

// 弹出编辑窗口
handleUpdate(row) {
//发送请求获取检查项信息
axios.get("/checkitem/findById.do?id=" + row.id).then((res)=>{
  if(res.data.flag){
    //设置编辑窗口属性,dialogFormVisible4Edit为true表示显示
    this.dialogFormVisible4Edit = true;
    //为模型数据设置值,基于VUE双向数据绑定回显到页面
    this.formData = res.data.data;
  }else{
    this.$message.error("获取数据失败,请刷新当前页面");
  }
});
}

6.1.3 发送请求

在编辑窗口中修改完成后,点击确定按钮需要提交请求,所以需要为确定按钮绑定事件并提供处理函数

<el-button type="primary" @click="handleEdit()">确定</el-button>
1
//编辑
handleEdit() {
//表单校验
this.$refs['dataEditForm'].validate((valid)=>{
  if(valid){
    //表单校验通过,发送请求
    axios.post("/checkitem/edit.do",this.formData).then((response)=> {
      //隐藏编辑窗口
      this.dialogFormVisible4Edit = false;
      if(response.data.flag){
        //编辑成功,弹出成功提示信息
        this.$message({
          message: response.data.message,
          type: 'success'
      });
      }else{
        //编辑失败,弹出错误提示信息
        this.$message.error(response.data.message);
      }
    }).finally(()=> {
      //重新发送请求查询分页数据
      this.findPage();
    });
  }else{
    //表单校验失败
    this.$message.error("表单数据校验失败");
    return false;
  }
});
}

6.2 后台代码

6.2.1 Controller

在CheckItemController中增加编辑方法

//编辑
@RequestMapping("/edit")
public Result edit(@RequestBody CheckItem checkItem){
  try {
    checkItemService.edit(checkItem);
  }catch (Exception e){
    return new Result(false,MessageConstant.EDIT_CHECKITEM_FAIL);
  }
  return new Result(true,MessageConstant.EDIT_CHECKITEM_SUCCESS);
}
@RequestMapping("/findById")
public Result findById(Integer id){
  try{
    CheckItem checkItem = checkItemService.findById(id);
    return new Result(true,MessageConstant.QUERY_CHECKITEM_SUCCESS,checkItem);
  }catch (Exception e){
    e.printStackTrace();
    //服务调用失败
    return new Result(false, MessageConstant.QUERY_CHECKITEM_FAIL);
  }
}

6.2.2 服务接口

在CheckItemService服务接口中扩展编辑方法

public void edit(CheckItem checkItem);
public CheckItem findById(Integer id);

6.2.3 服务实现类

在CheckItemServiceImpl实现类中实现编辑方法

//编辑
public void edit(CheckItem checkItem) {
  checkItemDao.edit(checkItem);
}
public CheckItem findById(Integer id) {
  return checkItemDao.findById(id);
}

6.2.4 Dao接口

在CheckItemDao接口中扩展edit方法

public void edit(CheckItem checkItem);
public CheckItem findById(Integer id);

6.2.5 Mapper映射文件

在CheckItemDao.xml中扩展SQL语句

<!--编辑-->
<update id="edit" parameterType="com.itheiheihei.pojo.CheckItem">
update t_checkitem
  <set>
  <if test="name != null">
    name = #{name},
  </if>
  <if test="sex != null">
    sex = #{sex},
  </if>
  <if test="code != null">
    code = #{code},
  </if>
  <if test="age != null">
    age = #{age},
  </if>
  <if test="price != null">
    price = #{price},
  </if>
  <if test="type != null">
    type = #{type},
  </if>
  <if test="attention != null">
    attention = #{attention},
  </if>
  <if test="remark != null">
    remark = #{remark},
  </if>
  </set>
    where id = #{id}
</update>
<select id="findById" parameterType="int" resultType="com.itheiheihei.pojo.CheckItem">
  select * from t_checkitem where id = #{id}
</select>
目录
相关文章
|
前端开发 JavaScript Java
【实操】SpringBoot监听Iphone15邮件提醒,Selenium+Python自动化抢购脚本
本文介绍了一个结合SpringBoot和Python的实用功能,旨在监控iPhone 15的库存状态并通过邮件提醒用户。系统采用SpringBoot监听苹果官网API,解析JSON数据判断是否有货,并展示最近的库存记录。此外,还能自动触发Selenium+Python脚本实现自动化购买。文中详细介绍了技术栈、接口分析、邮件配置及自动化脚本的设置方法。该项目不仅适用于熟悉后端开发的人员,也适合回顾Layui和Jquery等前端技术。
320 0
【实操】SpringBoot监听Iphone15邮件提醒,Selenium+Python自动化抢购脚本
|
9月前
|
机器学习/深度学习 编解码 自然语言处理
王炸组合,阶跃星辰SOTA模型Step-Video和Step-Audio模型开源
王炸组合,阶跃星辰SOTA模型Step-Video和Step-Audio模型开源
314 0
|
11月前
|
机器学习/深度学习 人工智能 自然语言处理
GLM-Edge:智谱开源的端侧大语言和多模态系列模型
GLM-Edge是智谱开源的一系列端侧部署优化的大语言对话模型和多模态理解模型,旨在实现模型性能、实机推理效果和落地便利性之间的最佳平衡。该系列模型支持在手机、车机和PC等端侧设备上高效运行,适用于智能助手、聊天机器人、图像标注等多种应用场景。
391 7
GLM-Edge:智谱开源的端侧大语言和多模态系列模型
|
11月前
|
数据可视化 Python
使用Python进行数据可视化的初学者指南
在数据的海洋里,我们如何能够不迷失方向?通过数据可视化的力量,我们可以将复杂的数据集转化为易于理解的图形和图表。本文旨在为初学者提供一份简明的入门手册,介绍如何使用Python中的Matplotlib库来揭示数据背后的故事。我们将从基础的图表开始,逐步深入到更高级的可视化技术,确保每个步骤都清晰易懂,让初学者也能轻松上手。让我们开始绘制属于你自己的数据图谱吧!
|
11月前
|
机器学习/深度学习 人工智能 编译器
【AI系统】死代码消除
死代码消除是一种编译器优化技术,旨在移除程序中不会被执行的代码,提升程序效率和资源利用。通过分析控制流图,识别并删除不可达操作和无用操作,减少不必要的计算。在传统编译器中,主要通过深度优先搜索和条件分支优化实现;而在AI编译器中,则通过对计算图的分析,删除无用或不可达的计算节点,优化模型性能。
350 3
|
前端开发 应用服务中间件 API
|
存储 监控 安全
深入解析Sysmon日志:增强网络安全与威胁应对的关键一环
在不断演进的网络安全领域中,保持对威胁的及时了解至关重要。Sysmon日志在这方面发挥了至关重要的作用,通过提供有价值的见解,使组织能够加强其安全姿态。Windows在企业环境中是主导的操作系统,因此深入了解Windows事件日志、它们的独特特性和局限性,并通过Sysmon进行增强,变得至关重要。
348 1
|
Java Spring
成功解决Initialization failed for ‘https://start.spring.io‘ Please check URL, network and proxy settings
这篇文章提供了解决Spring Initializr网站初始化失败问题的方法,包括检查URL、网络和代理设置。
成功解决Initialization failed for ‘https://start.spring.io‘ Please check URL, network and proxy settings
|
存储 安全 Java
Java编程中的对象序列化与反序列化
【10月更文挑战第3天】在Java编程的世界里,对象序列化与反序列化是实现数据持久化和网络传输的关键技术。本文将深入探讨Java序列化的原理、应用场景以及如何通过代码示例实现对象的序列化与反序列化过程。从基础概念到实践操作,我们将一步步揭示这一技术的魅力所在。
|
机器学习/深度学习 边缘计算 人工智能
深度学习的未来趋势与挑战
本文探讨了深度学习的最新进展和未来发展方向,并分析了当前面临的主要挑战。通过具体案例和研究数据,揭示了深度学习在多个领域的应用前景及其潜在问题。