searchStudentName 模块设计

函数使用:

  • HttpServletRequestgetSession() 方法:获取当前 HTTP 请求的 Session 对象。
  • setAttribute() 方法:将数据存入 Session 对象中。

实现逻辑:

  1. 从前端传入查询的学生名字,并将其存入 student 对象中。
  2. 使用 HttpServletRequestgetSession() 方法获取当前 HTTP 请求的 Session 对象。
  3. 使用 setAttribute() 方法将查询的学生名字存入 Session 对象中,键名为 findStudentByName

selectStudent 模块设计

函数使用:

  • HttpServletRequestgetSession() 方法:获取当前 HTTP 请求的 Session 对象。
  • getAttribute() 方法:从 Session 对象中获取数据。
  • PageHelper 插件中的 startPage() 方法:设置分页参数。
  • PageInfo 类的构造函数:封装查询结果。

实现逻辑:

  1. 使用 HttpServletRequestgetSession() 方法获取当前 HTTP 请求的 Session 对象。
  2. 使用 getAttribute() 方法从 Session 对象中获取 findStudentByName 属性,即查询的学生名字。
  3. 使用 PageHelper 插件的 startPage() 方法设置分页参数,包括当前页码和每页显示条数。
  4. 调用 studentServicefindByName() 方法进行查询,并根据分页参数获取当前页的学生信息。
  5. 使用 PageInfo 类封装查询结果,将查询结果、总页数、总条数等信息封装到 PageInfo 对象中。
  6. PageInfo 对象存入 ModelAndView 对象中,并将 selectStudent 页面作为视图名。
  7. 返回 ModelAndView 对象,在前端页面展示查询结果。
Java Web 应用中使用 Session 保存学生姓名并进行分页查询

原文地址: https://www.cveoy.top/t/topic/oMvP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录