------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------
视图解析器------默认就有配置,但是默认的在实际使用过程中有很多不方便的地方,所以我们配置一道视图解析器
在自己的配置文件xml中,配一个bean节点
<!--视图解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!--前--> <property name="prefix" value="/"></property> <!--后--> <property name="suffix" value=".jsp"></property> </bean>
在自定义的处理器中就可以省略/和.jsp的写法
package cn.dawn.day02viewResolver; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Created by Dawn on 2018/3/19. */ //处理器 public class FirstController implements Controller { /** * handleRequest 处理请求 * @param httpServletRequest * @param httpServletResponse * @return * @throws Exception */ public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { ModelAndView me=new ModelAndView(); //因为视图解析器已经把前后所要写的/和.jsp写了,此处的index就代表/index.jsp me.setViewName("index"); return me; } }