hibernate 指定id
dboTGcGridinfo dbotgcgridinfo = new dboTGcGridinfo();
try {
if(isadd.equals("true")){ //判断是新增,
//将前台传入的id和name放入对象中
dbotgcgridinfo.setId(gridid);
dbotgcgridinfo.setGridname(gridname);
//要求存放指定id,防止被hibernate自动生成的id覆盖
basedao.getSession().replicate(dbotgcgridinfo, ReplicationMode.OVERWRITE); //指定id
basedao.getSession().save(dbotgcgridinfo);
return "success";
}else{ //判断是编辑,利用hibernate内部自带函数save即可
dbotgcgridinfo = queryEntityById(dboTGcGridinfo.class, gridid);
dbotgcgridinfo.setGridname(gridname);
basedao.saveEntity(dbotgcgridinfo);
return "success";
}
}