java从数据库中读取的数据怎样显示在jsp的网页当中

2024-11-16 16:40:43
推荐回答(1个)
回答1:

我用的SSM框架 这是java类

@Controller
@RequestMapping("/studentController")
public class StudentController {

@Autowired
private StudentServices studentServices;

public StudentServices getStudentServices() {
return studentServices;
}

public void setStudentServices(StudentServices studentServices) {
this.studentServices = studentServices;
}
@RequestMapping("showStudent")
public String showStudents(Model model,HttpServletRequest request){
String currentPage = request.getParameter("currentPage")==null?"0": request.getParameter("currentPage");
long studentCount = studentServices.getStudentCount();
int pageSum = (int) (studentCount%20 == 0?studentCount/20:studentCount/20+1);
if(Integer.parseInt(currentPage)>=0&&Integer.parseInt(currentPage) List students = studentServices.queryAll(Integer.parseInt(currentPage),20,pageSum);
model.addAttribute("students", students);
request.setAttribute("studentCount", studentCount);
request.setAttribute("currentPage", currentPage);
request.setAttribute("pageSum", pageSum);
return "showInfos/showStudent";
}else{
return "errorPage/showError";
}
}
}

这是JSP



新增
































学生编号 学生姓名 学生性别 学生年龄 学生地址 学生生日 删除学生 修改学生
${stu.stuid } ${stu.name } ${stu.sex } ${stu.age } ${stu.address } ${bir } 删除学生 修改学生


首页
上页
下页
末页
共<< >>页
当前第<<
>>






这是完成JSP展示数据库的数据,其他的类我就不写了。希望能帮到你