注解映射器适配器编写handle

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;

}

}


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


测试


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容