並非通用, 根據自己實際情況來
不能刪除前的dao方法
public void delete(CmsProjectNew bean);
可以刪除后的dao方法
@Modifying
@Query("delete CmsProjectNew bean where bean.id in (?1)")
public void deleteById(Integer id);
【下面錯誤原因】——service方法增加@Transactional
@Transactional
public void delete(int id) {
dao.deleteById(id);
}
嚴重: Servlet.service() for servlet [background] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query] with root cause
javax.persistence.TransactionRequiredException: Executing an update/delete query
