Spring Mvc 之 注解式开发详解

来源:互联网 发布:linux服务器性能监控 编辑:程序博客网 时间:2024/05/21 17:43
 首先,创建类 helloAnntation。
package cn.happy.controller02anntation;
import org.springframework.stereotype.Component;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import javax.annotation.Resource;/** * Created by lenovo on 2017/8/18. */@Controller@RequestMapping("")public class HelloAnntation {    @RequestMapping("/first")    public String doFirst(){        return "/WEB-INF/insert.jsp";    }    @RequestMapping("/second")    public String doSecond(){        return  "/WEB-INF/insert.jsp";    }}


此类当中 需要的注解 @ Controller 、    @ResutMapping  



其次,在resources中配置spring相对应得xml文件。  这其中只需要 一个包扫描器 。



当访问页面时,在url中 使用first 亦或second 即可。