springboot的RESTFull開發

@PathVariable

獲取url中的數據

該註解是實現RESTFull最主要的一個註解

eg:

package com.example.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * restfull
 */
@RestController
public class RESTFullController {
    //訪問地址http://localhost:8080//boot/restfullstudent/id/status
    @RequestMapping("/boot/restfullstudent/{id}/{status}")
    public Object  restfullstudent(@PathVariable("id") Integer id,@PathVariable("status") Integer status){
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("id",id);
        map.put("status",status);
        return map;
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章