jsp页面:
< input type = " checkbox" class = " middle children-checkbox" name = " check" value = " ${info.productId}" />
< script type = " application/javascript" >
function delProduct ( ) {
var idArrs = new Array ( ) ;
$ ( "input[name=check]:checked" ) . each ( function ( i) {
idArrs[ i] = $ ( this ) . val ( ) ;
} )
if ( idArrs. length== 0 ) {
alert ( "至少要选中一笔资料" ) ;
return ;
}
if ( confirm ( "确定要删除掉勾选内容吗?" ) ) {
$. ajax ( {
url : "http://localhost:8080/product/delProduct" ,
type : "POST" ,
data: { _method: "DELETE" , idArrs: idArrs} ,
dataType : "json" ,
success : function ( data) {
if ( data=== "success" ) {
$ ( "input[name=check]:checked" ) . each ( function ( ) {
$ ( this ) . parent ( ) . parent ( ) . parent ( ) . remove ( ) ;
} )
$ ( "#msg" ) . text ( "删除成功!" ) . css ( "color" , "green" ) ;
} else {
$ ( "#msg" ) . text ( "删除失败!" ) . css ( "color" , "red" ) ;
}
}
} ) ;
}
}
$ ( function ( ) {
$ ( "#all" ) . click ( function ( ) {
if ( $ ( "input[name=check]:checkbox" ) . is ( ":checked" ) ) {
$ ( "input[name=check]:checkbox" ) . prop ( "checked" , false ) ;
} else {
$ ( "input[name=check]:checkbox" ) . prop ( "checked" , true ) ;
}
} )
} )
</ script>
controller:
@RequestMapping ( value = "/delProduct" , method = RequestMethod. DELETE)
@ResponseBody
public Object delProduct ( @RequestParam ( value= "idArrs[]" ) String [ ] idArrs) {
String jsonString = "" ;
productService. delImgs ( idArrs) ;
int count = productService. delProduct ( idArrs) ;
System. out. println ( "count" + count) ;
if ( count< 0 ) {
jsonString = JSON. toJSONString ( Constants. ERROR_MESSAGE) ;
System. out. println ( "....." ) ;
return jsonString;
} else {
jsonString = JSON. toJSONString ( Constants. SUCCESS_MESSAGE) ;
return jsonString;
}
}
mapper:
int delProduct ( String [ ] idArrs) ;
< delete id = " delProduct" parameterType = " string" >
update productinfo set flg=1 where productId in
< foreach collection = " array" item = " ids" open = " (" separator = " ," close = " )" >
#{ids}
</ foreach>
</ delete>