How can I have an interface as a ModelAttribute as in the below scenario?
@GetMapping("/{id}")
public String get(@PathVariable String id, ModelMap map) {
map.put("entity", service.getById(id));
return "view";
}
@PostMapping("/{id}")
public String update(@ModelAttribute("entity") Entity entity) {
service.store(entity);
return "view";
}
Above snippet gives the follow errors
BeanInstantiationException: Failed to instantiate [foo.Entity]: Specified class is an interface
I don't want spring to instantiate entity for me, I want to use the existing instance provided by map.put("entity", ..).
entityobject on view side ?<form th:object="${entity}">..</form>th:field