1.新建一个HelloView实现View
@Component
public class HelloView implements View{
@Override
public String getContentType() {
return "text/html";
}
@Override
public void render(Map<String, ?> arg0, HttpServletRequest request,
HttpServletResponse response) throws Exception {
response.getWriter().print("hello springmvc view");
}
}
2.在springmvc配置文件中添加
<!-- springmvc视图解析器 -->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver">
<property name="order" value="100"></property>
</bean>
3.解析自定义的类
@RequestMapping("/testView")
public String testView(){
System.out.println("测试springmvcview");
//返回的helloView对应的是HelloView类第一个字母小写
return "helloView";
}
4.最后在页面会输出:hello springmvc view