springboot project for batch new features

This bothered me all day thing, and finally resolved.

  The first is the new sql statement mybatis in bulk.

  Note: Here I give is that I need to add a field, you need to change your field.

1 <insert id="insertBatch" >
2     insert into hm_authorization (ID,ROLE_CODE,RES_TYPE_CODE,RES_CODE)
3     values
4     <foreach collection="list" item="item" index="index" separator=",">
5       (#{item.id},#{item.roleCode},#{item.resTypeCode},#{item.resCode})
6     </foreach>
7   </insert>

  Controller then directly on the interface layer.

  Note: This is written on my class notes is @RestController, if you write a @Controller, do not forget to add in the method @ResponseBody.

  Explain this code: List generic placed inside your own objects, JSON.parseArray method fastjson package. Attach jar package maven reference.

  My approach here may be somewhat stupid, but to achieve the most important. I also try to start a reception list, but not receiving. Various methods Baidu came out feeling is idle nonsense. Anyway, I will not take.

<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.58</version>
        </dependency>

 

1 @PostMapping(value = "addbatch")
2     public ResultVo addBatch(@RequestParam String data){
3         System.out.println(data);
4         String strlist = data;
5         List<AuthVo> array = JSON.parseArray(strlist,AuthVo.class);
6 
7         return authorizationService.insertBatch(array);
8     }

   And then deal with the problem of front-end

1  // front-end I used a table, select the direct access to the array. If you can not directly get the array,
 2  // first data to traverse an array. As for how to traverse, Baidu bar.
3  // make sure your data is the format of the array, the data is converted to json format. On the line.
4  // listener table selection box
 . 5                      $ ( "# the Add"). ON ( 'the Click', function () {
 . 6                          //table.on('checkbox(useruv) ', function (obj) {
 . 7                          var the checkStatus table.checkStatus = ( 'LAY_table_user');
 . 8                          var obj = checkStatus.data;
 . 9                          var info = the JSON.stringify (obj);
 10                          the console.log (info);
 . 11                          $ .ajax ({
 12 is                             type: "post",
13                             url: "addbatch",
14                             data: "data="+info,
15                             dataType: "json",
16                             success: function (d) {
17                                 if (d.code == 1) {
18                                     layer.msg("新增成功", {
19                                         icon: 6
20                                     });
21                                 } else {
22                                     layer.msg("新增失败", {
23                                         icon: 5
24                                     });
25                                 }
26                             }
27                         })

 

Guess you like

Origin www.cnblogs.com/zhanvo/p/10963776.html