CONTROLLER里面是不是尽量不要出现直接用比如readerDao,readerJdbc直接操作的方法。
然后再service里用@Transactional标识整个事物
/**
* 借阅列表(点击续借按钮)
*
* @param id
* @param readerLendRecord
* @param readerLendRecordQueryForm
* @param bindingResult
* @param model
* @param redirectAttrs
* @return
*/
@RequestMapping("/renewBook/{id}")
public String renewBook(@PathVariable("id") Long id,
ReaderLendRecord readerLendRecord,
ReaderLendRecordQueryForm readerLendRecordQueryForm,
Model model,RedirectAttributes redirectAttrs) {
String path = lendService.renewBook(getCurrentSchool(), id, model, MANA_PATH, readerLendRecordQueryForm);
return path;
}
/**
* 借阅列表(点击续借按钮)
* @param school
* @param id
* @param model
* @param manapath
* @param readerLendRecordQueryForm
* @return
*/
@Transactional
public String renewBook(School school,Long id,Model model,String manapath,ReaderLendRecordQueryForm readerLendRecordQueryForm) {
ReaderLendRecord rlr = readerLendRecordDao.findOne(id);
if (getMaxRenewNum(school.getId(),
readerDao.findBySchoolIdAndBarcode(school
.getId(), rlr.getReaderBarcode()), collectionDao
.findByBarcode(rlr.getCollectionBarcode(), school.getId()))) {
model.addAttribute(Constant.MESSAGE_ERROR, Constant.LEND_DEAL_MAX);
return manapath + "lend/renew";
} else {
renew(rlr.getCollectionBarcode(), rlr
.getReaderBarcode(),
school.getId());
List<BorrowList> list2 = null;
list2 = lendDaoJdbc.getBorrowListQuery(readerLendRecordQueryForm
.getReaderBarcode(), school.getId());
model.addAttribute("page", list2);
model.addAttribute(Constant.MESSAGE_SUCCESS, Constant.RENEW_SUCCESS);
return manapath + "lend/renew";
}
}
我知道这样写又问题 如何才规范
------解决思路----------------------
典型的是控制器调用服务层 服务层调用DAO层 DAO层操作数据库