SpringMVC中的参数怎么利用注解获取?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

SpringMVC可以通过RequestParam注解来映射获得参数,具体用法如下:

例子:
配置过程省略
1.新建controller类
package com.loger.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class RequestParam {
public static final String SUCCESS = "success";
@RequestMapping(value="/requestparam")
public String requestParam(@org.springframework.web.bind.annotation.
RequestParam(value="username") String un,
@org.springframework.web.bind.annotation.RequestParam(value="age") Integer age){
System.out.println(un + " " + age);
return SUCCESS;
}
}