人员单条删除功能
protected void remove ( HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException {
String id = request. getParameter ( "id" ) ;
if ( Validator . isInteger ( id) ) {
personnelService. delete ( Integer . parseInt ( id) ) ;
}
response. sendRedirect ( request. getContextPath ( ) + "/personnel.do" ) ;
}
public interface PersonnelService {
int delete ( int id) ;
}
public class PersonnelServiceImpl implements PersonnelService {
private PersonnelDao personnelDao = PersonnelFactory . getPersonnelDao ( ) ;
@Override
public int delete ( int id) {
return personnelDao. delete ( id) ;
}
}
public interface PersonnelDao {
int delete ( int id) ;
}
public class PersonnelDaoImpl implements PersonnelDao {
public PersonnelDaoImpl ( ) {
}
private static PersonnelDaoImpl instance = null ;
public static PersonnelDaoImpl getInstance ( ) {
if ( instance == null ) {
synchronized ( PersonnelDaoImpl . class ) {
if ( instance == null ) {
instance = new PersonnelDaoImpl ( ) ;
}
}
}
return instance;
}
@Override
public int delete ( int id) {
SqlSession session = MybatisUtils . openSession ( true ) ;
int count = session. delete ( "personnel.delete" , id) ;
session. close ( ) ;
return count;
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<! DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
< mapper namespace = " personnel" >
< delete id = " delete" parameterType = " int" >
delete
from rms_personnel
where id = #{id}
</ delete>
</ mapper>