eclipse(springmvc+spring+mybatis)
案例下载:SSM
整合包:springmvc+spring+mybatis
4、添加目录结构
5、导入SSM所需要的jar包
6、添加jsp
![]()
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="<%=path %>/userController/login.do" method="post">
<table>
<tr>
<td>用户名</td>
<td><input type="text" name="ename"></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td><input type="submit" value="立即登陆"></td>
</tr>
</table>
</form>
</body>
</html>
add.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'add.jsp' starting page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="<%=path %>/userController/add.do" method="post">
<input type="hidden" name="password" value="123">
<table>
<tr>
<td>姓名</td>
<td><input type="text" name="ename"></td>
</tr>
<tr>
<td>所属部门</td>
<td><input type="text" name="dept"></td>
</tr>
<tr>
<td>年龄</td>
<td><input type="text" name="age"></td>
</tr>
<tr>
<td>性别</td>
<td><input type="text" name="gender"></td>
</tr>
<tr>
<td>入职时间</td>
<td><input type="text" name="workdate"></td>
</tr>
<tr>
<td><input type="submit" value="添加"></td>
<td><input type="button" value="返回" onclick="history.go(-1);"></td>
</tr>
</table>
</form>
</body>
</html>
list.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<c:set value="${pageContext.request.contextPath}" scope="page" var="ctx"></c:set>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'list.jsp' starting page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
body{
font-family: Microsoft Yahei, sans-serif;
}
</style>
</head>
<body>
<div>
<input type="button" value="查询" onclick="window.location.href='<%=path %>/userController/list.do'">
<input type="button" value="添加" onclick="window.location.href='<%=path %>/userController/toadd.do'">
</div>
<table>
<thead>
<tr>
<th>编号</th>
<th>姓名</th>
<th>所属部门</th>
<th>年龄</th>
<th>性别</th>
<th>入职时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach items="${users}" var="item" varStatus="status">
<tr>
<td>${item.eid }</td>
<td>${item.ename }</td>
<td>${item.dept }</td>
<td>${item.age }</td>
<td>${item.gender }</td>
<td><fmt:formatDate value="${item.workdate }" type="both" pattern="yyyy-MM-dd"/></td>
<td>
<a href="<%=path %>/userController/toupdate.do?eid=${item.eid }">修改</a>/
<a href="<%=path %>/userController/delete.do?eid=${item.eid }">删除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>
update.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'update.jsp' starting page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="<%=path %>/userController/update.do" method="post">
<input type="hidden" name="password" value="${users.password }">
<input type="hidden" name="eid" value="${users.eid }">
<table>
<tr>
<td>姓名</td>
<td><input type="text" name="ename" value="${users.ename }"></td>
</tr>
<tr>
<td>所属部门</td>
<td><input type="text" name="dept" value="${users.dept }"></td>
</tr>
<tr>
<td>年龄</td>
<td><input type="text" name="age" value="${users.age }"></td>
</tr>
<tr>
<td>性别</td>
<td><input type="text" name="gender" value="${users.gender }"></td>
</tr>
<tr>
<td>入职时间</td>
<td>
<fmt:formatDate var="newdate" value="${users.workdate}" pattern="yyyy-MM-dd"/>
<input type="text" name="workdate" value="${newdate }">
</td>
</tr>
<tr>
<td><input type="submit" value="修改"></td>
<td><input type="button" value="返回" onclick="history.go(-1);"></td>
</tr>
</table>
</form>
</body>
</html>
框架搭建结束!