删除功能_代码实现与修改功能_分析

删除功能_代码实现

  

package hf.xueqiang.web.servlet;

import hf.xueqiang.service.UserService;
import hf.xueqiang.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/delUserServlet")
public class DelUserServlet extends HttpServlet {


    @Override   
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取id
        String id = request.getParameter("id");
        //2.调用service删除
        UserService service = new UserServiceImpl();
        service.deleteUser(id);
        //3.跳转到查询所有Servlet
        response.sendRedirect(request.getContextPath()+"/userListServlet");
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
    /**
     * 根据id删除数据
     * @param id
     */
    void deleteUser(String id);
}
   @Override
    public void deleteUser(String id) {
        dao.deleteUser(Integer.parseInt(id));
    }
    void deleteUser(int i);
}
    @Override
    public void deleteUser(int id) {
        //1.定义sql
        String sql = "delete from user where id = ?";
        //2.执行sql
        template.update(sql, id);
    }

删除之前的:

 

删除之后的:

 

 

 

 

 

 

 

修改功能_分析

 

posted @ 2023-02-13 21:39  zj勇敢飞,xx永相随  阅读(36)  评论(0编辑  收藏  举报