我正在學習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