【发布时间】:2017-06-28 00:27:27
【问题描述】:
AdminController.java
@Controller
public class AdminController {
@Autowired
HttpServletRequest request;
@Autowired
AdminDao adminDao;
@RequestMapping("/deletebatch")
public String deletebatch(){
int batchid = Integer.parseInt(request.getParameter("id"));
adminDao.deletebatch(batchid);
return "redirect:/viewbatch";
}
#AdminDaoImpl.java
@Repository("adminDao")
public class AdminDaoImpl implements AdminDao {
@Autowired
SessionFactory sessionFactory;
@Transactional
public void deletebatch(int batchid){
// Batch batch = (Batch) sessionFactory.getCurrentSession().load(Batch.class,batchid);
// if(batch!=null){
sessionFactory.getCurrentSession().delete(batchid);
//}
}
}
#viewbatch.jsp
<form >
<table border="1">
<tr>
<th>BATCH id</th>
<th>BATCH name</th>
<th>edit/delete</th>
</tr>
<c:forEach items="${batchlist}" var="batchlist">
<tr>
<td>${batchlist.batchid}</td>
<td>${batchlist.batchname}</td>
<td><a href="edit">edit</a>/<a href="${pageContext.servletContext.contextPath}/deletebatch?id=${batchlist.batchid}">delete</a></td>
</tr>
</c:forEach>
当我尝试删除时出现错误:
HTTP 状态 500 - 请求处理失败;嵌套异常是 org.hibernate.MappingException:未知实体:java.lang.Integer"
和
我也尝试将 admincontroller 设置为“/delete?id=${batchid}”。
当我这样做时,我遇到了无法转换为字符串的问题
【问题讨论】:
标签: java hibernate spring-mvc