springmvc无法解析视图前缀prefix_一文搞懂 Spring MVC

一、MVC 设计模式

MVC 模式代表 Model-View-Controller(模型-视图-控制器)

181adcd97c271deb25da1a398632b088.png

在实际的web开发过程中,简单粗暴的看法就是:

Model就是Entity类和相关DAO

Controller就是业务逻辑代码

View就是jsp页面

仔细分析一下这个设模式给我们带来的好处。web开发中,他最大的好处就是把用户所在的视图层和面向对象的模型、和具体的业务代码给分开了。MVC就是用这样一种解耦的方式。从JSP + servlet + javabean,到Struts2到spring MVC都是用了这一种设计模式。

甚至可以这样理解:在前后端分离的场景下,使用@RestController。JSON是服务器端MVC框架的V,是前端MVC框架的M

二、SpringMVC

而Spring Web MVC就是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦。

三、hello springMVC

新建web项目,并引入依赖,这里我直接用mven引的在web.xml中配置servlet为springMVC的DispatchcerServlet

<?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">        <servlet>        <servlet-name>springDispatcherServletservlet-name>        <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>                <init-param>            <param-name>contextConfigLocationparam-name>            <param-value>WEB-INF/applicationContext.xmlparam-value>        init-param>                <load-on-startup>1load-on-startup>    servlet>    <servlet-mapping>        <servlet-name>springDispatcherServletservlet-name>        <url-pattern>/url-pattern>    servlet-mapping>web-app>

配置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"       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-4.0.xsd        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">        <context:component-scan base-package="com.gwsssi.springmvc">context:component-scan>     
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值