Spring MVC 自定义视图

实现View

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.View; @Component
public class HelloView implements View{ @Override
public String getContentType() {
return "text/html";
} @Override
public void render(Map<String, ?> model, HttpServletRequest request,
HttpServletResponse response) throws Exception {
response.getWriter().print("hello view, time: " + new Date());
} }

XML配置

  <!-- 配置视图  BeanNameViewResolver 解析器: 使用视图的名字来解析视图 -->
<!-- 通过 order 属性来定义视图解析器的优先级, order 值越小优先级越高 -->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver">
<property name="order" value=""></property>
</bean>

控制器

  @RequestMapping("/testView")
public String testView(){
System.out.println("testView");
return "helloView";
}
上一篇:Vim8.0在Debian下,normal模式的O命令出现延时


下一篇:Spring MVC的视图解析器