博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringMVC-@RequestParam
阅读量:6852 次
发布时间: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

你可能感兴趣的文章
C#中 @ 的3种用途
查看>>
模板方法模式(Template Pattern)
查看>>
Instr() 函数
查看>>
hdu-acm steps Max sum
查看>>
Radar Installation
查看>>
组队项目四则运算成果
查看>>
使用UIPickerView显示数据
查看>>
java代码继承基础
查看>>
java继承实例基础
查看>>
数据库增删改查梳理
查看>>
linux下检测每个进程占用swap大小
查看>>
[转] 编译输出文件的区别
查看>>
Java MyBatis 插入数据库返回主键--insertSelective这样就不用每次到数据库里面查询了...
查看>>
springboot集成redis操作
查看>>
x64 QWORD Xor shellcode encoder
查看>>
大数据之mapreduce小实战
查看>>
Elasticsearch(二)
查看>>
一步一步学linq to sql(九)其他补充
查看>>
windows service and process 的关系
查看>>
转 Oracle 12C 之 CDB/PDB用户的创建与对象管理
查看>>