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;
  }
}

Springboot学习笔记——处理url中的参数注解_第1张图片

@RequestParam

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

Springboot学习笔记——处理url中的参数注解_第2张图片

@RequestBody(传递JSON数据)

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

Springboot学习笔记——处理url中的参数注解_第3张图片

Springboot学习笔记——处理url中的参数注解_第4张图片

你可能感兴趣的:(SpringBoot)