原始问题是,这将导致http get方法调用,而doGet()方法没有代码可以处理相同的问题
我对CRUD删除操作有问题。当我单击以这种方式写入jsp文件<form action="delete?Id=${medicines.id}" method="post">
<input type="submit" value="Delete">
</form>
的删除时。
这里是我的DeleteController(如果我在doGet中键入内容,那么我会从中获取结果,而不是空白页)
@WebServlet("/delete")
public class MedicinesDeleteController extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
int id = Integer.parseInt(request.getParameter("Id"));
if(request.getUserPrincipal() != null) {
MedicinesService query = new MedicinesService();
query.delete(id);
response.sendRedirect(request.getContextPath() + "/");
} else {
response.sendError(403);
}
}
}
从MedicinesService删除功能(我认为这是我的问题)] >>
public void delete(int id) { DAOFactory factory = DAOFactory.getDAOFactory(); MedicinesDAO medicinesDao = factory.getMedicinesDAO(); Medicines medicines = new Medicines(); medicines.setId(id); medicinesDao.delete(medicines); }
和MedicinesDAOImpl
private final static String DELETE_MEDICINES = "DELETE FROM medicines WHERE id_medicines=:id_medicines;"; @Override public void delete(Medicines medicines) { SqlParameterSource namedParameter = new MapSqlParameterSource("Id", medicines.getId()); template.update(DELETE_MEDICINES, namedParameter); }
新错误
medicinesDao.delete(medicines); < MedicicinesService:41
template.update(DELETE_MEDICINES, namedParameter); < MedicinesDAOImpl:77
query.delete(id); <MedicinesDeleteController:31
Type Exception Report
Message No value supplied for the SQL parameter 'id_medicines': No value registered for key 'id_medicines'
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.springframework.dao.InvalidDataAccessApiUsageException: No value supplied for the SQL parameter 'id_medicines': No value registered for key 'id_medicines'
org.springframework.jdbc.core.namedparam.NamedParameterUtils.buildValueArray(NamedParameterUtils.java:355)
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.getPreparedStatementCreator(NamedParameterJdbcTemplate.java:398)
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.getPreparedStatementCreator(NamedParameterJdbcTemplate.java:370)
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:317)
pl.firstaidkit.dao.MedicinesDAOImpl.delete(MedicinesDAOImpl.java:77)
pl.firstaidkit.dao.MedicinesDAOImpl.delete(MedicinesDAOImpl.java:1)
pl.firstaidkit.service.MedicinesService.delete(MedicinesService.java:41)
pl.firstaidkit.controller.MedicinesDeleteController.doPost(MedicinesDeleteController.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
pl.firstaidkit.filter.LoginFilter.doFilter(LoginFilter.java:26)
Note The full stack trace of the root cause is available in the server logs.
我对CRUD删除操作有问题。当我单击以这种方式写在jsp文件中的Delete时
原始问题是,这将导致http get方法调用,而doGet()方法没有代码可以处理相同的问题
<a href="delete?drugid=${medicines.id}">Delete</a>
第二个问题是MapSqlParameterSource参数名称和查询中的占位符不匹配。
原始问题是,这将导致http get方法调用,而doGet()方法没有代码可以处理相同的问题
原始问题是,这将导致http get方法调用,而doGet()方法没有代码可以处理相同的问题