按钮修改状态


首先创造函数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);
前端添加:

同意报销申请 驳回报销申请 后端Servlet添加 package com.comple.servlet;

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");
}

}

posted @ 2024-12-23 23:12  雨花阁  阅读(7)  评论(0编辑  收藏  举报