Spring整合SpringMVC

目录

【pom.xml】文件;

新建【applicationContext.xml】文件

新建【springmvc.xml】文件;

配置【src/main/webapp/WEB-INF/web.xml】文件;

新建【com.gupaoedu.service.IUserService】;

新建【com.gupaoedu.service.impl.UserServiceImpl】;

新建【com.gupaoedu.controller.UserController】;


pom.xml文件;

<?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>com.gupaoedu</groupId><artifactId>springmvc_demo_03</artifactId><version>1.0-SNAPSHOT</version><packaging>war</packaging><name>springmvc_demo_03 Maven Webapp</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><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></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>4.3.1.RELEASE</version></dependency></dependencies><build><finalName>springmvc_demo_03</finalName><pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --><plugins><plugin><artifactId>maven-clean-plugin</artifactId><version>3.1.0</version></plugin><!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --><plugin><artifactId>maven-resources-plugin</artifactId><version>3.0.2</version></plugin><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.8.0</version></plugin><plugin><artifactId>maven-surefire-plugin</artifactId><version>2.22.1</version></plugin><plugin><artifactId>maven-war-plugin</artifactId><version>3.2.2</version></plugin><plugin><artifactId>maven-install-plugin</artifactId><version>2.5.2</version></plugin><plugin><artifactId>maven-deploy-plugin</artifactId><version>2.8.2</version></plugin></plugins></pluginManagement><plugins><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><version>2.2</version><configuration><port>8080</port> <!-- 访问端口 --><path>/</path>    <!-- 访问路径 --></configuration></plugin></plugins></build>
</project>

新建【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 http://www.springframework.org/schema/context/spring-context.xsd"><!-- 添加扫描 --><context:component-scan base-package="com.gupao.edu" use-default-filters="true"><context:exclude-filter type="annotation"expression="org.springframework.stereotype.Controller"/></context:component-scan>
</beans>

新建【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/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"><!-- 添加扫描 --><context:component-scan base-package="com.gupao.edu"use-default-filters="false"><context:include-filter type="annotation"expression="org.springframework.stereotype.Controller"/></context:component-scan><!-- 开启注解--><mvc:annotation-driven/>
</beans>

配置【src/main/webapp/WEB-INF/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><!-- 配置Spring --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- 配置SpringMVC --><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 关联SpringMVC的配置文件 --><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping>
</web-app>

新建【com.gupaoedu.service.IUserService】;

package com.gupaoedu.service;public interface IUserService {public String hello();}

新建【com.gupaoedu.service.impl.UserServiceImpl】;


import com.gupaoedu.service.IUserService;
import org.springframework.stereotype.Service;@Service
public class UserServiceImpl implements IUserService {@Overridepublic String hello() {return "hello Service ... ... ";}
}

新建【com.gupaoedu.controller.UserController】;

package com.gupaoedu.controller;import com.gupaoedu.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class UserController {@Autowiredprivate IUserService userService;@GetMapping("/user/hello")public String hello() {return userService.hello();}}

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【数据结构-堆】2233. K 次增加后的最大乘积

给你一个非负整数数组 nums 和一个整数 k 。每次操作&#xff0c;你可以选择 nums 中 任一 元素并将它 增加 1 。 请你返回 至多 k 次操作后&#xff0c;能得到的 nums的 最大乘积 。由于答案可能很大&#xff0c;请你将答案对 109 7 取余后返回。 示例 1&#xff1a; 输入&…

2025.1.8(c++对c语言的扩充——堆区空间,引用,函数)

笔记 上一笔记接续&#xff08;练习2的答案&#xff09; 练习&#xff1a;要求在堆区连续申请5个int的大小空间用于存储5名学生的成绩&#xff0c;分别完成空间的申请、成绩的录入、升序排序、成绩输出函数以及空间释放函数&#xff0c;并在主程序中完成测试 要求使用new和d…

(长期更新)《零基础入门 ArcGIS(ArcScene) 》实验七----城市三维建模与分析(超超超详细!!!)

城市三维建模与分析 三维城市模型已经成为一种非常普遍的地理空间数据资源,成为城市的必需品,对城市能化管理至关重要。语义信息丰富的三维城市模型可以有效实现不同领域数据与IS相信息的高层次集成及互操作,从而在城市规划、环境模拟、应急响应和辅助决策等众多领域公挥作用、…

在离线环境中安装 `.rpm` 包的步骤

在一些环境中&#xff0c;可能无法直接通过网络安装软件包。特别是在没有互联网连接的情况下&#xff0c;我们仍然可以手动下载 .rpm 安装包并进行离线安装。本文将介绍如何在离线环境中安装多个 .rpm 包&#xff0c;确保软件的顺利安装和依赖关系的处理。 1. 将 .rpm 文件复制…

【人工智能开题报告】

人工智能开题报告 第一步 12 篇文献 应用&#xff08;研究&#xff09;领域历史、现状、发展趋势以及对社会、环境、健康、安全等方面的影响分析第二步 15篇 应用&#xff08;研究&#xff09;领域中的 工作成果简述2.1 国外 6篇2.2 国内 9篇 第三步 9/10篇 研究方案 的分析与选…

Harmony开发【笔记1】报错解决(字段名写错了。。)

在利用axios从网络接收请求时&#xff0c;发现返回obj的code为“-1”&#xff0c;非常不解&#xff0c;利用console.log测试&#xff0c;更加不解&#xff0c;可知抛出错误是 “ E 其他错误: userName required”。但是我在测试时&#xff0c;它并没有体现为空&#xff0c;…

(2023|NIPS,LLaVA-Med,生物医学 VLM,GPT-4 生成自指导指令跟随数据集,数据对齐,指令调优)

LLaVA-Med: Training a Large Language-and-Vision Assistant for Biomedicine in One Day 目录 LLaVA-Med: Training a Large Language-and-Vision Assistant for Biomedicine in One Day 0. 摘要 1. 简介 2. 相关工作 3. 生物医学视觉指令数据 4. 将多模态对话模型适配…

什么是网络安全攻防演练,即红蓝对抗?

定义与目的 定义&#xff1a;网络安全攻防演练是一种模拟真实网络攻击和防御场景的活动&#xff0c;通过组织专业的攻击队伍&#xff08;红队&#xff09;和防御队伍&#xff08;蓝队&#xff09;进行对抗&#xff0c;来检验和提升组织的网络安全防御能力、应急响应能力和安全运…

(概率论)无偏估计

参考文章&#xff1a;(15 封私信 / 51 条消息) 什么是无偏估计&#xff1f; - 知乎 (zhihu.com) 首先&#xff0c;第一个回答中&#xff0c;马同学图解数学讲解得很形象&#xff0c; 我的概括是&#xff1a;“注意&#xff0c;有一个总体的均值u。然后&#xff0c;如果抽样n个&…

国产游戏崛起,燕云十六移动端1.9上线,ToDesk云电脑先开玩

游戏爱好者的利好消息出新了&#xff01;网易大型武侠仙游《燕云十六声》正式官宣&#xff0c;移动端要在1月9日正式上线了&#xff01;你期待手游版的燕云吗&#xff1f;不妨评论区留言说说你的看法。小编分别花了几个小时在台式机电脑和手机上都试了下&#xff0c;欣赏画面还…

一文大白话讲清楚ES6代理Proxy和反射Reflect

文章目录 一文大白话讲清楚ES6代理Proxy和反射Reflect1. 你当过老板么2.代理Proxy2.1 get(target,propKey,receiver)//获取对象的属性2.2 set(target,propKey,newValue,receiver)//设置属性的值2.3 has(target,propKey)//代理查询属性操作&#xff0c;propKey in obj的操作2.4 …

VS2022引入sqlite数据库交互

法一&#xff1a;用官网编译好的动态库(推荐) 下载所需文件 sqlite官网地址&#xff1a;https://www.sqlite.org/howtocompile.html 下载以下的2个压缩包 第一个压缩包 sqlite-amalgamation-xxxx.zip&#xff0c;xxxx是版本号,保持一致即可&#xff0c;这里面有sqite3.h 第…

Java后端常用的4种请求方式(通俗易懂)

文章目录 前言通用接口类(ControllerDemo)通用实体类(UserEntity)通用响应类(HttpClientResult)成功截图(先启动项目,然后右键执行main方法) HttpClientHttpClient 的主要类代码案例导入依赖工具类(HttpClientUtil)测试类 HttpURLConnection简介调用步骤代码案例导入依赖工具类…

STM32烧写失败之Contents mismatch at: 0800005CH (Flash=FFH Required=29H) !

一&#xff09;问题&#xff1a;用ULINK2给STM32F103C8T6下载程序&#xff0c;下载方式设置如下&#xff1a; 出现下面两个问题&#xff1a; 1&#xff09;下载问题界面如下&#xff1a; 这个错误的信息大概可以理解为&#xff0c;在0x08000063地址上读取到flash存储为FF&am…

Dynamic-Datasource 文档

dynamic-datasource-spring-boot-starter是一个基于springboot的快速集成多数据源的启动器。 特性 支持数据源分组&#xff0c;适用于多种场景&#xff0c;纯粹多库、读写分离、一主多从、混合模式。支持数据库敏感配置信息加密(可自定义)ENC()。支持每个数据库独立初始化表结…

P10424 [蓝桥杯 2024 省 B] 好数

题目描述 一个整数如果按从低位到高位的顺序&#xff0c;奇数位&#xff08;个位、百位、万位……&#xff09;上的数字是奇数&#xff0c;偶数位&#xff08;十位、千位、十万位……&#xff09;上的数字是偶数&#xff0c;我们就称之为“好数”。 给定一个正整数 N&#xf…

Spring Boot教程之五十二:CrudRepository 和 JpaRepository 之间的区别

Spring Boot – CrudRepository 和 JpaRepository 之间的区别 Spring Boot建立在 Spring 之上&#xff0c;包含 Spring 的所有功能。由于其快速的生产就绪环境&#xff0c;使开发人员能够直接专注于逻辑&#xff0c;而不必费力配置和设置&#xff0c;因此如今它正成为开发人员…

LLM的MoE由什么构成:门控网络,专家网络

LLM的MoE由什么构成:门控网络,专家网络 目录 LLM的MoE由什么构成:门控网络,专家网络专家网络门控网络MoE在联邦学习中的使用及原理专家网络 定义与特点:是一组独立的模型,每个模型都负责处理某个特定的子任务或学习输入空间的特定部分。这些专家可以是简单的线性回归模型…

DeepSeek-V3与GPT-4o的对比详解

DeepSeek-V3&#xff0c;作为一款引人注目的开源大型语言模型&#xff0c;自其诞生以来&#xff0c;便以卓越的性能和高效的性价比&#xff0c;在AI界掀起了一股新的浪潮。本文将详细介绍DeepSeek-V3的诞生背景、技术优势&#xff0c;以及与顶尖闭源模型GPT-4o的对比&#xff0…

Mysql 性能优化:覆盖索引

概述 覆盖索引&#xff08;Covering Index&#xff09;是一个 MySQL 查询优化技术&#xff0c;它指的是一个索引包含了查询所需的所有字段的数据&#xff0c;因此不需要回表&#xff08;访问数据表的行&#xff09;就可以完成查询。使用覆盖索引可以显著提高查询性能&#xff…