springmvc中的注解

@Value注入Properties数据

-------------------------------------------------------------------------------

@PathVariable是用来获得请求url中的动态参数的

----------------------------------------------------------------------------------------------

要返回json数据要使用@ResponseBody
------------------------------------------------------------------------------------
public String queryUserName(@RequestParam String userName)
请求中包含username参数(如/requestparam1?userName=zhang),则自动传入。
value:参数名字,即入参的请求参数名字,如username表示请求的参数区中的名字为username的参数的值将传入;
defaultValue:默认值,表示如果请求中没有同名参数时的默认值

public String requestparam5(  @RequestParam(value="username", required=true, defaultValue="zhangsan") String username)

如果没有传入参数,则默认是"zhangsan".

-------------------------------------------------------------------------------------------------------

javax.inject中@Inject、@Named、@Qualifier和@Provider用法

-------------------------------------------------------------------------------------------------------

 

consumes: 指定处理请求的提交内容类型(Content-Type),例如application/json, text/html;
produces: 指定返回的内容类型,仅当request请求头中的(Accept)类型中包含该指定类型才返回;
------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

//定义两个路径
@RequestMapping(path  ={"/","/index"})
@ResponseBody
public String index(){
    return "Hello reed";
}

http://localhost:8080/  和http://localhost:8080/index的效果一样

 

---------------------------------------------------------------------------------------------------------------

 

//@PathVarible,@RequestParam,defaultValue,required的用法
@RequestMapping(path = {"profile/{groupId}/{userId}"})
@ResponseBody
public String profile(@PathVariable("userId") int userId, @PathVariable("groupId") String groupId,
                      @RequestParam(value = "type",defaultValue = "1") int type,
                      @RequestParam(value = "key",required = false) String key){
    return String.format("profile %s/%d,t:%d k:%s",groupId,userId,type,key);
}
//http://localhost:8080/profile/1/1?type=2&key=reed    profile 1/1,t:2 k:reed
//http://localhost:8080/profile/1/1?key=reed   profile 1/1,t:1 k:reed
//http://localhost:8080/profile/1/1     profile 1/1,t:1 k:null

 

 

 

@PathVarible取路径中的参数做为变量参数

?后面那种带参可以用@RequestParam

defaultValue用来设置默认值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值