springboot中的RESTful请求风格

注:如果同一个项目两种restful请求格式相同的话,会产生请求模糊异常。

package com.springboot.controller;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author dc
 * @date 2020/5/11 - 20:12
 */
@RestController
public class StudentController {

    /*这3种方法均为restful请求风格,形成2组对比
    * 1与2对比,1与3对比,1与2对比说明请求形式可区分restful
    * 1与3对比说明请求数据格式可区分restful*/

    @GetMapping("/student/detail/{id}/{age}")
    public Object doFirst(@PathVariable("id") Integer id,
                          @PathVariable("age") Integer age){
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("age", age);
        return map;
    }

    @PostMapping("/student/detail/{id}/{status}")
    public Object doSecond(@PathVariable("id") Integer id,
                          @PathVariable("status") Integer status){
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("status", status);
        return map;
    }

    @GetMapping("/student/{id}/detail/{city}")
    public Object doThird(@PathVariable("id") Integer id,
                          @PathVariable("city") Integer city){
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("city", city);
        return map;
    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值