@PathVariable和@RequestParam的区别

顾名思义, @PathVariable和@RequestParam,分别是从路径里面去获取变量,也就是把路径当做变量,后者是从请求里面获取参数。

1.@RequestParam :是从请求里面获取参数

请求的url: http://localhost:8080/jfly.openapi/pad/sulfuCheckInfoByMachineNo/v1?machineNo=ECCM001
其中"required = false" 是设置请求参数为非必须

@RequestMapping (value = "/sulfuCheckInfoByMachineNo/v1" , method = RequestMethod. GET )
@ResponseBody
public String I_MES_PAD_16( @RequestParam (value = "machineNo" , required = false ) String machineNo ) {
       if ( machineNo != null && ! "" .equals( machineNo )) {
            IPadService service = Application. getClassBean (IPadService. class );
            List<MesSulfuCheckInfo> infoList = service .findSulfuCheckInfoByMachineNo( machineNo );
             if ( infoList != null && ! infoList .isEmpty()) {
                   jsonString = JSONUtil. getJSONString ( new JSONData( infoList ));
            } else {
                   jsonString = JSONUtil. getErrorJSONString ( "未查询到该机台号硫化信息" );
            }
             return jsonString ;
      } else {
             jsonString = JSONUtil. getErrorJSONString ( "机台编号不能为空" );
             return jsonString ;
      }
}

2.@PathVariable :从路径里面去获取变量

请求的url: http://localhost:8080/jfly.openapi/pad/sulfuCheckInfoByMachineNo1/v1/ECCM001

@RequestMapping (value = "/sulfuCheckInfoByMachineNo1/v1/{machineNo}" , method = RequestMethod. GET )
@ResponseBody
public String I_MES_PAD_18( @PathVariable ( "machineNo" ) String machineNo ) {
       if ( machineNo != null && ! "" .equals( machineNo )) {
            IPadService service = Application. getClassBean (IPadService. class );
            List<MesSulfuCheckInfo> infoList = service .findSulfuCheckInfoByMachineNo( machineNo );
             if ( infoList != null && ! infoList .isEmpty()) {
                   jsonString = JSONUtil. getJSONString ( new JSONData( infoList ));
            } else {
                   jsonString = JSONUtil. getErrorJSONString ( "未查询到该机台号硫化信息" );
            }
             return jsonString ;
      } else {
             jsonString = JSONUtil. getErrorJSONString ( "机台编号不能为空" );
             return jsonString ;
      }
}

原文链接:https://blog.csdn.net/sinat_29774479/article/details/79697383

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值