自定义视图
Posted seven_hu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自定义视图相关的知识,希望对你有一定的参考价值。
package com.seven.views; import org.springframework.stereotype.Component; import org.springframework.web.servlet.View; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Date; import java.util.Map; /** * Created by hu on 2016/4/2. */ //必须添加@Component,这样SpringMvc才会感知这个View @Component public class HelloView implements View { @Override public String getContentType() { return "text/html"; } @Override public void render(Map<String, ?> map, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { httpServletResponse.getWriter().print("hello view,time: "+new Date()); } }
package com.seven.demos; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; /** * Created by hu on 2016/4/2. */ @Controller @RequestMapping("/SpringMvcTest2") public class SpringMvcTest2 { @RequestMapping("/helloView") public String getHelloView(){ System.out.println("enter"); return "helloView"; } }
以上是关于自定义视图的主要内容,如果未能解决你的问题,请参考以下文章