人员批量删除功能
protected void batch ( HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException {
String [ ] ids = request. getParameterValues ( "ids" ) ;
if ( Validator . isNotEmpty ( ids) ) {
int [ ] array = new int [ ids. length] ;
for ( int i = 0 ; i < ids. length; i++ ) {
array[ i] = Integer . parseInt ( ids[ i] ) ;
}
personnelService. batch ( array) ;
}
response. sendRedirect ( request. getContextPath ( ) + "/personnel.do" ) ;
}
public interface PersonnelService {
int batch ( int . . . ids) ;
}
public class PersonnelServiceImpl implements PersonnelService {
private PersonnelDao personnelDao = PersonnelFactory . getPersonnelDao ( ) ;
@Override
public int batch ( int . . . ids) {
return personnelDao. batch ( ids) ;
}
}
public interface PersonnelDao {
int batch ( int . . . ids) ;
}
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 batch ( int . . . ids) {
SqlSession session = MybatisUtils . openSession ( true ) ;
int count = session. delete ( "personnel.batch" , ids) ;
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 = " batch" parameterType = " int" >
delete from rms_personnel where id in
< foreach collection = " array" item = " id" open = " (" close = " )" separator = " ," >
#{id}
</ foreach>
</ delete>
</ mapper>