我希望讓 Spring 使用正確的端點(diǎn),而不是為我的 Spring Boot Rest Controller 構(gòu)建 case 語句。我什至不確定這是否可能,但我希望宇宙能拯救我。 @PostMapping("/endpoint") public String one(Greeting greet) { return "Greeting Posted"; } @PostMapping("/endpoint") public String two(Address addr) { return "Address Posted"; }電流誤差Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'RController' method public java.lang.String com.example.controller.RController.two(com.example.model.Address)to {[/endpoint],methods=[POST]}: There is already 'RController' bean methodpublic java.lang.String com.example.controller.RController.one(com.example.model.Greeting) mapped.
2 回答

慕工程0101907
TA貢獻(xiàn)1887條經(jīng)驗(yàn) 獲得超5個(gè)贊
這是不是可能的。這是模棱兩可的。
作為一種很好的做法,如果 2 個(gè)資源將以不同的方式處理數(shù)據(jù),則必須為每個(gè)資源創(chuàng)建一個(gè)不同的端點(diǎn)。
或者可能的解決方法,它是創(chuàng)建一個(gè) ViewModel 對(duì)象并僅用一種方法處理它。
public class GreetingAddressVM {
private Address address;
private Greeting greeting;
}
我更喜歡為每個(gè)動(dòng)作創(chuàng)建不同的映射。
添加回答
舉報(bào)
0/150
提交
取消