public void linksSave() {
Connection conn=null;
try {
conn=DbKit.getConfig().getDataSource().getConnection();
DbKit.getConfig().setThreadLocalConnection(conn);
//自动提交变成false
conn.setAutoCommit(false);
//获取数据
Record loginUser = getSessionAttr("loginUser");
String loginName = loginUser.get("user_id").toString();
SpSysLinks links = getModel(SpSysLinks.class,"links");
links.setUpdateUser(loginName);
links.setUpdateTime(new Date());
if(links.getLinksId()!=null) {
links.update();
}else {
links.setAddTime(new Date());
links.setAddUser(loginName);
links.setStatus(1);
links.save();
}
//不存在异常则进行提交
conn.commit();
} catch (Exception e) {
try
{
if(null!=conn) {
//存在异常则对数据进行回滚
conn.rollback();
}
}
catch (SQLException e1)
{
e1.printStackTrace();
}
}finally {
try
{
if(null!=conn){
//关闭连接
conn.close();
}
}
catch (Exception e2)
{
e2.printStackTrace();
}finally{
DbKit.getConfig().removeThreadLocalConnection();//发送数据
//发送数据
redirect("/links/linksList");
}
}
}