67,516
社区成员
发帖
与我相关
我的任务
分享
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="postdaohib" class="daoimpl.PostsDaoHibImple" >
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
public class PostsDaoHibImple extends HibernateDaoSupport implements PostsDao {
public void del(int id) {
HibernateTemplate ht=super.getHibernateTemplate();
Posts p=ht.get(Posts.class, id);
try {
ht.delete(p);
System.out.println("删除");
ht.flush();
} catch(Exception e){
System.out.println("删除出错");
}
}
public static void main(String[] args)
{
ApplicationContext c = new ClassPathXmlApplicationContext("applicationContext.xml");
PostsDaoHibImple p=(PostsDaoHibImple) c.getBean("postdaohib");
p.del(35);
}
}
姓名 | <input id="user" name="user" type="text" /></td> |
密码 | <input id="psw" name="psw" type="text" /></td> |
<input type="submit" value="提交"/><input type="button" value="返回" /> |