MVC分层架构及项目实战
现行的开发模式并不是一蹴而就的,是经过无数开发者经过不断实践和总结逐步演变而来,在本章内将详细讲解开发模式的演进过程及MVC开发模式以及项目实战
Model1和Model2
早期的Java Web开发,大都采用Model 1模型进行开发,Model 1模型主要以JSP为主,辅助以少量JavaBean处理数据库连接等功能即可。对于Model 1模型的Web应用,整个应用几乎全部由JSP页面组成,JSP页面接收处理客户端请求,对请求处理后直接做出响应。用少量的JavaBean来处理数据库连接、数据库访问等操作。下图显示了Model 1的程序流程。
Model 1模式的实现比较简单,适用于快速开发小规模项目。但从工程化的角度看,它的局限性非常明显:JSP页面身兼View(视图)和Controller(控制器)两种角色,将控制逻辑和表现逻辑混杂在一起,从而导致代码的重用性非常低,增加了应用的扩展和维护的难度。
早期有JSP技术开发出来的Web应用,这些Web应用都采用了Model 1架构。
Model 2已经是基于MVC架构的设计模式。在Model 2架构中,Servlet作为前端控制器,负责接收客户端发送的请求,在Servlet中只包含控制逻辑和简单的前端处理;然后,调用后端JavaBean来完成实际的逻辑处理;最后,转发到相应的JSP页面处理显示逻辑。其具体实现方式如图所示。
在Model 2下JSP不再承担控制器的责任,它仅仅是表现层角色,仅仅用于将结果呈现给用户,JSP页面的请求与Servlet(控制器)交互,而Servlet负责与后台的JavaBean通信。在Model 2模式下,模型(Model)由JavaBean充当,视图(View)由JSP页面充当,而控制器(Controller)则由Servlet充当。
由于引入了MVC模式,使Model 2具有组件化的特点,更适用于大规模应用的开发,但也增加了应用开发的复杂程度。原本需要一个简单的JSP页面就能实现的应用,在Model 2中被分解成多个协同工作的部分,需要花费更多的时间才能真正掌握其设计和实现过程。
MVC开发模式
MVC并不是Java语言所特有的设计思想,也并不是Web应用所特有的思想,它是所有面向对象程序设计语言都应该遵守的规范。MVC思想将一个应用分成三个基本部分:Model(模型)、View(视图)和Controller(控制器),这三个部分以最少的耦合协同工作,从而提高应用的可扩展性及可维护性。
在MVC开发模式中MVC含义分别如下:
Model:模型层,可以简单的理解为数据表对应的实例类
View:视图层,包括JSP页面和HTML静态页面
Controller:控制层,通常由Servlet来充当,用于接收视图层发送的数据以及向视图层发送数据。
三者的关系如下图:
项目实战
项目基础构建
接下来,通过单表的增删改查项目来学习MVC开发模式。
第一步:首先新建数据库并添加测试数据。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| CREATE DATABASE STUDENT_MANAGE; USE STUDENT_MANAGE;
CREATE TABLE STUDENT( STUDENT_ID INT(11) PRIMARY KEY AUTO_INCREMENT, STUDENT_NAME VARCHAR(30), STUDENT_AGE INT(3), STUDENT_GENDER CHAR(2) );
INSERT INTO STUDENT (STUDENT_NAME,STUDENT_AGE,STUDENT_GENDER) VALUES ("张三",18,'男'); INSERT INTO STUDENT (STUDENT_NAME,STUDENT_AGE,STUDENT_GENDER) VALUES ("李四",18,'女'); INSERT INTO STUDENT (STUDENT_NAME,STUDENT_AGE,STUDENT_GENDER) VALUES ("王五",18,'男'); CREATE TABLE USER( USER_ID INT PRIMARY KEY AUTO_INCREMENT, USERNAME VARCHAR(30), PASSWORD VARCHAR(32) ); INSERT INTO USER (USERNAME,PASSWORD) VALUES ('admin','21232f297a57a5a743894a0e4a801fc3');
|
第二步:新建项目并根据不同的功能进行分包,项目结构如下图:
下面对各个包进行说明:
●controller:控制器包,用于放置Servlet
●dao:该包用于放置编写sql语句操作数据的类
●entity:用于存放数据表对应的实体类
●service:用于存放服务类
●util:用于存放项目中使用的工具类
除此之外resource目录用于放置配置文件,webapp目录则是用于放置视图层也就是JSP的目录。
第三步:编写DBHelper类,用于操作数据库,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
| package cn.bytecollege.dao; import java.io.IOException; import java.lang.reflect.Field; import java.sql.*; import java.util.ArrayList; import java.util.List; import java.util.Properties;
public class DBHelper { private static String url = null; private static String driver = null; private static String username = null; private static String password = null; private Connection connection = null; private PreparedStatement ps = null; private ResultSet rs = null;
static{ Properties properties = new Properties(); try { properties.load(DBHelper.class.getClassLoader().getResourceAsStream("data.properties")); } catch (IOException e) { e.printStackTrace(); } url = properties.getProperty("url"); driver = properties.getProperty("driver"); username = properties.getProperty("username"); password = properties.getProperty("password"); }
public void getConnection() throws SQLException { if(connection==null||connection.isClosed()){ connection = DriverManager.getConnection(url,username,password); } }
public int executeUpdate(String sql,Object...objs) throws SQLException { getConnection(); ps = connection.prepareStatement(sql); setObject(objs); return ps.executeUpdate(); }
public <T> List<T> executeQuery(String sql,Class<T> clazz, Object...objs) throws SQLException { getConnection(); ps = connection.prepareStatement(sql); setObject(objs); rs = ps.executeQuery(); ResultSetMetaData resultSetMetaData = rs.getMetaData(); List<T> list = new ArrayList<>(); while (rs.next()){ T t = mapper(rs,clazz,resultSetMetaData); list.add(t); } return list; }
public double executeScale(String sql,Object...objs) throws SQLException { getConnection(); ps = connection.prepareStatement(sql); setObject(objs); rs = ps.executeQuery(); double result = 0; while(rs.next()){ result = rs.getDouble(1); } return result; }
private void setObject(Object[] objs) throws SQLException { if(objs!=null&&objs.length>0){ for (int i = 0;i<objs.length;i++){ ps.setObject((i+1),objs[i]); } } }
public void close(){ if(rs!=null){ rs = null; } if(ps!=null){ ps = null; } if(connection!=null){ connection = null; } }
public void begin() throws SQLException { getConnection(); connection.setAutoCommit(false); }
public void commit() throws SQLException { connection.commit(); }
public void rollback() throws SQLException { connection.rollback(); }
private <T> T mapper(ResultSet rs,Class<T> clazz,ResultSetMetaData resultSetMetaData){ try{ T t = clazz.newInstance(); int count = resultSetMetaData.getColumnCount(); for (int i=1;i<=count;i++){ String columnName = resultSetMetaData.getColumnName(i).toLowerCase(); String fieldName = toCamelName(columnName); Field field = null; try { field = clazz.getDeclaredField(fieldName); }catch (NoSuchFieldException e){ field = clazz.getField(fieldName); } field.setAccessible(true); Object o = rs.getObject(columnName); field.set(t,o); } return t; }catch (SQLException |NoSuchFieldException | InstantiationException |IllegalAccessException e) { throw new RuntimeException(); } }
private String toCamelName(String columnName){ String[] strs = columnName.split("_"); if(strs.length==0){ return columnName; } StringBuilder builder = new StringBuilder(strs[0]); for (int i = 1;i<strs.length;i++){ String temp = strs[i]; String name = temp.substring(0,1).toUpperCase()+temp.substring(1); builder.append(name); } return builder.toString(); }
}
|
StudentDao代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| package cn.bytecollege.dao;
import cn.bytecollege.entity.Student; import cn.bytecollege.util.Page;
import java.sql.SQLException; import java.util.List;
public class StudentDao { private DBHelper helper = null; public StudentDao() { helper = new DBHelper(); }
public Page<Student> findStudentByPage(int currentIndex, int pageSize) throws SQLException { String querySql = "SELECT STUDENT_ID,STUDENT_NAME,STUDENT_AGE,STUDENT_GENDER " + "FROM STUDENT LIMIT ?,?"; Page page = new Page(); String countSql = "SELECT COUNT(*) FROM STUDENT"; Object[] objs = {(currentIndex-1)*pageSize,pageSize}; List<Student> list = helper.executeQuery(querySql,Student.class,objs); int count = (int) helper.executeScale(countSql); page.setList(list); page.setCount(count); page.setPageSize(pageSize); page.setTotalPage(count); page.setCurrentIndex(currentIndex); page.setPageIndex(currentIndex); return page; }
public int deleteById(String id) throws SQLException { String sql = "DELETE FROM STUDENT WHERE STUDENT_ID = ?"; return helper.executeUpdate(sql,id); }
public Student findById(String id) throws SQLException{ String sql = "SELECT STUDENT_ID,STUDENT_NAME,STUDENT_AGE,STUDENT_GENDER FROM STUDENT WHERE STUDENT_ID = ?"; return helper.executeQuery(sql,Student.class,id).get(0); }
public int add(Student student) throws SQLException{ String sql = "INSERT INTO STUDENT (STUDENT_NAME,STUDENT_AGE,STUDENT_GENDER) VALUES (?,?,?)"; Object[] objects = {student.getStudentName(),student.getStudentAge(),student.getStudentGender()}; return helper.executeUpdate(sql,objects); }
public int update(Student student) throws SQLException{ String sql = "UPDATE STUDENT SET STUDENT_NAME = ?,STUDENT_AGE=?,STUDENT_GENDER=? WHERE STUDENT_ID = ?"; Object[] objects = {student.getStudentName(),student.getStudentAge(),student.getStudentGender(),student.getStudentId()}; return helper.executeUpdate(sql,objects); } }
|
StudentService代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| package cn.bytecollege.service;
import cn.bytecollege.dao.StudentDao; import cn.bytecollege.entity.Student; import cn.bytecollege.util.Page;
import java.sql.SQLException;
public class StudentService { private StudentDao studentDao;
public StudentService() { studentDao = new StudentDao(); }
public Page findStudentByPage(int currentIndex,int pageSize) throws SQLException { return studentDao.findStudentByPage(currentIndex, pageSize); } public int deleteById(String id) throws SQLException { return studentDao.deleteById(id); } public Student findById(String id) throws SQLException{ return studentDao.findById(id); } public int add(Student student) throws SQLException{ return studentDao.add(student); } public int update(Student student) throws SQLException{ return studentDao.update(student); } }
|
Student实体类代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| package cn.bytecollege.entity;
public class Student { private Integer studentId; private String studentName; private Integer studentAge; private String studentGender;
public Integer getStudentId() { return studentId; }
public void setStudentId(Integer studentId) { this.studentId = studentId; }
public String getStudentName() { return studentName; }
public void setStudentName(String studentName) { this.studentName = studentName; }
public Integer getStudentAge() { return studentAge; }
public void setStudentAge(Integer studentAge) { this.studentAge = studentAge; }
public String getStudentGender() { return studentGender; }
public void setStudentGender(String studentGender) { this.studentGender = studentGender; } }
|
分页工具类Page代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| package cn.bytecollege.util;
import java.util.List;
public class Page<T> {
private int currentIndex;
private int totalPage;
private int count;
private int pageSize = 10;
private List<T> list;
private String[] pageIndex = new String[10];
public int getCurrentIndex() { return currentIndex; }
public void setCurrentIndex(int currentIndex) { this.currentIndex = currentIndex; }
public int getCount() { return count; }
public void setCount(int count) { this.count = count; }
public int getPageSize() { return pageSize; }
public void setPageSize(int pageSize) { this.pageSize = pageSize; }
public int getTotalPage() { return totalPage; }
public void setTotalPage(int count) { totalPage = (count+pageSize-1)/pageSize; }
public List<T> getList() { return list; }
public void setList(List<T> list) { this.list = list; }
public void setPageIndex(int currentIndex){ if(totalPage<=pageIndex.length){ for (int i = 1; i <=pageIndex.length ; i++) { pageIndex[i-1] = String.valueOf(i); } return; } if(currentIndex<8){ for (int i = 1; i <=pageIndex.length ; i++) { pageIndex[i-1] = String.valueOf(i); } pageIndex[pageIndex.length-2] = "..."; pageIndex[pageIndex.length-1] = String.valueOf(totalPage); return; }else if(currentIndex>totalPage-8){ pageIndex[0] = String.valueOf(1); pageIndex[1] = "..."; int k = totalPage-7; for (int i = 2; i < pageIndex.length&&k<=totalPage; i++) { pageIndex[i] = String.valueOf(k); k++; } } } public String[] getPageIndex(){ return pageIndex; } }
|
新增学生
JSP页面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>修改学生信息</title> </head> <body> <div> <form action="${pageContext.request.contextPath}/add" method="post"> <input name="name" placeholder="学生姓名"><br> <input name="age" placeholder="学生年龄"><br> <select name="gender"> <option value="男">男</option> <option value="女">女</option> </select> <br> <input type="submit" value="提交"> </form> </div> </body> </html>
|
Servlet代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| package cn.bytecollege.controller;
import cn.bytecollege.entity.Student; import cn.bytecollege.service.StudentService;
import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.sql.SQLException; @WebServlet(name = "AddStudentController",value = "/add") public class AddStudentController extends HttpServlet { private StudentService studentService; public AddStudentController(){ studentService = new StudentService(); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); String studentName = request.getParameter("name"); String studentAge = request.getParameter("age"); String studentGender = request.getParameter("gender"); Student student = new Student(); student.setStudentAge(Integer.valueOf(studentAge)); student.setStudentName(studentName); student.setStudentGender(studentGender); try { studentService.add(student); } catch (SQLException throwables) { throwables.printStackTrace(); } response.sendRedirect(request.getContextPath()+"/studentList"); } }
|
删除学生
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| package cn.bytecollege.controller;
import cn.bytecollege.service.StudentService;
import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.annotation.*; import java.io.IOException; import java.sql.SQLException;
@WebServlet(name = "DeleteStudentController", value = "/delete") public class DeleteStudentController extends HttpServlet { private StudentService studentService; public DeleteStudentController() { studentService = new StudentService(); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String studentId = request.getParameter("id"); try { studentService.deleteById(studentId); } catch (SQLException throwables) { throwables.printStackTrace(); } response.sendRedirect(request.getContextPath()+"/studentList"); } }
|
修改学生
根据ID查询学生信息FindStudentController代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| package cn.bytecollege.controller;
import cn.bytecollege.entity.Student; import cn.bytecollege.service.StudentService;
import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.annotation.*; import java.io.IOException; import java.sql.SQLException;
@WebServlet(name = "FindStudentController", value = "/findStudent") public class FindStudentController extends HttpServlet { private StudentService studentService;
public FindStudentController() { studentService = new StudentService(); }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); }
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String id = request.getParameter("id"); Student student = null; try{ student = studentService.findById(id); }catch (SQLException e){ e.printStackTrace(); } request.setAttribute("student",student); request.getRequestDispatcher(request.getContextPath()+"/update.jsp").forward(request,response); } }
|
update.jsp页面如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>修改学生信息</title> </head> <body> <form action="${pageContext.request.contextPath}/updateStudent" method="post"> <input name="name" placeholder="学生姓名" value="${student.studentName}"><br> <input name="age" placeholder="学生年龄" value="${student.studentAge}"><br> <select name="gender"> <c:choose> <c:when test="${student.studentGender eq '男'}"> <option value="男" selected>男</option> <option value="女">女</option> </c:when> <c:otherwise> <option value="男">男</option> <option value="女" selected>女</option> </c:otherwise> </c:choose> </select> <br> <input type="hidden" name="id" value="${student.studentId}"> <input type="submit" value="提交"> </form> </body> </html>
|
UpdateStudentController代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| package cn.bytecollege.controller;
import cn.bytecollege.entity.Student; import cn.bytecollege.service.StudentService;
import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.annotation.*; import java.io.IOException; import java.sql.SQLException;
@WebServlet(name = "UpdateStudentController", value = "/updateStudent") public class UpdateStudentController extends HttpServlet { private StudentService studentService; public UpdateStudentController(){ studentService = new StudentService(); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); }
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); String id = request.getParameter("id"); String studentName = request.getParameter("name"); String studentAge = request.getParameter("age"); String studentGender = request.getParameter("gender"); Student student = new Student(); student.setStudentId(Integer.parseInt(id)); student.setStudentAge(Integer.valueOf(studentAge)); student.setStudentName(studentName); student.setStudentGender(studentGender);
try { studentService.update(student); } catch (SQLException throwables) { throwables.printStackTrace(); } response.sendRedirect(request.getContextPath()+"/studentList"); } }
|
分页查询学生
学生列表页面如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| <%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>学生列表</title> <style> .pageNum{ display: inline-block; width: 30px; height: 30px; text-align: center; line-height: 30px; background-color: #009688; color: white; text-decoration: none; } .active{ background-color: #FF5722 !important; } </style> </head> <body> <table align="center" width="600" border="1"> <thead> <tr> <td>ID</td> <td>姓名</td> <td>性别</td> <td>年龄</td> <td>编辑</td> <td>删除</td> <%-- <td>编辑</td>--%> </tr> </thead> <tbody> <c:forEach var="student" items="${page.list}"> <tr> <td>${student.studentId}</td> <td>${student.studentName}</td> <td>${student.studentAge}</td> <td>${student.studentGender}</td> <td><a href="${pageContext.request.contextPath}/findStudent?id=${student.studentId}">编辑</a></td> <td><a href="${pageContext.request.contextPath}/delete?id=${student.studentId}">删除</a></td> </tr> </c:forEach> </tbody> </table> <div style="text-align: center">当前第${page.currentIndex},共${page.totalPage}页</div> <div style="text-align: center"> <% Page p = (Page) request.getAttribute("page"); request.setAttribute("current",String.valueOf(p.getCurrentIndex())); %> <c:forEach var="item" items="${page.pageIndex}"> <c:if test="${item != '...'}"> <c:choose> <c:when test="${item eq current}"> <a class="pageNum active" href="${pageContext.request.contextPath}/studentList?page=${item}">${item}</a> </c:when> <c:otherwise> <a class="pageNum" href="${pageContext.request.contextPath}/studentList?page=${item}">${item}</a> </c:otherwise> </c:choose> </c:if> <c:if test="${item eq '...'}"> <a class="pageNum" href="#">${item}</a> </c:if> </c:forEach> </div> </body> </html>
|
StudentListController代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| package cn.bytecollege.controller;
import cn.bytecollege.service.StudentService; import cn.bytecollege.util.Page;
import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.annotation.*; import java.io.IOException; import java.sql.SQLException; import java.util.Optional;
@WebServlet(name = "StudentListController", value = "/studentList") public class StudentListController extends HttpServlet { private StudentService studentService; public StudentListController() { studentService = new StudentService(); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String page = request.getParameter("page"); String size = request.getParameter("size"); if(page==null){ page = "1"; } if(size==null){ size = "5"; } Page p = null; try { p = studentService.findStudentByPage(Integer.parseInt(page),Integer.parseInt(size)); } catch (SQLException throwables) { throwables.printStackTrace(); } request.setAttribute("page",p); request.getRequestDispatcher("/index.jsp").forward(request,response); } }
|
Maven pom.xml配置清单
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd">
<parent> <artifactId /> <groupId /> <version />
<relativePath /> </parent> <modelVersion>4.0.0</modelVersion> <groupId>asia.banseon</groupId>
<artifactId>banseon-maven2</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>banseon-maven</name> <url>http://www.baidu.com/banseon</url>
<description>A maven project to study maven.</description> <prerequisites> <maven /> </prerequisites> <issueManagement> <system>jira</system> <url>http://jira.baidu.com/banseon</url> </issueManagement> <ciManagement> <system /> <url /> <notifiers> <notifier> <type /> <sendOnError /> <sendOnFailure /> <sendOnSuccess /> <sendOnWarning /> <address /> <configuration /> </notifier> </notifiers> </ciManagement> <inceptionYear /> <mailingLists> <mailingList> <name>Demo</name> <post>banseon@126.com</post> <subscribe>banseon@126.com</subscribe> <unsubscribe>banseon@126.com</unsubscribe> <archive>http:/hi.baidu.com/banseon/demo/dev/</archive> </mailingList> </mailingLists> <developers> <developer> <id>HELLO WORLD</id> <name>banseon</name> <email>banseon@126.com</email> <url /> <roles> <role>Project Manager</role> <role>Architect</role> </roles> <organization>demo</organization> <organizationUrl>http://hi.baidu.com/banseon</organizationUrl> <properties> <dept>No</dept> </properties> <timezone>-5</timezone> </developer> </developers> <contributors> <contributor> <name /> <email /> <url /> <organization /> <organizationUrl /> <roles /> <timezone /> <properties /> </contributor> </contributors> <licenses> <license> <name>Apache 2</name> <url>http://www.baidu.com/banseon/LICENSE-2.0.txt</url> <distribution>repo</distribution> <comments>A business-friendly OSS license</comments> </license> </licenses> <scm> <connection> scm:svn:http://svn.baidu.com/banseon/maven/banseon/banseon-maven2-trunk(dao-trunk) </connection> <developerConnection> scm:svn:http://svn.baidu.com/banseon/maven/banseon/dao-trunk </developerConnection> <tag /> <url>http://svn.baidu.com/banseon</url> </scm> <organization> <name>demo</name> <url>http://www.baidu.com/banseon</url> </organization> <build> <sourceDirectory /> <scriptSourceDirectory /> <testSourceDirectory /> <outputDirectory /> <testOutputDirectory /> <extensions> <extension> <groupId /> <artifactId /> <version /> </extension> </extensions> <defaultGoal /> <resources> <resource>
<targetPath /> <filtering /> <directory /> <includes /> <excludes /> </resource> </resources> <testResources> <testResource> <targetPath /> <filtering /> <directory /> <includes /> <excludes /> </testResource> </testResources> <directory /> <finalName /> <filters /> <pluginManagement> <plugins> <plugin> <groupId /> <artifactId /> <version /> <extensions /> <executions> <execution> <id /> <phase /> <goals /> <inherited /> <configuration /> </execution> </executions> <dependencies> <dependency> ...... </dependency> </dependencies> <inherited /> <configuration /> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId /> <artifactId /> <version /> <extensions /> <executions> <execution> <id /> <phase /> <goals /> <inherited /> <configuration /> </execution> </executions> <dependencies> <dependency> ...... </dependency> </dependencies> <goals /> <inherited /> <configuration /> </plugin> </plugins> </build> <profiles> <profile> <id /> <activation> <activeByDefault /> <jdk /> <os> <name>Windows XP</name> <family>Windows</family> <arch>x86</arch> <version>5.1.2600</version> </os> <property> <name>mavenVersion</name> <value>2.0.3</value> </property> <file> <exists>/usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ </exists> <missing>/usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ </missing> </file> </activation> <build> <defaultGoal /> <resources> <resource> <targetPath /> <filtering /> <directory /> <includes /> <excludes /> </resource> </resources> <testResources> <testResource> <targetPath /> <filtering /> <directory /> <includes /> <excludes /> </testResource> </testResources> <directory /> <finalName /> <filters /> <pluginManagement> <plugins> <plugin> <groupId /> <artifactId /> <version /> <extensions /> <executions> <execution> <id /> <phase /> <goals /> <inherited /> <configuration /> </execution> </executions> <dependencies> <dependency> ...... </dependency> </dependencies> <goals /> <inherited /> <configuration /> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId /> <artifactId /> <version /> <extensions /> <executions> <execution> <id /> <phase /> <goals /> <inherited /> <configuration /> </execution> </executions> <dependencies> <dependency> ...... </dependency> </dependencies> <goals /> <inherited /> <configuration /> </plugin> </plugins> </build> <modules /> <repositories> <repository> <releases> <enabled /> <updatePolicy /> <checksumPolicy /> </releases> <snapshots> <enabled /> <updatePolicy /> <checksumPolicy /> </snapshots> <id /> <name /> <url /> <layout /> </repository> </repositories> <pluginRepositories> <pluginRepository> <releases> <enabled /> <updatePolicy /> <checksumPolicy /> </releases> <snapshots> <enabled /> <updatePolicy /> <checksumPolicy /> </snapshots> <id /> <name /> <url /> <layout /> </pluginRepository> </pluginRepositories> <dependencies> <dependency> ...... </dependency> </dependencies> <reports /> <reporting> ...... </reporting> <dependencyManagement> <dependencies> <dependency> ...... </dependency> </dependencies> </dependencyManagement> <distributionManagement> ...... </distributionManagement> <properties /> </profile> </profiles> <modules /> <repositories> <repository> <releases> <enabled /> <updatePolicy /> <checksumPolicy /> </releases>
<snapshots> <enabled /> <updatePolicy /> <checksumPolicy /> </snapshots> <id>banseon-repository-proxy</id> <name>banseon-repository-proxy</name> <url>http://192.168.1.169:9999/repository/</url>
<layout>default</layout> </repository> </repositories> <pluginRepositories> <pluginRepository> ...... </pluginRepository> </pluginRepositories> <dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-artifact</artifactId> <version>3.8.1</version>
<type>jar</type>
<classifier></classifier>
<scope>test</scope> <systemPath></systemPath> <exclusions> <exclusion> <artifactId>spring-core</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> <optional>true</optional> </dependency> </dependencies> <reports></reports> <reporting> <excludeDefaults /> <outputDirectory /> <plugins> <plugin> <groupId /> <artifactId /> <version /> <inherited /> <configuration /> <reportSets> <reportSet> <id /> <configuration /> <inherited /> <reports /> </reportSet> </reportSets> </plugin> </plugins> </reporting>
<dependencyManagement> <dependencies> <dependency> ...... </dependency> </dependencies> </dependencyManagement> <distributionManagement> <repository> <uniqueVersion /> <id>banseon-maven2</id> <name>banseon maven2</name> <url>file://${basedir}/target/deploy</url> <layout /> </repository> <snapshotRepository> <uniqueVersion /> <id>banseon-maven2</id> <name>Banseon-maven2 Snapshot Repository</name> <url>scp://svn.baidu.com/banseon:/usr/local/maven-snapshot</url> <layout /> </snapshotRepository> <site> <id>banseon-site</id> <name>business api website</name> <url> scp://svn.baidu.com/banseon:/var/www/localhost/banseon-web </url> </site> <downloadUrl /> <relocation> <groupId /> <artifactId /> <version /> <message /> </relocation>
<status /> </distributionManagement> <properties /> </project>
|