java - 如何在 spring hibernate 中将值列表插入数据表

标签 java hibernate spring-mvc

我需要在一次提交时将多行值插入到同一个表中。 enter image description here

在 Ajax

$("#btn_themDay").click(function(){
$("#themDay_validation").hide();
var no_row = Number($('#tbl_videoDetails').find("td.lastno").text());
var videoDetails_valid = true;
var name = new Array();
var land = new Array();
var area = new Array();
var District = new Array();
var thaluk = new Array();
var i;

for(i=1;i<=no_row;i++){     // validdation 
    name[i]=$("#vodtitle"+i).val();
    land[i]=$("#vodtime"+i).val();
    area[i]=$("#voduploadImage"+i).val();
    District[i]=$("#vodurl"+i).val();
    thaluk[i]=$("#voddes"+i).val();

$.ajax({
    url: "savefull",
    type: "POST",
    data: {values:name},
    traditional: true,
    dataType: "json",
    cache: false,
    success: function (data) {

    }
});



return false;   // for testing return false 

});

我像这样在 Controller 中捕获数据

    @RequestMapping(value="savefull",method=RequestMethod.POST)
    public @ResponseBody ThematicDay savefull(@ModelAttribute("Data") Data values){
        try{
            System.out.print("Value "+values+"        ");

    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
        return null;

    } 

但我不知道如何使用 hibernate 查询将它插入到我的 dao 中。

最佳答案

您可以使用 Batch Inserts

Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

for ( int i=0; i<100000; i++ ) {
    Customer customer = new Customer(.....);
    session.save(customer);
    if ( i % 20 == 0 ) { //20, same as the JDBC batch size
        //flush a batch of inserts and release memory:
        session.flush();
        session.clear();
    }
}

tx.commit();
session.close();

关于java - 如何在 spring hibernate 中将值列表插入数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29007488/

相关文章:

spring-mvc - Spring Boot 2.0.0.M4 和电子邮件地址作为@PathVariable 给出 HTTP 500 错误

java - 如何创建既有样式又有自定义字体的 Java/Swing 文本组件?

hibernate - Elasticsearch 的性能是否会受到关系数据库模型(如MySQL)的影响?

hibernate - Grails save(flush:true)不会立即持久保存到数据库

php - 在哪里保存数据?

java - 关于Interceptor中读取POST方法参数

java - 如何将数据从 BroadcastReceiver 传递到主 Activity ?

java - ProGuard:ClassCastException

java - 如何点击没有可点击的按钮:true state in Appium+Java?

java - 带有 Jaxb2Marshaller 的 Spring MVC 在 2013 年的日期失败