mvc結構 連接數據庫 類色圖書館管理系統 但不要那麼復雜的 我只要裡面的分類查詢顯示 這一塊 簡單的就行 給例子 謝謝 大神了哈!!!!
list頁面 相當於V
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
servlet 相當於C
public class listStudent extends HttpServlet {
private static final long serialVersionUID = -6441193787541923748L;
private StudentService studentService = new StudentServiceImpl();
private BJService bJService = new BJServiceImpl();
/**
* @Description: 處理doGet方法
* @param req
* @param resp
* @throws ServletException
* @throws IOException
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// 交給doPost處理
doPost(req, resp);
}
/**
* @Description: 處理doPost方法
* @param req
* @param resp
* @throws ServletException
* @throws IOException
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
final int pageSize = 3;
int pageNow = 1;
int pageCount = 1;
// 查詢條件封裝成map集合
Map<String, String> paramsMap = new HashMap<String, String>();
if (StringUtils.isNotBlank(req.getParameter("xh"))) {
paramsMap.put("xh", req.getParameter("xh"));
}
if (StringUtils.isNotBlank(req.getParameter("name"))) {
paramsMap.put("name", req.getParameter("name"));
}
if (StringUtils.isNotBlank(req.getParameter("b_no"))) {
paramsMap.put("b_no", req.getParameter("b_no"));
}
// 設置當前頁
if (StringUtils.isNotBlank(req.getParameter("pageNow"))) {
pageNow = Integer.parseInt(req.getParameter("pageNow"));
}
List<Student> listStudent = null;
List<BJ> listBJ=null;
try {
// 根據pageSize,pageNow和parmasMap查詢所有符合條件的學生
listStudent = studentService.listStudent(pageSize, pageNow,
paramsMap);
listBJ=bJService.listAllBJ();
// 獲取頁數
pageCount = studentService.getCount(pageSize, paramsMap);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 學生數據集合
req.setAttribute("list", listStudent);
//班級數據集合
req.setAttribute("listBJ", listBJ);
// 總頁數
req.setAttribute("pageCount", pageCount);
// 當前頁
req.setAttribute("pageNow", pageNow);
req.getRequestDispatcher("/listStudent.jsp").forward(req, resp);
}
javaBean 相當於M
public class Student {
private int xh;// 學號
private String name;// 姓名
private int sex;// 性別,0表示男,1表示女
private String birthday;// 生日
private String favorite;// 愛好
private String b_name;// 班級名稱
private int b_no;//班級號
public int getXh() {
return xh;
}
public void setXh(int xh) {
this.xh = xh;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getFavorite() {
return favorite;
}
public void setFavorite(String favorite) {
this.favorite = favorite;
}
public String getB_name() {
return b_name;
}
public void setB_name(String b_name) {
this.b_name = b_name;
}
public int getB_no() {
return b_no;
}
public void setB_no(int b_no) {
this.b_no = b_no;
}
}