SpringMVC配置

本文介绍了SpringMVC的基本配置,包括需要导入的jar包,创建Controller类,SpringMVC配置,如添加约束和注册处理器。强调了注解式开发的重点,如创建非继承Controller的类和组件扫描器的配置。同时,文章解决了配置过程中遇到的静态资源加载问题,提供了多种解决方案。
摘要由CSDN通过智能技术生成

SpringMVC:也叫Spring web mvc,属于表现层框架。SpringMVC是Spring框架的一部分,是在Spring3.0后发布的。

在这里插入图片描述
由以上Spring的结构图可以看出,Spring由四大部分组成:Dao部分(DAO与ORM)、AOP部分、Web部分(JEE与Web),及loC容器部分(Core)。

1.需要导入的jar包

在这里插入图片描述
Spring-context-support:包含支持UI模板,邮件服务,缓存Cache等方面的类。
Spring-webmvc:对SpringMVC的实现。

Spring Frame 4.3.8源码下载地址:https://repo.spring.io/webapp/#/artifacts/browse/tree/General/libs-release-local/org/springframework/spring/4.3.8.RELEASE/spring-framework-4.3.8.RELEASE-dist.zip

2.创建一个controller类,实现Controller接口

public class MyController implements Controller {

	@Override
	public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
		ModelAndView mv = new ModelAndView();
		//其底层执行的是request.setAttribute()方法
		mv.addObject("message", "Hello SpringMVC world!");
		mv.setViewName("welcome");
		return mv;
	}

}

这里是随意写的类,需要配置注册才能使其生效。=>在spring配置文件中注册。

3.SpringMCV配置

  • 添加约束
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://www.springframework.org/schema/beans"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:tool="http://www.springframework.org/schema/tool"
	xmlns:tx="http://www.springframework.org/schema/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值