日期:2014-05-17 浏览次数:20781 次
package com.tjw.mysql.model; import javax.annotation.Generated; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import org.springframework.stereotype.Component; @Component("admin") @Entity public class Admin { private int id ; private String name ; private String password ; private int grade ; @Id public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public int getGrade() { return grade; } public void setGrade(int grade) { this.grade = grade; } }
package com.tjw.mysql.dao.impl; import java.io.Serializable; import java.util.HashSet; import java.util.List; import java.util.Set; import javax.annotation.Resource; import javax.jms.Session; import org.hibernate.Query; import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.stereotype.Component; import com.tjw.mysql.dao.AdminDAO; import com.tjw.mysql.model.Admin; @Component("adminDAO") public class AdminImpl implements AdminDAO{ private HibernateTemplate hibernateTemplate; public void doCreate(Admin admin) { // TODO Auto-generated method stub hibernateTemplate.save(admin); } public boolean doCreateOrdoUpdate(Admin admin) { // TODO Auto-generated method stub return false; } public void doDelete(Admin admin) { this.hibernateTemplate.delete(admin); } public void doUpdate(Admin admin) { // TODO Auto-generated method stub this.hibernateTemplate.update(admin); } public List<Admin> findAll(){ // TODO Auto-generated method stub List<Admin> list = (List<Admin>)this. hibernateTemplate.find("from Admin"); return list ; } public Admin findById(int id) { // TODO Auto-generated method stub return null; } public int getCount() { // TODO Auto-generated method stub return 0; } public HibernateTemplate getHibernateTemplate() { return hibernateTemplate; } @Resource public void setHibernateTemplate(HibernateTemplate hibernateTemplate) { this.hibernateTemplate = hibernateTemplate; } }
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/a