我正在学习SpringMVC 2,我有一个窗体,我需要绑定到一个对象(命令)。但是如果我需要这个命令对象作为接口,那么我可以使用不同的对象实现(当然所有的实现都会有相同的字段)。SpringMVC窗体绑定到命令对象这是接口
对于绑定表示帐户的表单我有这个控制器。 是否有可能将表单绑定到帐户接口,所以我可以使用它之后像一个业务bean?
或者只是告诉我什么是像一个流动的最佳春天做法: 表 - >业务逻辑 - >保存到数据库
public class OpenAccountControllerSpring2
extends SimpleFormController {
private ClientDao clientDao;
private Account account;
public OpenAccountControllerSpring2() {
setCommandClass(// dont know what to write here);
setCommandName("newAccount");
}
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
Object command, BindException bindExp)
throws Exception {
try {
//here i just want to create a new Account, add it to a Client (Interface), then transform the Client into a database-bean and save it.
int client_id = Integer.parseInt(request.getParameter("clientId"));
Account account = (Account) command;
Client client = Transformer.toBusinessHeavy(clientDao.getClient(client_id));
client.addAccount(account);
clientDao.updateClient(Transformer.toEntity(client));
} catch (Exception err) {
return new ModelAndView(this.getFormView());
}
return new ModelAndView(this.getSuccessView());
}
public void setClientDao(ClientDao dao) {
this.clientDao = dao;
}
public void setAccount(Account account) {
this.account = account;
}
}
我想学习2和3.目前我认为2更多地用于生产 – Blitzkr1eg 2010-09-10 22:07:02