3.7 批量删除
columns : [
{ checkbox : true } ,
...
]
点击删除学生的按钮 所有被选中的student 从数据库删除 刷新表格数据
< script type = " text/javascript" >
$ ( function ( ) {
$ ( "#but_delete" ) . bind ( "click" , function ( ) {
var coll= $ ( "#table_student" ) . bootstrapTable ( "getSelections" ) ;
var b= window. confirm ( "确定要删除?" ) ;
if ( ! b) { return ; }
var sidStr= "" ;
for ( var i= 0 ; i< coll. length; i++ ) {
sidStr+= ( coll[ i] . sid+ "" ) ;
if ( i< coll. length- 1 ) {
sidStr+= "-" ;
}
}
console. log ( "sidStr=" + sidStr) ;
$. ajax ( {
cache : false ,
type : "DELETE" ,
data : null ,
url : path+ "student/deleteSome/" + sidStr+ ".action" ,
dataType : "json" ,
async : false ,
success : function ( rv ) {
if ( rv. status== 200 ) {
$ ( "#table_student" ) . bootstrapTable ( "refresh" ) ;
return ;
}
alert ( rv. errorMessage) ;
}
} ) ;
} ) ;
} ) ;
</ script>
@DeleteMapping ( "/student/deleteSome/{sidStr}.action" )
public ResponseVO < String > deleteSomeMethod ( @PathVariable ( "sidStr" ) String sidStr) {
System . out. println ( "sidStr=" + sidStr) ;
String [ ] sidsArrStr= sidStr. split ( "-" ) ;
int [ ] sidsArrInt= new int [ sidsArrStr. length] ;
for ( int i= 0 ; i< sidsArrStr. length; i++ ) {
sidsArrInt[ i] = Integer . parseInt ( sidsArrStr[ i] ) ;
}
System . out. println ( Arrays . toString ( sidsArrInt) ) ;
return new ResponseVO < > ( 200 , null , "删除成功行数:" + service. deleteSomeMethod ( sidsArrInt) ) ;
}
< delete id = " deleteSome" parameterType = " int[]" >
delete from student where sid in
< foreach collection = " array" item = " sid" open = " (" close = " )" separator = " ," >
#{sid}
</ foreach>
</ delete>
delete请求方式 不能添加请求 参数