SSM整合篇】三. SSM整合+事务+单元测试案例 完结 (共四章)

2024-03-28 18:32

本文主要是介绍SSM整合篇】三. SSM整合+事务+单元测试案例 完结 (共四章),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Spring+SpringMvc+MyBatis整合+事务+单元测试案例 第四章

github源码(day56-ssm-transaction)https://github.com/1196557363/ideaMavenProject

对一些知识点不懂可以参考 SSM整合篇】一. Spring+SpringMvc+MyBatis简单案例

该案例接上章【SSM整合篇】三. SSM整合+事务+单元测试案例 第三章 (共四章)

8 Spring和SpringMVC整合

8.1 定义Controller

package com.wpj.web.controller;import org.springframework.stereotype.*;/*** ClassName: Controller* Description:** @author JieKaMi* @version 1.0* @date: 2020\1\8 0008 21:55* @since JDK 1.8*/
@Controller
@RequestMapping("/emp")
public class EmpController {}

8.2 创建springmvc.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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd"><!-- 开启包扫描--><context:component-scan base-package="com.wpj" use-default-filters="false"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><!-- 开启注解驱动--><mvc:annotation-driven/><!-- 配置thymeleaf的视图解析器--><bean id="templateResolver"class="org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver"> <!--前缀配置--><property name="prefix" value="/"></property> <!--后缀配置--><property name="suffix" value=".html"></property> <!--模板类型--><property name="templateMode" value="HTML"></property> <!--不使用缓存--><property name="cacheable" value="false"></property> <!--编码类型--><property name="characterEncoding" value="UTF-8"></property></bean><!--模板引擎配置--><bean id="templateEngine" class="org.thymeleaf.spring5.SpringTemplateEngine"><property name="templateResolver" ref="templateResolver"></property></bean><!--视图处理器--><bean class="org.thymeleaf.spring5.view.ThymeleafViewResolver"><property name="templateEngine" ref="templateEngine"></property><property name="characterEncoding" value="UTF-8"></property></bean><!-- 静态资源文件处理--><mvc:default-servlet-handler/></beans>

8.3 配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"version="2.5"><display-name>Archetype Created Web Application</display-name><!-- Filter--><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></filter><filter-mapping><filter-name>CharacterEncodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!-- lsiteneter--><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring-context.xml</param-value></context-param><!-- 在Tomcat启动的时候初始化Spring容器--><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- Servlet--><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.xml</param-value></init-param><!-- 优先级--><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>DispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping>
</web-app>

8.4 Controller写映射路径

package com.wpj.web.controller;import com.wpj.bean.*;
import com.wpj.service.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.stereotype.*;
import org.springframework.ui.*;
import org.springframework.web.bind.annotation.*;import java.util.*;/*** ClassName: Controller* Description:** @author JieKaMi* @version 1.0* @date: 2020\1\8 0008 21:55* @since JDK 1.8*/
@Controller
@RequestMapping("/emp")
public class EmpController {@Autowiredprivate IEmpService iEmpService;@RequestMapping("/getAllEmp")public String getAllEmp(ModelMap map){List<Emp> empList = iEmpService.getAllEmp();map.put("empList",empList);return "list";}
}

8.5 运行

http://localhost:8080/emp/getAllEmpemp ⇒   controller映射路径getAllEmp ⇒  controller内定义方法映射路径

8.6 结果

在这里插入图片描述

8.6.1 ssm整合成功。

这篇关于SSM整合篇】三. SSM整合+事务+单元测试案例 完结 (共四章)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/856380

相关文章

SpringBoot整合Dubbo+ZK注册失败的坑及解决

《SpringBoot整合Dubbo+ZK注册失败的坑及解决》使用Dubbo框架时,需在公共pom添加依赖,启动类加@EnableDubbo,实现类用@DubboService替代@Service,配... 目录1.先看下公共的pom(maven创建的pom工程)2.启动类上加@EnableDubbo3.实

SpringBoot整合(ES)ElasticSearch7.8实践

《SpringBoot整合(ES)ElasticSearch7.8实践》本文详细介绍了SpringBoot整合ElasticSearch7.8的教程,涵盖依赖添加、客户端初始化、索引创建与获取、批量插... 目录SpringBoot整合ElasticSearch7.8添加依赖初始化创建SpringBoot项

MySql基本查询之表的增删查改+聚合函数案例详解

《MySql基本查询之表的增删查改+聚合函数案例详解》本文详解SQL的CURD操作INSERT用于数据插入(单行/多行及冲突处理),SELECT实现数据检索(列选择、条件过滤、排序分页),UPDATE... 目录一、Create1.1 单行数据 + 全列插入1.2 多行数据 + 指定列插入1.3 插入否则更

SpringSecurity整合redission序列化问题小结(最新整理)

《SpringSecurity整合redission序列化问题小结(最新整理)》文章详解SpringSecurity整合Redisson时的序列化问题,指出需排除官方Jackson依赖,通过自定义反序... 目录1. 前言2. Redission配置2.1 RedissonProperties2.2 Red

Spring boot整合dubbo+zookeeper的详细过程

《Springboot整合dubbo+zookeeper的详细过程》本文讲解SpringBoot整合Dubbo与Zookeeper实现API、Provider、Consumer模式,包含依赖配置、... 目录Spring boot整合dubbo+zookeeper1.创建父工程2.父工程引入依赖3.创建ap

SpringBoot3.X 整合 MinIO 存储原生方案

《SpringBoot3.X整合MinIO存储原生方案》本文详细介绍了SpringBoot3.X整合MinIO的原生方案,从环境搭建到核心功能实现,涵盖了文件上传、下载、删除等常用操作,并补充了... 目录SpringBoot3.X整合MinIO存储原生方案:从环境搭建到实战开发一、前言:为什么选择MinI

Python通用唯一标识符模块uuid使用案例详解

《Python通用唯一标识符模块uuid使用案例详解》Pythonuuid模块用于生成128位全局唯一标识符,支持UUID1-5版本,适用于分布式系统、数据库主键等场景,需注意隐私、碰撞概率及存储优... 目录简介核心功能1. UUID版本2. UUID属性3. 命名空间使用场景1. 生成唯一标识符2. 数

PostgreSQL的扩展dict_int应用案例解析

《PostgreSQL的扩展dict_int应用案例解析》dict_int扩展为PostgreSQL提供了专业的整数文本处理能力,特别适合需要精确处理数字内容的搜索场景,本文给大家介绍PostgreS... 目录PostgreSQL的扩展dict_int一、扩展概述二、核心功能三、安装与启用四、字典配置方法

Spring事务传播机制最佳实践

《Spring事务传播机制最佳实践》Spring的事务传播机制为我们提供了优雅的解决方案,本文将带您深入理解这一机制,掌握不同场景下的最佳实践,感兴趣的朋友一起看看吧... 目录1. 什么是事务传播行为2. Spring支持的七种事务传播行为2.1 REQUIRED(默认)2.2 SUPPORTS2

SpringBoot整合liteflow的详细过程

《SpringBoot整合liteflow的详细过程》:本文主要介绍SpringBoot整合liteflow的详细过程,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋...  liteflow 是什么? 能做什么?总之一句话:能帮你规范写代码逻辑 ,编排并解耦业务逻辑,代码