通过Long这个类的Decode (String);可以得到一个Long 型;
可以通过他来做到:方法里放入的是一个String类型的变量,结果可以把这个变量变成符合要求的类型package dao;
import java.sql.Date;
import org.hibernate.Session;
import org.hibernate.Transaction;
import po.Acticle;
import po.ActicleType;
import tools.HibernateSessionFactory;
public class UpdateDAO {
public void Update(int acticleid, String title, String content,
String adddate, String modifydate, String typeid) {
HibernateSessionFactory hsf = new HibernateSessionFactory();
Session session = hsf.getSession();
Transaction tra = session.beginTransaction();
Acticle ac = (Acticle) session.get(Acticle.class, new Long(acticleid));
ac.setTitle(title);
ac.setContent(content);//
ac.setAdddate(Date.valueOf(adddate));
ac.setTypeid(Long.decode(typeid));
ac.setModifydate(Date.valueOf(modifydate));
session.saveOrUpdate(ac);
// session.update(ac);
tra.commit();
hsf.closeSession();
}
public void UpdateType(int typeid, String typename) {
HibernateSessionFactory hsf = new HibernateSessionFactory();
Session session = hsf.getSession();
Transaction tra = session.beginTransaction();
ActicleType ac = (ActicleType) session.get(ActicleType.class, new Long(
typeid));
ac.setTypename(typename);
session.saveOrUpdate(ac);
// session.update(ac);
tra.commit();
hsf.closeSession();
}
}