博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringMVC-@RequestParam
阅读量:6853 次
发布时间:2019-06-26

本文共 1392 字,大约阅读时间需要 4 分钟。

请求处理方法签名

 承接一二章

 

springmvc通过分析处理方法的签名,将http请求信息绑定到处理方法的相应参数中。并根据方法的返回质类型作出相应的后续处理。

必要时可以对其方法及方法参数标注相应的注解。如:@PathVariable @RequestParam @RequestHeader

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
Hello World hhhhhhhhh
可以传参数默认是必须的

test.java

package com.hdxy.domian;import java.lang.reflect.Method;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;/** * @author 流年拓荒者 * required=false :设置此参数是不是必须的。默认为turn *defaultValue="0"默认为0 */@RequestMapping("springMVC")@Controllerpublic class Test {   final public String SUCCESS="loginSuccess";     @RequestMapping(value="/testRest")   public String testRequestParam(@RequestParam(value="name") String un,@RequestParam(value="age")String age){       System.out.println("testRequestParam"+un+age);       return SUCCESS;   }      @RequestMapping(value="/testRest1")   public String testsRequestParam(@RequestParam(value="name") String un,@RequestParam(value="age",required=false,defaultValue="0")int age){       System.out.println("testRequestParam"+un+age);       return SUCCESS;   }}

 

转载于:https://www.cnblogs.com/lnthz/p/8024951.html

你可能感兴趣的文章
进程、应用程序域,线程和上下文之间的关系
查看>>
Spring源码学习之一下载和导入
查看>>
13.使用第三方类实现动画
查看>>
H5在js中向指定的元素添加样式
查看>>
本地通知,UILocalNotification
查看>>
分页---总结
查看>>
前端开发的历史和趋势(转摘阮一峰)
查看>>
Ubuntu 削减非 LTS 支持周期
查看>>
_实用的cms企业后台管理模板
查看>>
菜鸟看Redis(一)
查看>>
matplotlib.pyplot.plot()参数详解
查看>>
||PHP||关于=>和->以及::的用法
查看>>
最短路径问题
查看>>
Yii2中定义自己的Widget
查看>>
Aforge.net识别简易数字验证码问题
查看>>
JVM系列二:GC策略&内存申请、对象衰老
查看>>
MySQL 数据库备份策略:全备与增量备份
查看>>
Springboot的热部署
查看>>
Thinking in UML-1-为什么需要UML
查看>>
vs编译obj给delphi用
查看>>