SSM框架單表增刪改查項目開發(fā)流程詳解
SSM框架單表增刪改查項目開發(fā)流程詳解
?
?
1.數(shù)據(jù)庫建表;
?
student.sql建表SQL:
create database school;
?
use school;
?
create table student(
? id int(11) unique key auto_increment,
? sno int(11) primary key,
? sname varchar(30),
? sex char(1),
? birth date,
? university varchar(50),
? dept varchar(50),
? major varchar(50),
? appearance varchar(10)
);
?
2. 新建maven項目,并在pom.xml文件中引入下列依賴;
<properties>
??? <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
??? <maven.compiler.source>1.7</maven.compiler.source>
??? <maven.compiler.target>1.7</maven.compiler.target>
??? <spring.version>5.2.19.RELEASE</spring.version>
? </properties>
? <dependencies>
<!--??? junit單元測試包-->
??? <dependency>
????? <groupId>junit</groupId>
????? <artifactId>junit</artifactId>
????? <version>4.12</version>
????? <scope>test</scope>
??? </dependency>
<!--??? Spring框架包-->
<!--??? spring-core包-->
??? <dependency>
????? <groupId>org.springframework</groupId>
????? <artifactId>spring-core</artifactId>
????? <version>${spring.version}</version>
??? </dependency>
<!--?? ?spring-beans包-->
??? <dependency>
????? <groupId>org.springframework</groupId>
????? <artifactId>spring-beans</artifactId>
????? <version>${spring.version}</version>
??? </dependency>
<!--??? spring-context包-->
??? <dependency>
????? <groupId>org.springframework</groupId>
????? <artifactId>spring-context</artifactId>
????? <version>${spring.version}</version>
??? </dependency>
<!--??? spring-context-support包-->
??? <dependency>
????? <groupId>org.springframework</groupId>
????? <artifactId>spring-context-support</artifactId>
????? <version>${spring.version}</version>
??? </dependency>
<!--??? spring-web包-->
??? <dependency>
????? <groupId>org.springframework</groupId>
????? <artifactId>spring-web</artifactId>
????? <version>${spring.version}</version>
??? </dependency>
<!--??? spring-webmvc包-->
??? <dependency>
????? <groupId>org.springframework</groupId>
????? <artifactId>spring-webmvc</artifactId>
????? <version>${spring.version}</version>
??? </dependency>
<!--??? spring-expression包-->
??? <dependency>
????? <groupId>org.springframework</groupId>
????? <artifactId>spring-expression</artifactId>
????? <version>${spring.version}</version>
??? </dependency>
<!--??? spring-aop包-->
??? <dependency>
????? <groupId>org.springframework</groupId>
????? <artifactId>spring-aop</artifactId>
????? <version>${spring.version}</version>
??? </dependency>
<!--??? spring-tx包-->
??? <dependency>
????? <groupId>org.springframework</groupId>
????? <artifactId>spring-tx</artifactId>
????? <version>${spring.version}</version>
??? </dependency>
<!--??? spring-aspects包-->
??? <dependency>
????? <groupId>org.springframework</groupId>
????? <artifactId>spring-aspects</artifactId>
????? <version>${spring.version}</version>
??? </dependency>
<!--??? spring-jcl包-->
??? <dependency>
????? <groupId>org.springframework</groupId>
????? <artifactId>spring-jcl</artifactId>
????? <version>${spring.version}</version>
??? </dependency>
<!--??? spring-jdbc包-->
??? <dependency>
????? <groupId>org.springframework</groupId>
????? <artifactId>spring-jdbc</artifactId>
????? <version>${spring.version}</version>
??? </dependency>
<!--??? spring-test包-->
??? <dependency>
????? <groupId>org.springframework</groupId>
????? <artifactId>spring-test</artifactId>
????? <version>${spring.version}</version>
??? </dependency>
<!--??? MyBatis框架包-->
<!--??? mybatis包-->
??? <dependency>
????? <groupId>org.mybatis</groupId>
????? <artifactId>mybatis</artifactId>
????? <version>3.5.9</version>
??? </dependency>
<!--??? MyBatis和Spring框架整合包-->
<!--??? mybatis-spring包-->
??? <dependency>
????? <groupId>org.mybatis</groupId>
????? <artifactId>mybatis-spring</artifactId>
????? <version>2.0.7</version>
??? </dependency>
<!--??? MySQL數(shù)據(jù)庫包-->
<!--??? mysql-connector-java包-->
??? <dependency>
????? <groupId>mysql</groupId>
????? <artifactId>mysql-connector-java</artifactId>
????? <version>8.0.30</version>
??? </dependency>
<!--??? 數(shù)據(jù)庫連接池包-->
<!--??? commons-pool2包-->
??? <dependency>
????? <groupId>org.apache.commons</groupId>
????? <artifactId>commons-pool2</artifactId>
????? <version>2.11.1</version>
??? </dependency>
<!--????? commons-dbcp2包-->
??? <dependency>
????? <groupId>org.apache.commons</groupId>
????? <artifactId>commons-dbcp2</artifactId>
????? <version>2.9.0</version>
??? </dependency>
<!--????? 日志包-->
<!--????? commons-logging包-->
??? <dependency>
????? <groupId>commons-logging</groupId>
????? <artifactId>commons-logging</artifactId>
????? <version>1.2</version>
??? </dependency>
<!--????? log4j包-->
??? <dependency>
????? <groupId>log4j</groupId>
????? <artifactId>log4j</artifactId>
????? <version>1.2.17</version>
??? </dependency>
<!--????? slf4j-api包-->
??? <dependency>
????? <groupId>org.slf4j</groupId>
????? <artifactId>slf4j-api</artifactId>
????? <version>2.0.1</version>
??? </dependency>
<!--????? slf4j-log4j12包-->
??? <dependency>
????? <groupId>org.slf4j</groupId>
????? <artifactId>slf4j-log4j12</artifactId>
????? <version>2.0.1</version>
??? </dependency>
<!--????? Servlet包-->
<!--????? servlet-api包-->
??? <dependency>
????? <groupId>javax.servlet</groupId>
????? <artifactId>servlet-api</artifactId>
????? <version>2.5</version>
??? </dependency>
<!--????? jsp-api包-->
??? <dependency>
????? <groupId>javax.servlet</groupId>
????? <artifactId>jsp-api</artifactId>
????? <version>2.0</version>
??? </dependency>
<!--????? JSP標(biāo)準(zhǔn)標(biāo)簽庫包-->
<!--??? jstl包-->
??? <dependency>
????? <groupId>jstl</groupId>
????? <artifactId>jstl</artifactId>
????? <version>1.2</version>
??? </dependency>
?????? </dependencies>
3.在maven項目中建好如下圖所示目錄結(jié)構(gòu);
?
4.在java目錄下建好下圖所示結(jié)構(gòu);
?
5、在resources和webapp目錄下建好下圖所示結(jié)構(gòu);
?
6.項目源碼。
Student.java:
package com.culture.model;
import java.sql.Date;
public class Student {
??? private int id;
??? private int sno;
??? private String sname;
??? private char sex;
??? private Date birth;
??? private String university;
??? private String dept;
??? private String major;
??? private String appearance;
??? public int getId() {
??????? return id;
??? }
??? public void setId(int id) {
??????? this.id = id;
??? }
??? public int getSno() {
??????? return sno;
??? }
??? public void setSno(int sno) {
??????? this.sno = sno;
??? }
??? public String getSname() {
??????? return sname;
??? }
??? public void setSname(String sname) {
??????? this.sname = sname;
??? }
??? public char getSex() {
??????? return sex;
??? }
??? public void setSex(char sex) {
??????? this.sex = sex;
??? }
??? public Date getBirth() {
??????? return birth;
??? }
??? public void setBirth(Date birth) {
??????? this.birth = birth;
??? }
??? public String getUniversity() {
??????? return university;
??? }
??? public void setUniversity(String university) {
??????? this.university = university;
??? }
??? public String getDept() {
??????? return dept;
??? }
??? public void setDept(String dept) {
??????? this.dept = dept;
??? }
??? public String getMajor() {
??????? return major;
??? }
??? public void setMajor(String major) {
??????? this.major = major;
??? }
??? public String getAppearance() {
??????? return appearance;
??? }
??? public void setAppearance(String appearance) {
??????? this.appearance = appearance;
??? }
??? @Override
??? public String toString() {
??????? return "Student{" +
??????????????? "id=" + id +
??????????????? ", sno=" + sno +
??????????????? ", sname='" + sname + '\'' +
??????????????? ", sex=" + sex +
??????????????? ", birth=" + birth +
??????????????? ", university='" + university + '\'' +
??????????????? ", dept='" + dept + '\'' +
??????????????? ", major='" + major + '\'' +
??????????????? ", appearance='" + appearance + '\'' +
??????????????? '}';
??? }
}
?
StudentDao.java:
package com.culture.dao;
import com.culture.model.Student;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface StudentDao {
??? @Insert("insert into student(sno,sname,sex,birth,university,dept,major,appearance) " +
?? ?????????"values(#{sno},#{sname},#{sex},#{birth},#{university},#{dept},#{major},#{appearance})")
??? public void insertStudent(Student student);
??? @Select("select * from student order by id")
??? public List<Student> selectAllStudent();
??? @Select("select * from student where sno=#{sno}")
??? public List<Student> selectStudentBySno(int sno);
???
??? @Delete("delete from student where sno=#{sno};" +
??????????? "alter table student drop id;" +
??????????? "alter table student add id int(11) unique key auto_increment FIRST;")
??? public void deleteStudentBySno(int sno);
??? @Delete("truncate table student")
??? public void deleteAllStudent(Student student);
??? @Update("update student set sname=#{sname},sex=#{sex},birth=#{birth},university=#{university}," +
??????????? "dept=#{dept},major=#{major},appearance=#{appearance} where sno=#{sno}")
??? public void updateStudent(Student student);
}
StudentService.java:
package com.culture.service;
import com.culture.model.Student;
import java.util.List;
public interface StudentService {
??? public void insertStudent(Student student);
??? public List<Student> selectAllStudent();
??? public List<Student> selectStudentBySno(int sno);
??? public void deleteStudentBySno(int sno);
??? public void deleteAllStudent(Student student);
??? public void updateStudent(Student student);
}
?
StudentServiceImpl.java:
package com.culture.service.impl;
import com.culture.dao.StudentDao;
import com.culture.model.Student;
import com.culture.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("studentService")
public class StudentServiceImpl implements StudentService {
??? @Autowired
??? private StudentDao studentDao;
??? @Override
??? public void insertStudent(Student student) {
??????? studentDao.insertStudent(student);
??? }
??? @Override
??? public List<Student> selectAllStudent() {
??????? return studentDao.selectAllStudent();
??? }
??? @Override
??? public List<Student> selectStudentBySno(int sno) {
??????? return studentDao.selectStudentBySno(sno);
??? }
??? @Override
??? public void deleteStudentBySno(int sno) {
??????? studentDao.deleteStudentBySno(sno);
??? }
??? @Override
??? public void deleteAllStudent(Student student) {
??????? studentDao.deleteAllStudent(student);
??? }
??? @Override
??? public void updateStudent(Student student) {
??????? studentDao.updateStudent(student);
??? }
}
?
index.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
??? <form action="./student/insert" method="post">
??????? 學(xué)號:<input type="text" name="sno" placeholder="學(xué)號" autocomplete="off" required/><br/>
??????? 姓名:<input type="text" name="sname" placeholder="姓名" autocomplete="off" required/><br/>
??????? 性別:<input type="text" name="sex" placeholder="性別" autocomplete="off" required/><br/>
??????? 出生日期:<input type="date" name="birth"/><br/>
??????? 學(xué)校:<input type="text" name="university" placeholder="學(xué)校" autocomplete="off" required/><br/>
??????? 系別:<input type="text" name="dept" placeholder="系別" autocomplete="off" required/><br/>
??????? 專業(yè):<input type="text" name="major" placeholder="專業(yè)" autocomplete="off" required/><br/>
??????? 政治面貌:<input type="text" name="appearance" placeholder="政治面貌" autocomplete="off" required/><br/>
??????? <input type="submit" value="增加學(xué)生"/><input type="reset" value="清空"/>
??? </form>
??? <a href="./student/selectall">查詢所有學(xué)生信息</a>
??? <br/><br/>
??? <form action="./student/selectbysno" method="post">
??????? 學(xué)號:<input type="text" name="sno" placeholder="學(xué)號" autocomplete="off" required/><br/>
??????? <input type="submit" value="通過學(xué)號查詢學(xué)生"/><input type="reset" value="清空"/>
??? </form>
??? <form action="./student/deletebysno" method="post">
??????? 學(xué)號:<input type="text" name="sno" placeholder="學(xué)號" autocomplete="off" required/><br/>
??????? <input type="submit" value="通過學(xué)號刪除學(xué)生"/><input type="reset" value="清空"/>
??? </form>
??? <a href="./student/deleteall">刪除所有學(xué)生信息</a>
??? <br/><br/>
??? <form action="./student/update" method="post">
??????? 學(xué)號:<input type="text" name="sno" placeholder="學(xué)號" autocomplete="off" required/><br/>
??????? 姓名:<input type="text" name="sname" placeholder="姓名" autocomplete="off" required/><br/>
??????? 性別:<input type="text" name="sex" placeholder="性別" autocomplete="off" required/><br/>
??????? 出生日期:<input type="date" name="birth"/><br/>
??????? 學(xué)校:<input type="text" name="university" placeholder="學(xué)校" autocomplete="off" required/><br/>
??????? 系別:<input type="text" name="dept" placeholder="系別" autocomplete="off" required/><br/>
??????? 專業(yè):<input type="text" name="major" placeholder="專業(yè)" autocomplete="off" required/><br/>
??????? 政治面貌:<input type="text" name="appearance" placeholder="政治面貌" autocomplete="off" required/><br/>
??????? <input type="submit" value="修改學(xué)生信息"/><input type="reset" value="清空"/>
??? </form>
</body>
</html>
?
insertstudent.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
??? <title>插入學(xué)生信息</title>
??? <style>
??????? body{
??????????? text-align: center;
??????? }
??? </style>
</head>
<body>
<h1>插入成功</h1>
<a href="../index.jsp">返回主頁</a>
</body>
</html>
?
selectallstudent.jsp:
<%@ 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>查看所有學(xué)生信息</title>
??? <style>
??????? table{
??????????? margin: auto;
??????????? text-align: center;
??????? }
??? </style>
</head>
<body>
??? <table border="1px">
??????? <caption>所有學(xué)生信息</caption>
??????? <tr>
??????????? <th>ID</th>
??????????? <th>學(xué)號</th>
??????????? <th>姓名</th>
??????????? <th>性別</th>
??????????? <th>出生日期</th>
??????????? <th>學(xué)校</th>
??????????? <th>系別</th>
??????????? <th>專業(yè)</th>
??????????? <th>政治面貌</th>
??????? </tr>
??????? <c:forEach items="${students}" var="student">
??????????? <tr>
??????????????? <td>${student.id}</td>
??????????????? <td>${student.sno}</td>
??????????????? <td>${student.sname}</td>
??????????????? <td>${student.sex}</td>
??????????????? <td>${student.birth}</td>
??????????????? <td>${student.university}</td>
??????????????? <td>${student.dept}</td>
??????????????? <td>${student.major}</td>
??????????????? <td>${student.appearance}</td>
??????????? </tr>
??????? </c:forEach>
??????? <tr>
??????????? <td colspan="9"><a href="../index.jsp">返回主頁</a> </td>
??????? </tr>
??? </table>
</body>
</html>
?
selectstudentbysno.jsp:
<%@ 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>通過學(xué)號查詢一個學(xué)生</title>
??? <style>
??????? table{
??????????? margin: auto;
??????????? text-align: center;
??????? }
??? </style>
</head>
<body>
??? <table border="1px">
??????? <caption>學(xué)生信息</caption>
??????? <tr>
??????????? <th>ID</th>
??????????? <th>學(xué)號</th>
??????????? <th>姓名</th>
??????????? <th>性別</th>
??????????? <th>出生日期</th>
??????????? <th>學(xué)校</th>
??????????? <th>系別</th>
??????????? <th>專業(yè)</th>
??????????? <th>政治面貌</th>
??????? </tr>
??????? <c:forEach items="${onestudent}" var="onestu">
??????????? <tr>
??????????????? <td>${onestu.id}</td>
??????????????? <td>${onestu.sno}</td>
??????????????? <td>${onestu.sname}</td>
??????????????? <td>${onestu.sex}</td>
??????????????? <td>${onestu.birth}</td>
??????????????? <td>${onestu.university}</td>
??????????????? <td>${onestu.dept}</td>
??????????????? <td>${onestu.major}</td>
??????????????? <td>${onestu.appearance}</td>
??????????? </tr>
??????? </c:forEach>
??????? <tr>
??????????? <td colspan="9"><a href="../index.jsp">返回主頁</a> </td>
??????? </tr>
??? </table>
</body>
</html>
?
updatestudent.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
??? <title>修改學(xué)生信息</title>
??? <style>
??????? body{
??????????? text-align: center;
??????? }
??? </style>
</head>
<body>
<h1>修改成功</h1>
<a href="../index.jsp">返回主頁</a>
</body>
</html>
?
deletestudentbysno.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
??? <title>通過學(xué)號刪除學(xué)生</title>
??? <style>
??????? body{
??????????? text-align: center;
??????? }
??? </style>
</head>
<body>
<h1>成功刪除此學(xué)號學(xué)生</h1>
<a href="../index.jsp">返回主頁</a>
</body>
</html>
?
deleteallstudent.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
??? <title>刪除所有學(xué)生信息</title>
??? <style>
??????? body{
??????????? text-align: center;
??????? }
??? </style>
</head>
<body>
<h1>刪除成功</h1>
<a href="../index.jsp">返回主頁</a>
</body>
</html>
?
StudentController.java:
package com.culture.controller;
import com.culture.model.Student;
import com.culture.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@Controller("studentController")
@RequestMapping("/student")
public class StudentController {
??? @Autowired
??? private StudentService studentService;
??? @RequestMapping("/insert")
??? public String insertStudent(Student student){
??????? studentService.insertStudent(student);
??????? return "insertstudent";
??? }
??? @RequestMapping("/selectall")
??? public String selectAllStudent(Model model){
??????? List<Student> students=studentService.selectAllStudent();
??????? model.addAttribute("students",students);
??????? return "selectallstudent";
??? }
??? @RequestMapping("/selectbysno")
??? public String selectStudentBySno(int sno,Model model){
??????? List<Student> onestudent=studentService.selectStudentBySno(sno);
??????? model.addAttribute("onestudent",onestudent);
??????? return "selectstudentbysno";
??? }
??? @RequestMapping("/deletebysno")
??? public String deleteStudentBySno(int sno){
??????? studentService.deleteStudentBySno(sno);
??????? return "deletestudentbysno";
??? }
??? @RequestMapping("/deleteall")
??? public String deleteAllStudent(Student student){
??????? studentService.deleteAllStudent(student);
??????? return "deleteallstudent";
??? }
??? @RequestMapping("/update")
??? public String updateStudent(Student student){
??????? studentService.updateStudent(student);
??????? return "updatestudent";
??? }
}
?
log4j.properties:
# Global logging configuration
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration...
log4j.logger.com.dao=DEBUG
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
?
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
?????? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
?????? xmlns:context="http://www.springframework.org/schema/context"
?????? xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
??? <!--??? 配置掃描器,spring管理的是service層和dao層的注解,controller層的注解交給springmvc管理-->
??? <context:component-scan base-package="com.culture">
<!--??????? 要忽略的注解-->
??????? <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
??? </context:component-scan>
<!--??? 配置數(shù)據(jù)源-->
??? <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
??????? <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
??????? <property name="url" value="jdbc:mysql://localhost:3306/school?allowMultiQueries=true"/>
??????? <property name="username" value="root"/>
??????? <property name="password" value="123456"/>
??? </bean>
<!--??? 配置SqlSession工廠-->
??? <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--??????? 引入數(shù)據(jù)源-->
??????? <property name="dataSource" ref="dataSource"/>
??? </bean>
<!--??? 配置Dao接口所在的類-->
??? <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
??????? <property name="basePackage" value="com.culture.dao"/>
??? </bean>
</beans>
?
springmvc-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
?????? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
?????? xmlns:context="http://www.springframework.org/schema/context"
?????? xmlns:mvc="http://www.springframework.org/schema/mvc"
?????? xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--??? 掃描使得注解生效-->
??? <context:component-scan base-package="com.culture">
<!--??????? 只掃描controller層注解-->
??????? <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
??? </context:component-scan>
<!--??? 配置視圖解析器-->
??? <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
??????? <property name="prefix" value="/WEB-INF/view/"/>
??????? <property name="suffix" value=".jsp"/>
??? </bean>
<!--??? 開啟springmvc注解支持-->
??? <mvc:annotation-driven/>
</beans>
?
web.xml:
<!DOCTYPE web-app PUBLIC
?"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
?"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
? <display-name>Archetype Created Web Application</display-name>
? <context-param>
??? <param-name>contextConfigLocation</param-name>
??? <param-value>classpath:applicationContext.xml</param-value>
? </context-param>
? <filter>
??? <filter-name>characterEncodingFilter</filter-name>
??? <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<!--??? 字符集初始化為UTF-8-->
??? <init-param>
????? <param-name>encoding</param-name>
????? <param-value>UTF-8</param-value>
??? </init-param>
??? <init-param>
????? <param-name>forceEncoding</param-name>
????? <param-value>true</param-value>
??? </init-param>
? </filter>
? <filter-mapping>
??? <filter-name>characterEncodingFilter</filter-name>
??? <url-pattern>/*</url-pattern>
? </filter-mapping>
<!--? Spring的監(jiān)聽器-->
? <listener>
??? <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
? </listener>
?
? <servlet>
??? <servlet-name>dispatcherServlet</servlet-name>
??? <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
??? <init-param>
????? <param-name>contextConfigLocation</param-name>
????? <param-value>classpath:springmvc-servlet.xml</param-value>
??? </init-param>
<!--??? 立即啟動服務(wù)器,加載servlet-->
??? <load-on-startup>1</load-on-startup>
? </servlet>
? <servlet-mapping>
??? <servlet-name>dispatcherServlet</servlet-name>
??? <url-pattern>/</url-pattern>
? </servlet-mapping>
</web-app>
?
最后,配置T omcat本地服務(wù)器,啟動Tomcat服務(wù)器運行項目。