SSM整合-基于IDEA社区版和Maven
- 1 IDEA社区版环境搭建
- 1.1 Tomcat安装
- 1.2 IDEA社区版配置Tomcat
- 2 SSM整合
- 2.1 IDEA创建工程:
- 2.2 IDEA配置 smart tomcat
- 2.3 创建SpringMVC的配置文件并配置
- 2.4 创建Mybaits的配置文件并配置
- 2.4.1 在resources下创建属性文件jdbc.properties
- 2.4.2 创建MyBatis的核心配置文件mybatis-config.xml
- 2.4.3 创建日志文件log4j.xml
- 2.5 创建Spring的配置文件并配置
- 2.6 SSM整合测试
- 2.6.1 创建表
- 2.6.2 创建实体类
- 2.6.3 创建Mapper接口和映射文件
- 2.6.4 创建service层接口和实现类
- 2.6.5 创建Controller层控制器
- 2.6.6 创建index.html
- 2.6.7 创建student_list页面
- 2.6.8 测试运行
- 2.7 SSM整合总结
1 IDEA社区版环境搭建
1.1 Tomcat安装
- 下载安装Tomcat: Tomcat下载地址:https://tomcat.apache.org/,选择Tomcat9,选择64-bit Windows.zip下载。
下载文件名为apache-tomcat-9.0.62.zip。Tomcat9.0需要安装JDK8 的版本。解压压缩包到D:apache目录下,配置环境变量:
代码语言:javascript复制CATALINA_HOME = D:apacheapache-tomcat-9.0.62
在“系统变量”中找到Path变量,双击打开Path变量,在“变量值”的最后面添加:
代码语言:javascript复制�TALINA_HOME%bin
�TALINA_HOME%lib
在“系统变量”中找到CLASSPATH,在末尾处添加如下配置:
代码语言:javascript复制�TALINA_HOME%libservlet-api.jar;
进入Tomcat目录下的bin目录,输入cmd。如D:apacheapache-tomcat-9.0.62bin>目录下打开cmd命令行,在控制台输入 catalina run 过程如下:
代码语言:javascript复制D:apacheapache-tomcat-9.0.62bin>catalina run
Using CATALINA_BASE: "D:apacheapache-tomcat-9.0.62"
Using CATALINA_HOME: "D:apacheapache-tomcat-9.0.62"
Using CATALINA_TMPDIR: "D:apacheapache-tomcat-9.0.62temp"
Using JRE_HOME: "D:hadoopjdk1.8.0_181"
Using CLASSPATH: "D:apacheapache-tomcat-9.0.62binbootstrap.jar;D:apacheapache-tomcat-9.0.62bintomcat-juli.jar"
Using CATALINA_OPTS: ""
在浏览器打开
代码语言:javascript复制http://localhost:8080/
即可打开Tomcat首页,如下图所示,表示Tomcat安装成功。
关闭终端Tomcat9服务,以免IEDA运行时出现端口冲突。
1.2 IDEA社区版配置Tomcat
IDEA2020社区版本默认不包含tomcat,需要手动安装tomcat插件。打开IDEA。需要选择File–Settings–plugins–搜索tomcat–选择Marketplace–选择Smart Tomcat–Installed–点击ok–安装后重启IDEA,如图所示。
2 SSM整合
2.1 IDEA创建工程:
打开IDEA,选择File–new–project–选择maven工程–输入工程名称chapter15和GAV坐标(groupId为edu.hncj.ssm,artifactId为chapter15,version为默认)见图所示,输入后选择Finish。
在pom.xml文件中添加SSM的相关依赖如下:
代码语言:javascript复制<?xml version="1.0" encoding="UTF-8"?>
<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.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.hncj.ssm</groupId>
<artifactId>chapter15</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<spring.version>5.3.1</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<!--springmvc-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Mybatis核心 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.7</version>
</dependency>
<!--mybatis和spring的整合包-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.6</version>
</dependency>
<!-- 连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.9</version>
</dependency>
<!-- junit测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- MySQL驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
<!-- log4j日志 -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.2.0</version>
</dependency>
<!-- 日志 -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<!-- ServletAPI -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!-- Spring5和Thymeleaf整合包 -->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
<version>3.0.12.RELEASE</version>
</dependency>
</dependencies>
</project>
在java下新建如下包:
edu.hncj.ssm.controller edu.hncj.ssm.service edu.hncj.ssm.service.impl edu.hncj.ssm.mapper edu.hncj.ssm.pojo
工程目录结构设置:
由于社区版不支持web工程,需要手动创建webapp目录,工程创建完毕后,在工程的src.main目录下创建webapp目录,在webapp目录下创建WEB-INF目录,在WEB-INF目录下创建web.xml文件,内容如下:
代码语言:javascript复制<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<!-- 配置Spring的编码过滤器 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<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>
<!-- 配置处理请求方式PUT和DELETE的过滤器 -->
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 配置SpringMVC的前端控制器 -->
<!-- 配置SpringMVC的前端控制器,对浏览器发送的请求统一进行处理 -->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 设置SpringMVC的配置文件的位置和名称 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<!-- 使用classpath:表示从类路径查找配置文件,例如maven工程中的src/main/resources -->
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<!--
作为框架的核心组件,在启动过程中有大量的初始化操作要做
而这些操作放在第一次请求时才执行会严重影响访问速度
因此需要通过此标签将启动控制DispatcherServlet的初始化时间提前到服务器启动时
-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<!--
设置springMVC的核心控制器所能处理的请求的请求路径
/所匹配的请求可以是/login或.html或.js或.css方式的请求路径
但是/不能匹配.jsp请求路径的请求
-->
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- 设置Spring的配置文件的位置和名称 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<!-- 配置Spring的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
在手动添加tomcat下的servlet-api.jar到模块下,过程为File–Project Structure–Moudles–选择工程名chapter15–选择Dependencies–选择 号–添加tomcat所在目录的lib目录下的servlet-api.jar。
2.2 IDEA配置 smart tomcat
IDEA配置tomcat,选择Add Configuration–点击 号–选择smart tomcat–设置tomcat的相关参数–点击ok,默认的名称为Unnamed,如下图所示:
2.3 创建SpringMVC的配置文件并配置
在resources下创建springmvc.xml。内容如下:
代码语言:javascript复制<?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:mvc="http://www.springframework.org/schema/mvc"
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/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!--扫描组件-->
<context:component-scan base-package="edu.hncj.ssm.controller">
</context:component-scan>
<!--配置视图解析器-->
<bean id="viewResolver"
class="org.thymeleaf.spring5.view.ThymeleafViewResolver">
<property name="order" value="1"/>
<property name="characterEncoding" value="UTF-8"/>
<property name="templateEngine">
<bean class="org.thymeleaf.spring5.SpringTemplateEngine">
<property name="templateResolver">
<bean class="org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver">
<!-- 视图前缀 -->
<property name="prefix" value="/WEB-INF/templates/"/>
<!-- 视图后缀 -->
<property name="suffix" value=".html"/>
<property name="templateMode" value="HTML5"/>
<property name="characterEncoding" value="UTF-8"/>
</bean>
</property>
</bean>
</property>
</bean>
<!-- 配置默认的servlet处理静态资源 -->
<mvc:default-servlet-handler/>
<!-- 开启MVC的注解驱动 -->
<mvc:annotation-driven/>
<!-- 配置访问首页的视图控制 -->
<mvc:view-controller path="/" view-name="index"></mvc:view-controller>
<!--必须通过文件解析器的解析才能将文件转换为MultipartFile对象-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>
</beans>
2.4 创建Mybaits的配置文件并配置
2.4.1 在resources下创建属性文件jdbc.properties
代码语言:javascript复制jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssm?serverTimezone=UTC
jdbc.username=root
jdbc.password=111111
2.4.2 创建MyBatis的核心配置文件mybatis-config.xml
代码语言:javascript复制<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!--将下划线映射为驼峰-->
<setting name="mapUnderscoreToCamelCase" value="true"/>
<!--开启延迟加载-->
<setting name="lazyLoadingEnabled" value="true"/>
<!--按需加载-->
<setting name="aggressiveLazyLoading" value="false"/>
</settings>
<plugins>
<!--设置分页插件-->
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
</configuration>
依据mybatis部分的内容,会发现这里的配置明显减少,数据库的连接配置也没有,这些配置都会通过spring的配置完成。
2.4.3 创建日志文件log4j.xml
代码语言:javascript复制<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<param name="Encoding" value="UTF-8" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %d{MM-dd HH:mm:ss,SSS}
%m (%F:%L) n" />
</layout>
</appender>
<logger name="java.sql">
<level value="debug" />
</logger>
<logger name="org.apache.ibatis">
<level value="info" />
</logger>
<root>
<level value="debug" />
<appender-ref ref="STDOUT" />
</root>
</log4j:configuration>
2.5 创建Spring的配置文件并配置
在resources下创建spring.xml文件
代码语言:javascript复制<?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">
<!--扫描组件-->
<context:component-scan base-package="edu.hncj.ssm">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 引入jdbc.properties -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!-- 配置Druid数据源 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<!-- 配置用于创建SqlSessionFactory的工厂bean -->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 设置MyBatis配置文件的路径(可以不设置) -->
<property name="configLocation" value="classpath:mybatis-config.xml">
</property>
<!-- 设置数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 设置类型别名所对应的包 -->
<property name="typeAliasesPackage" value="edu.hncj.ssm.pojo">
</property>
<!--
设置映射文件的路径
若映射文件所在路径和mapper接口所在路径一致,则不需要设置
-->
<!--
<property name="mapperLocations" value="classpath:mapper/*.xml">
</property>
-->
</bean>
<!--
配置mapper接口的扫描配置
由mybatis-spring提供,可以将指定包下所有的mapper接口创建动态代理
并将这些动态代理作为IOC容器的bean管理
-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="edu.hncj.ssm.mapper"></property>
</bean>
</beans>
2.6 SSM整合测试
2.6.1 创建表
在ssm数据库下创建t_student表,见表语句如下:
代码语言:javascript复制CREATE TABLE `t_student` (
`stu_id` int(11) NOT NULL AUTO_INCREMENT,
`stu_name` varchar(20) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`sex` char(1) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
PRIMARY KEY (`stu_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
INSERT INTO `ssm`.`t_student`(`stu_id`, `stu_name`, `age`, `sex`, `email`) VALUES (100, '张三', 21, '男', '123@qq.com');
INSERT INTO `ssm`.`t_student`(`stu_id`, `stu_name`, `age`, `sex`, `email`) VALUES (101, '张4', 22, '男', '123@163.com');
INSERT INTO `ssm`.`t_student`(`stu_id`, `stu_name`, `age`, `sex`, `email`) VALUES (102, '张5', 22, '男', '123@126.com');
INSERT INTO `ssm`.`t_student`(`stu_id`, `stu_name`, `age`, `sex`, `email`) VALUES (103, '张6', 20, '男', '620@qq.com');
INSERT INTO `ssm`.`t_student`(`stu_id`, `stu_name`, `age`, `sex`, `email`) VALUES (104, '张7', 19, '女', '719@qq.com');
INSERT INTO `ssm`.`t_student`(`stu_id`, `stu_name`, `age`, `sex`, `email`) VALUES (105, '张8', 21, '男', '821@qq.com');
在数据库执行,结果如下:
2.6.2 创建实体类
创建Student类
代码语言:javascript复制package edu.hncj.ssm.pojo;
public class Student {
private Integer stuId;
private String stuName;
private Integer age;
private String sex;
private String email;
public Student() {
}
public Student(Integer stuId, String stuName, Integer age, String sex, String email) {
this.stuId = stuId;
this.stuName = stuName;
this.age = age;
this.sex = sex;
this.email = email;
}
public Integer getStuId() {
return stuId;
}
public void setStuId(Integer stuId) {
this.stuId = stuId;
}
public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "Student{"
"stuId=" stuId
", stuName='" stuName '''
", age=" age
", sex='" sex '''
", email='" email '''
'}';
}
}
2.6.3 创建Mapper接口和映射文件
在edu.hncj.ssm.mapper下创建StudentMapper接口:
代码语言:javascript复制package edu.hncj.ssm.mapper;
import edu.hncj.ssm.pojo.Student;
import java.util.List;
public interface StudentMapper {
// 返回所有的Student数据
List<Student> getStudentList();
}
在resources下的edu.hncj.ssm.mapper目录下创建 StudentMapper.xml文件,内容如下:
代码语言:javascript复制<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="edu.hncj.ssm.mapper.StudentMapper">
<!-- List<Student> getStudentList();-->
<select id="getStudentList" resultType="Student">
select * from t_student
</select>
</mapper>
2.6.4 创建service层接口和实现类
在edu.hncj.ssm.service下创建StudentService接口,代码如下:
代码语言:javascript复制package edu.hncj.ssm.service;
import edu.hncj.ssm.pojo.Student;
import java.util.List;
public interface StudentService {
// 返回所有student数据
List<Student> getStudentList();
}
在在edu.hncj.ssm.service.impl下创建StudentService接口的实现类StudentServiceImpl,代码如下:
代码语言:javascript复制package edu.hncj.ssm.service.impl;
import edu.hncj.ssm.mapper.StudentMapper;
import edu.hncj.ssm.pojo.Student;
import edu.hncj.ssm.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class StudentServiceImpl implements StudentService {
// 自动加载 StudentMapper
// 在spring.xml中的
// <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
// <property name="basePackage" value="edu.hncj.ssm.mapper"></property>
// </bean>
@Autowired
private StudentMapper studentMapper;
@Override
public List<Student> getStudentList() {
List<Student> studentList = studentMapper.getStudentList();
return studentList;
}
}
2.6.5 创建Controller层控制器
在edu.hncj.ssm.controller下创建StudentController类,代码如下:
代码语言:javascript复制package edu.hncj.ssm.controller;
import edu.hncj.ssm.pojo.Student;
import edu.hncj.ssm.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 org.springframework.web.bind.annotation.RequestMethod;
import java.util.List;
@Controller
public class StudentController {
@Autowired
private StudentService studentService;
@RequestMapping(value = "/student",method =
RequestMethod.GET)
public String getStudentList(Model model){
List<Student> list = studentService.getStudentList();
model.addAttribute("list",list);
return "student_list";
}
}
2.6.6 创建index.html
在src/main/webapp/WEB-INF目录下创建templates目录,在templates目录下创建index.html,内容如下:
代码语言:javascript复制<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>index.html</h1>
<a th:href="@{/student}">查询所有的学生信息</a>
<hr>
</body>
</html>
在springmvc.xml中配置了当访问根路径时,跳转到index.html页面。在该页面中有/student的请求,会跳转到student_list页面。
2.6.7 创建student_list页面
在templates目录下创建student_list.html,内容如下:
代码语言:javascript复制<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>学生列表</title>
</head>
<body>
<table>
<tr>
<th colspan="6">学生列表</th>
</tr>
<tr>
<th>序号</th>
<th>学生姓名</th>
<th>年龄</th>
<th>性别</th>
<th>邮箱</th>
<th>操作</th>
</tr>
<tr th:each="student,status : ${list}">
<td th:text="${status.count}"></td>
<td th:text="${student.stuName}"></td>
<td th:text="${student.age}"></td>
<td th:text="${student.sex}"></td>
<td th:text="${student.email}"></td>
<td>
<a href="">删除</a>
<a href="">修改</a>
</td>
</tr>
</table>
</body>
</html>
2.6.8 测试运行
运行此web项目,在浏览器端访问:
代码语言:javascript复制http://localhost:8080/chapter15
跳转到index.html页面,输出如下:
点击 查询所有的学生信息连接,跳转到studet_list.html页面,如下:
2.7 SSM整合总结
SSM整合的实现步骤如下: 0.创建数据库, 创建表 1.新建maven web项目 2.加入依赖 springmvc,spring,mybatis三个框架的依赖,jackson依赖,mysql驱动,druid连接池 jsp,servlet依赖