add<电脑删除>
parent
b75c396a41
commit
e00a186f03
|
@ -13,7 +13,7 @@ import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@WebServlet(urlPatterns = {"/computerList"})
|
@WebServlet(urlPatterns = {"/computerList","/deleteComputer"})
|
||||||
public class ComputerServlet extends HttpServlet {
|
public class ComputerServlet extends HttpServlet {
|
||||||
|
|
||||||
IComputerService computerService = new ComputerServiceImpl();
|
IComputerService computerService = new ComputerServiceImpl();
|
||||||
|
@ -29,6 +29,19 @@ public class ComputerServlet extends HttpServlet {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "/deleteComputer":
|
||||||
|
deleteComputer(req, resp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteComputer(HttpServletRequest req, HttpServletResponse resp) {
|
||||||
|
String id = req.getParameter("id");
|
||||||
|
try {
|
||||||
|
computerService.deleteComputer(id);
|
||||||
|
resp.sendRedirect("/computerList");
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,14 +31,13 @@ public class ComputerDao {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int deleteComputer(int id) {
|
public void deleteComputer(int id) {
|
||||||
String sql = "delete from computer where id=?";
|
String sql = "delete from computer where id=?";
|
||||||
try {
|
try {
|
||||||
return queryRunner.update(sql, id);
|
queryRunner.update(sql, id);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Computer> getAllComputer() throws SQLException {
|
public List<Computer> getAllComputer() throws SQLException {
|
||||||
|
|
|
@ -10,4 +10,6 @@ public interface IComputerService {
|
||||||
public void addComputer(String name, String brand, String type, String price);
|
public void addComputer(String name, String brand, String type, String price);
|
||||||
|
|
||||||
List<Computer> listComputer() throws SQLException;
|
List<Computer> listComputer() throws SQLException;
|
||||||
|
|
||||||
|
void deleteComputer(String id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,4 +20,9 @@ public class ComputerServiceImpl implements IComputerService {
|
||||||
public List<Computer> listComputer() throws SQLException {
|
public List<Computer> listComputer() throws SQLException {
|
||||||
return computerDao.getAllComputer();
|
return computerDao.getAllComputer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteComputer(String id) {
|
||||||
|
computerDao.deleteComputer(Integer.parseInt(id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
<td>${computer.stock}</td>
|
<td>${computer.stock}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="/computer?action=updateForm&id=${computer.id}">Edit</a> |
|
<a href="/computer?action=updateForm&id=${computer.id}">Edit</a> |
|
||||||
<a href="/computer?action=delete&id=${computer.id}">Delete</a>
|
<a href="/deleteComputer?id=${computer.id}">Delete</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</c:forEach>
|
</c:forEach>
|
||||||
|
|
Reference in New Issue