标签:
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"; } }
标签:
原文地址:http://www.cnblogs.com/hujingwei/p/5347727.html