📄 systemdao.java
字号:
package com.oa.module.system;
import java.io.Serializable;
import java.util.List;
import javax.mail.Provider.Type;
import org.hibernate.Query;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.hibernate.Transaction;
import com.oa.module.system.HibernateSessionFactory;
import com.oa.module.system.HibernateUtil;
import com.oa.module.system.Ttype;
import com.oa.module.system.Tparam;
public class SystemDAO {
private SessionFactory sf;
public SessionFactory getSf() {
return sf;
}
public void setSf(SessionFactory sf) {
this.sf = sf;
}
//查询类型
public List gettype(){
HibernateTemplate ht=new HibernateTemplate(this.sf);
String hql="select a from Ttype a where 1=1";
List typelist=ht.find(hql);
return typelist;
}
//查询参数
public List getparam(){
HibernateTemplate ht=new HibernateTemplate(this.sf);
String hql="select a from Tparam a where 1=1";
List paramlist=ht.find(hql);
return paramlist;
}
//添加类别
public boolean addtype(String tname,String tmemo){
Ttype type=new Ttype();
type.setTname(tname);
type.setTmemo(tmemo);
HibernateTemplate ht=new HibernateTemplate(this.sf);
try {
ht.save(type);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
//添加参数
public boolean addparam(long tid,String pname,String pmemo){
Tparam param=new Tparam();
param.setTid(tid);
param.setPname(pname);
param.setPmemo(pmemo);
HibernateTemplate ht=new HibernateTemplate(this.sf);
try {
ht.save(param);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
//删除参数类别
public boolean deltype(long tid){
HibernateTemplate ht=new HibernateTemplate(this.sf);
String hql=" from Ttype a where a.tid='"+tid+"'";
List list=ht.find(hql);
if(list.size()==0){
return false;
}else{
Ttype type=(Ttype) list.get(0);
ht.delete(type);
return true;
}
}
//删除参数
public boolean delparam(long pid){
HibernateTemplate ht=new HibernateTemplate(this.sf);
String hql=" from Tparam a where a.pid='"+pid+"'";
List list=ht.find(hql);
if(list.size()==0){
return false;
}else{
Tparam param=(Tparam) list.get(0);
ht.delete(param);
return true;
}
}
//修改参数类别
public boolean edittype(long tid,String tname,String tmemo){
Ttype type=new Ttype();
type.setTid(tid);
type.setTname(tname);
type.setTmemo(tmemo);
HibernateTemplate ht=new HibernateTemplate(this.sf);
try {
ht.update(type);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
//修改参数
public boolean editparam(long tid,long pid,String pname,String pmemo){
Ttype type=new Ttype();
Tparam param=new Tparam();
param.setTid(tid);
param.setPid(pid);
param.setPname(pname);
param.setPmemo(pmemo);
HibernateTemplate ht=new HibernateTemplate(this.sf);
try {
ht.update(param);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
//验证类别是否存在
public boolean checktype(String tname){
HibernateTemplate ht=new HibernateTemplate(this.sf);
String hql="select a from Ttype a where a.tname='"+tname+"'";
//查到数据
int count=ht.find(hql).size();
if(count>0){
return true;
}else{
return false;
}
}
//验证参数是否存在
public boolean checkparam(String pname){
HibernateTemplate ht=new HibernateTemplate(this.sf);
String hql="select a from Tparam a where a.pname='"+pname+"'";
//查到数据
int count=ht.find(hql).size();
if(count>0){
return true;
}else{
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -