【实例】赵雅智_login(4)删除

来源:互联网 发布:java程序员的晋升之路 编辑:程序博客网 时间:2024/06/08 11:54

新建servletDeleteByIdServlet

package www.csdn.net.servlet;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import www.csdn.net.service.AdminService;import www.csdn.net.service.AdminServiceImpl;public class DeleteByIdServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {String sId = request.getParameter("id");AdminService adminService = new AdminServiceImpl();boolean flag = adminService.deleteById(Integer.valueOf(sId));if(flag){ request.getRequestDispatcher("./select.do").forward(request, response);}else{System.out.println("删除失败");}}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {this.doGet(request, response);}}

实现dao包

package www.csdn.net.junit;import java.util.List;import org.junit.Test;import www.csdn.net.dao.AdminDao;import www.csdn.net.dao.AdminDaoImpl;import www.csdn.net.domain.Admin;public class AdminDaoImolTest {//AdminDao接口,AdminDaoImpl是接口的实现类,所有一个接口实现类的对象可以转换成接口的对象(多态性)。private AdminDao adminDao = new AdminDaoImpl();@Testpublic void login(){ Admin entity = adminDao.login("Jack", "123"); System.out.println(entity.toString());}@Testpublic void findAll() {List<Admin> list = adminDao.findAll();System.out.println("查询内容是:");for (Admin admin : list) {System.out.println("id:" + admin.getId());System.out.println("name:" + admin.getName());System.out.println("pw:" + admin.getPass());System.out.println("sex:" + admin.getSex());System.out.println("role:" + admin.getRole());System.out.println(" ");}}@Testpublic void findNowTest(){ List<Admin> i = adminDao.findNowPageInfo(3); System.out.println(i);}@Testpublic void deleteByIdTest(){ boolean i = adminDao.deleteById(7); System.out.println(i);}}


测试


原创粉丝点击