我正在使用 Java Spring 和 JDBC 开发 CRUD 应用程序。我看过教程,但我坚持使用 crUd 的“U”字母 :)。 我已经做了一些事情,但如果你能帮助我,我将不胜感激。
以下是我做过的事情:
TournamentDAO:
public void edit(Tournament tournament){
String sql = "update TOURNAMENT.TOURNAMENT set name = ? , location = ? , date = ? , where id = ?";
m_jdbcTemplate.update(sql,
new Object[]{
tournament.getName(),
tournament.getLocation(),
tournament.getDate(),
Long.toString(tournament.getId())
});
}
Controller “EditTournament”:
@Controller
public class EditTournament {
@Autowired
private TournamentService turnirSer;
@RequestMapping(value = "/editTournament", method = RequestMethod.GET)
public ModelAndView edit(@RequestParam("id") Integer id) {
ModelAndView mav = new ModelAndView("editTournament");
Tournament Tournament = turnirSer.getById(id);
mav.addObject("editTournament", tournament);
return mav;
}
@RequestMapping(value = "/editTournament", method = RequestMethod.POST)
public String update(Model model, @Valid Tournament tournament,
BindingResult bindingResult,
@ModelAttribute("tournamentList") ArrayList<Tournament> TournamentList) {
if (!bindingResult.hasErrors()) {
turnirSer.editTournament(tournament);
tournamentList.add(tournament);
}
return "editTournament";
}
}
现在只想说我知道这完全是一团糟,这就是为什么我需要你的帮助!
在这一行中:
Tournament Tournament = turnirSer.getById(id);
我没有方法 getById(id)
,我从基于 Hibernate 的教程中获取了它,我不使用它,我不知道如何创建一个!
有人可以向我解释哪里出了问题以及如何编写此代码以使我的更新有效。
附言。创建、读取和删除工作正常。在这里发布这个问题是我最后的选择,我已经尽力了。
最佳答案
你有多余的
,
在查询中的where
之前
date = ? , where id = ?";
关于Java CRUD 应用程序卡在 "Update"上!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12141616/