?? personinfo.java
字號:
package com.dao.data;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.dao.entity.Student;
import com.dao.service.UPerson;
import com.dao.utrl.HibernateSessionFactory;
import com.struts.form.LoginForm;
import com.struts.form.UpdateForm;
public class PersonInfo implements UPerson {
// 刪除信息
public void del(Student formbean) {
Transaction tr = null;
try {
Session seion = HibernateSessionFactory.getSession();
tr = seion.beginTransaction();
seion.clear();
seion.delete(formbean);
tr.commit();
} catch (Exception ex) {
tr.rollback();
ex.printStackTrace();
}
}
// 添加信息
public void ins(Student formbean) {
Transaction tr = null;
try {
Session seion = HibernateSessionFactory.getSession();
tr = seion.beginTransaction();
seion.save(formbean);
tr.commit();
} catch (Exception ex) {
tr.rollback();
ex.printStackTrace();
}finally{
this.close();
}
}
// 登陸
public boolean login(LoginForm formbean) {
boolean b = false;
try {
Session seion = HibernateSessionFactory.getSession();
String hql = "from Logininfo where lname=? and lpwd=?";
Query query = seion.createQuery(hql);
query.setParameter(0, formbean.getLoginname().trim());
query.setParameter(1, formbean.getLpwd().trim());
if (query.list().size() > 0) {
b = true;
}
} catch (Exception ex) {
ex.printStackTrace();
}finally{
this.close();
}
return b;
}
public void close(){
HibernateSessionFactory.closeSession();
}
// 查詢信息
public List sel(Student formbean) {
// TODO Auto-generated method stub
List list = new ArrayList();
try {
Session seion = HibernateSessionFactory.getSession();
String hql = "";
Query query = null;
hql = "from Student where sname like ? or sage like ?";
if (formbean.getText().equals("*")) {
hql = "from Student";
query = seion.createQuery(hql);
} else {
query = seion.createQuery(hql);
query.setParameter(0, "%" + formbean.getText().trim() + "%");
query.setParameter(1, "%" + formbean.getText().trim() + "%");
}
seion.clear();
list = query.list();
} catch (Exception ex) {
ex.printStackTrace();
}finally{
this.close();
}
return list;
}
//查詢
public static List s(String id){
List list=new ArrayList();
try {
Session seion = HibernateSessionFactory.getSession();
String hql = "from Student where sid=?";
Query query = seion.createQuery(hql);
query.setParameter(0, new Integer(id));
list= query.list();
} catch (Exception ex) {
ex.printStackTrace();
}finally{
HibernateSessionFactory.closeSession();
}
return list;
}
// 修改信息
public void up(Student formbean) {
Transaction tr = null;
try {
Session seion = HibernateSessionFactory.getSession();
tr = seion.beginTransaction();
seion.clear();
seion.update(formbean);
tr.commit();
} catch (Exception ex) {
tr.rollback();
ex.printStackTrace();
}finally{
this.close();
}
}
/**
* @param args
*/
// public static void main(String[] args) {
// PersonInfo p = new PersonInfo();
// Student s = new Student();
// s.setSage("19");
// s.setSname("張三");
// s.setSsex("男");
//
// //p.ins(s);
// //s.setText("19");
// s.setSid(new Integer(3));
// // p.up(s);
// p.del(s);
// List list = p.sel(s);
// Iterator it = list.iterator();
// while (it.hasNext()) {
// Student s2 = (Student) it.next();
// System.out.println(s2.getSname().trim()+"\t"+s2.getSsex());
//
// }
// }
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -