BULK INSERT. Ajax initiated the request, the core code is as follows:
var mids = new Array (), for (var i=0; i< rows.length; i++) {Mids.push (rows[i].id);} $.ajax ({type: ' POST ', DataType: "JSON", Async:false, traditional:true,//This line is important url:parent.getBasePath () + "Sys/role/setauth.do", data: {' mids ': Mids}, Success:function (data) {}, Error:function (Err) {}});
Next is the controller's code:
Passing in the list directly in the method will result in an error, so wrap a layer of @requestmapping ("/setauth") through a class @ResponseBodypublic map<string,object> Setauth ( Short ID, Modparam MIDSA) {}//encapsulates the class of the list object public class Modparam implements serializable{private static final long serialvers Ionuid = 8607859409880232081l;private list<short> mids;public list<short> getMids () {return mids;} public void Setmids (list<short> mids) {this.mids = mids;}}
Contoller the first layer of the call down, and finally to the mapper:
/*** * BULK INSERT * @return * @throws Exception */int insertwithlist (list<roleresource> rr) throws Exception;
The corresponding XML (my ID here is not a self-sequence, I am going to choose the largest ID in the table, and then add 1, then write to the object, so there is no use of the MyBatis Selectkey, this is for Oracle):
<insert id= "insertwithlist" parametertype= "java.util.List" > INSERT into T_web_role_resource (ID, role_id, source _id, remark) <foreach collection= "list" item= "item" index= "index" separator= "union All" > select #{item.id},#{item . Roleid},#{item.sourceid},#{item.remark} from dual </foreach> </insert>
Well, that's pretty much it.
Attach a reference link:
http://chenzhou123520.iteye.com/blog/1583407
Springmvc+mybatis+ajax BULK INSERT Data