码迷,mamicode.com
首页 > 其他好文 > 详细

自定义视图

时间:2016-04-02 17:25:04      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!