table:
create table users
(
id int auto_increment not null primary key,
name varchar(32) not null,
password varchar(32) not null
);
select * from users
insert into users (name,password) values('text','text');
insert into users(name,password) select name,password from users;
dao:
package com.ssh.dao;
import java.util.List;
import com.ssh.orm.Users;
public interface UsersDao {
public boolean insert(Users users) throws Exception;
public Users select(int id) throws Exception;
public boolean update(Users users) throws Exception;
public boolean delete(int id) throws Exception;
public List selectAll() throws Exception;
public List selectAllByPage(int curPage, int lineSize) throws Exception;
public int getCount() throws Exception;
}
daoImpl:
package com.ssh.dao.impl;
import java.util.List;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.ssh.dao.UsersDao;
import com.ssh.orm.Users;
public class UsersDaoImpl extends HibernateDaoSupport implements UsersDao {
public boolean delete(int id) throws Exception {
}
public boolean insert(Users users) throws Exception {
}
public Users select(int id) throws Exception {
}
public boolean update(Users users) throws Exception {
}
public List selectAll() throws Exception {
}
public List selectAllByPage(int curPage, int lineSize) throws Exception {
}
public int getCount() throws Exception {
}
}
operate:
package com.ssh.text;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationC
import com.ssh.dao.impl.UsersDaoImpl;
import com.ssh.orm.Users;
public class Text {
public static void main(String[] args) throws Exception {
}
}
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource"
</bean>
<bean id="sessionFactory"
</bean>
<bean id="hibernateTemplate"
</bean>
<bean id="userDao" class="com.ssh.dao.UsersDao" abstract="true"></bean>
<bean id="userDaoImpl" class="com.ssh.dao.impl.UsersDaoImpl"
</bean>
</beans>
Hibernate映射文件和Users 类不在写出。