Springmvc+mybatis+ajax BULK INSERT Data

Source: Internet
Author: User
Tags bulk insert

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.