我有兩個類A
& B
它們正在實現一個接口。在彈簧控制器方法參數中使用接口
public class A implements MyInterface {
// Class A stuff
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class B implements MyInterface {
//Class B stuff
private MyCustomClass myCustomclass;
public String getName() {
this.myCustomclass.getName();
}
}
public interface MyInterface {
public String getName();
}
我想要使用一個控制器方法,它可以在A和B上工作,具體取決於前端發送的對象。所以當我嘗試使用Interface時,Spring並沒有發現合適的消息轉換器。
@RequestMapping(value = "/mymethod", method = RequestMethod.POST) public String updateRecord(@RequestBody MyInterface myInterface, HttpServletResponse response) { //Do stuff }
可以添加A和B類的整體嗎? –
已添加。如果您有任何疑問,請告訴我。 –
您是否使用'jackson'進行彈簧消息映射? –