一、bootStrap
1、bootstrap介绍
- bootstrap是简洁、直观、强悍的前端开发框架,让web开发更迅速、简单。
- bootstrap是当下最流行的前端框架(界面工具集)。
- 目的是为了让web开发更敏捷。
2、为什么使用bootstrap
- 提供了一套美观大方的界面组件。
- 提供了一套优雅的HTML+CSS编码规范。
- 让web开发更简单、更快捷。
- 使用bootstrap并不代表不用写CSS样式,二是不用写绝大多数大家都会用到的样式。
- bootstrap提供了大量的全局样式,在基本的HTML标签上通过添加class设置样式得到增强的效果。
具体bootstrap框架代码
二、以书籍管理为例
1、service方法代码
@WebServlet("/book")
public class BookServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("BookServlet.service");
req.setCharacterEncoding("UTF-8");
String method = req.getParameter("method");
if (method == null || method == "") {
method = "select";
}
switch (method) {
case "select":
select(req,resp);
break;
case "delete":
delete(req,resp);
break;
case "insert":
insert(req,resp);
break;
case "selectById":
selectById(req,resp);
break;
case "update":
update(req,resp);
break;
}
}
private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException {
System.out.println("BookServlet.update");
String id = req.getParameter("id");
String name = req.getParameter("name");
String publish = req.getParameter("publish");
String price = req.getParameter("price");
Connection connection = null;
PreparedStatement statement = null;
try {
connection = JDBCUtil.getConnection();
String sql = "update book set name=?,publish=?,price=? where id=?";
statement = connection.prepareStatement(sql);
statement.setString(1,name);
statement.setString(2,publish);
statement.setDouble(3,Double.parseDouble(price));
statement.setInt(4,Integer.parseInt(id));
int count = statement.executeUpdate();
System.out.println("count:" + count);
} catch (SQLException throwables) {
throwables.printStackTrace();
} finally {
JDBCUtil.close(connection,statement,null);
}
resp.sendRedirect(req.getContextPath() + "/book?method=select");
}
private void selectById(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("BookServlet.selectById");
int id = Integer.parseInt(req.getParameter("id"));
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;