さらに面倒なく、コードに直接移動
package com.mcgx;
public class Data {
private String sign;
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
}
package com.mcgx;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class,args);
}
@RequestMapping("test")
public String test(Data data){
System.out.println(data.getSign());
return "OK";
}
}
テストインターフェースのDataエンティティクラスを介して渡された属性を受け取ります。パラメーターテストを見てみましょう。signまたはSignに渡すことができます。
SIgnに渡されましたが、許可されていません
それは少し不思議です、なぜですか?
Springがオブジェクトにパラメーターを注入するとき、それはsetメソッドを通じて注入され、パラメーターはgetを通じて取得されることがわかっています。
賢いクラスメートは、この文が表示されたときにこの文を推測する必要があります。上記のパラメータを渡すと、それがsignかsignか、
注入はsetSignメソッドを介して行われるため、ここで大文字を使用できます。
ただし、渡すパラメーターがSIgnの場合、setSIgnメソッドがないので恥ずかしいので注入できず、質疑応答は終了します。