controller配置汇总
来源:互联网 发布:剑三男捏脸数据 编辑:程序博客网 时间:2024/06/06 01:31
1.通过URL对应Bean
<pre name="code" class="html"><!-- 配置HandlerMapping 根据beanname找对对应的controller -->
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean> <!-- 配置handleradapter --> <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean>
<span style="white-space:pre"></span><!-- 配置controller --> <bean name="/hello.do" class="cn.com.jit.controller.HelloController"/>以上配置访问/hello.do就会寻找ID为/hello.do的Bean,此类方式仅使用小型应用系统
2.为URL分配Bean
使用一个统一配置集合,对各个URL对应的Controller做关系映射
<!-- 最常用的 -->
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <!-- key 对应URL请求名 value 对应处理器的ID--> <prop key="/hello.do">hellocontroller</prop> </props> </property> </bean> <bean id="hellocontroller" class="cn.com.jit.controller.HelloController"></bean>此类配置还可以使用通配符,访问/hello.do时,Spring会把请求分配给helloController进行处理。
3.URL匹配Bean
如果定义的Conroller名称规范,也可以使用如下配置
<!-- 将hello*.do交给helloController去处理 -->
<!-- 配置HandlerMapping 根据beanname找对对应的controller --> <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> <!-- 配置controller 请求为hello*.do都将会被匹配 --> <bean name="/helloController" class="cn.com.jit.controller.HelloController"/>
4注解
<!-- 配置springMVC 注解驱动 --> <mvc:annotation-driven/> <!-- 扫描器 --> <context:component-scan base-package="cn"></context:component-scan>在controller中添加注解:
@Controller@RequestMapping("/user")public class UserController {/** * 时间编辑器 */ @InitBinder public void initBinder(ServletRequestDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }@RequestMapping("/add1.do")public String add(HttpServletRequest request){String username = request.getParameter("username");String password = request.getParameter("password");System.out.println("username:" + username + "---" + "password:" + password);return "user/user_list";}@RequestMapping("/add2.do")public String add2(String username, String password ){System.out.println("username:" + username + "-----" + "password:" + password);return "user/user_list";}@RequestMapping("/add3.do")public String add3(UserInfo userInfo){System.out.println(userInfo);return "user/user_list";}@RequestMapping("/add4.do")public String add4(String userName, Date date){System.out.println("username:" + userName + "---" + "date:" + date);return "user/user_list";}}
0 0
- controller配置汇总
- 第二讲 Controller配置汇总
- SpringMVC扫描controller配置
- SpringMVC的配置--controller
- springMVC----controller配置总结
- controller配置总结
- 【CAS】自定义Controller配置
- [LR]Controller配置
- Struts2 首页action/controller配置
- Spring MVC Controller配置方式
- Spring MVC Controller配置方式
- Spring MVC Controller配置方式
- Spring MVC Controller配置方式
- 入门程序以及Controller配置
- restful controller response header 配置
- ModelAndView 配置后,controller方法
- SpringMVC Controller的配置方式
- spring 配置controller返回json
- 10815 - Andy's First Dictionary
- HDU2059 多段决策
- Eclipse将引用了第三方jar包的Java项目打包成jar文件的两种方法
- web基础 Web.xml配置详解
- apt-get update与ssh server服务安装
- controller配置汇总
- Android studio使用问题收录
- [数据结构]链表的基本操作
- iOS开发网络篇—网络编程基础
- 设置Myeclipse中的代码格式化、注释模板及保存时自动格式化
- 写论文第九天:MATLAB之rsindex函数
- UML类图符号
- 信息的表示
- iOS开发网络篇—搭建本地服务器