注解映射器适配器编写handle

来源:互联网 发布:数据库数据抓取 编辑:程序博客网 时间:2024/06/05 22:41

springmvc 配置映射器与适配器

<mvc:annotation-driven/>使用MVC注解驱动加载 适配器与映射器

使用注解驱动的同时还会添加了好多MVC参数绑定方法比如json转换器

添加bean 

使用<bean class="springmvc.copy.Controller">来添加controller

但是单个controler添加比较麻烦

生产环境下我们使用以下组件来自动扫描controller坐在包目录下的所有controller类

<context:component-scan base-package="springmvc.copy"/>


编写 controler


package springmvc.copy;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.servlet.ModelAndView;

//使用注解标记这个类是控制器

@Controller

public class Controls {

//使用注解对url以及方法进行映射

@RequestMapping("index")

public ModelAndView quers() throws Exception {

ModelAndView andView = new ModelAndView();

andView.setViewName("newmod");

return andView;

}

}


视图解析器前缀后缀的配置



测试



0 0