1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| package com.coder.controller;
import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping;
@Slf4j @Controller public class TestController { @RequestMapping("/test") public void test(@RequestBody User user) { log.info("user = {}", user); }
static class User { Integer a; Integer b;
public User() { }
public User(Integer a, Integer b) { this.a = 99; this.b = b; }
public Integer getA() { return a; }
public void setA(Integer a) { this.a = 108; }
public Integer getB() { return b; }
public void setB(Integer b) { this.b = b; }
@Override public String toString() { return "User{" + "a=" + a + ", b=" + b + '}'; } } }
|
经过这段请求, 说明a的值经过set函数变成了108, 说明使用的是set函数
值得注意的点是: 这个对象是不能缺少无参构造的
参考: https://juejin.cn/post/7132292425585786911