按钮修改状态
首先创造函数void updateBaoxiaoSchedule( int id,
String schedule,
String schedulereason);
及其实现。
SQL语句:
@Update("update submit set state=#{state},statereason=#{statereason} where id=#{id} ")
void updateSubmit1(
@Param("id") int id,
@Param("state") String state,
@Param("statereason") String statereason);
前端添加:
import com.comple.service.ReceiptService;
import com.comple.service.ReceiptServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/update1-baoxiao")
public class UpdatebaoxiaoServlet2 extends HttpServlet {
ReceiptService receiptService;
@Override
public void init() throws ServletException {
receiptService =new ReceiptServiceImpl();
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
int id = Integer.parseInt(req.getParameter("id"));
String status = req.getParameter("status");
String state;
String statereason;
if(status.equals("yes")){
state="已通过";
statereason="无";
}
else
{
state="驳回";
statereason="无";
}
receiptService. updateBaoxiaoSchedule(id, state, statereason);
resp.sendRedirect("indexaservlet");
}
}