我需要在一次提交时将多行值插入到同一个表中。
在 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/