Spring MVC【入门】就这一篇!

https://www.jianshu.com/p/91a2d0a1e45a

SpringMVC非注解方式和注解方式不能同时使用。注解方式只需要配一句话就行了dispatcher-servlet.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">

<!-- 扫描controller下的组件 当我加载配置文件时,到我们指定的包下扫描(读取)java文件,寻找标注注解的地方(接口,类,方法或者其他),进行完成初始化。-->
<context:component-scan base-package="controller"/>

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>

Spring MVC返回ModelAndView,视图解析器找不到jsp

是包引入错误而导致的: 
import org.springframework.web.portlet.ModelAndView;——错误的包 
import org.springframework.web.servlet.ModelAndView;——正确的包

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄