Springboot學習筆記——處理url中的參數註解

@PathVariable

package com.test.demo;

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

@RestController
public class hello {
  /**
   *@author pxChen
   *@date 2019/6/11 10:56
   */
  @RequestMapping(value = "/test/{id}/{name}", method = RequestMethod.GET)
  public String say(@PathVariable("id") Integer id, @PathVariable("name") String name) {
    return "id:"+id+";name:"+name;
  }
}

@RequestParam

@RequestMapping(value = "/test", method = RequestMethod.GET)
public String msg(@RequestParam("name") String name, @RequestParam("msg") String msg) {
  return name+" say: "+msg;
}

@RequestBody(傳遞JSON數據)

@PostMapping("/show")
public String show(Person person) {
  return "id:"+person.getId()+";name:"+person.getName();
}

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