spring+hibernate :annotation
来源:互联网 发布:netty 好书 知乎 编辑:程序博客网 时间:2024/06/05 09:22
User.class
@Entitypublic class User {private int id;private String name;@Id@GeneratedValuepublic 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 User(String name) {super();this.name = name;}}
StudentDao.class
@Repository("student")public class StudentDao {private SessionFactory factory;public SessionFactory getFactory() {return factory;}@Resourcepublic void setFactory(SessionFactory factory) {this.factory = factory;}public void save(User user){System.out.println("begin save!!!");Session session=factory.openSession();session.beginTransaction();session.save(user);session.getTransaction().commit();session.close();System.out.println("save success!!");}}
beans.xml
<?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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "><context:component-scan base-package="com.sl"/><bean id="mydataSource" class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"><property name="driverClassName" value="com.mysql.jdbc.Driver" /><property name="url" value="jdbc:mysql://localhost:3306/spring" /><property name="username" value="root" /><property name="password" value="qi" /></bean><bean id="factory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="mydataSource"/> <property name="annotatedClasses"> <list> <value>com.sl.entity.User</value> </list> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.show_sql=true hibernate.format_sql=true hibernate.hbm2ddl.auto=create </value> </property> </bean></beans>
test
public class test {@Testpublic void testOne(){ApplicationContext appl=new ClassPathXmlApplicationContext("beans.xml");StudentDao dao=(StudentDao)appl.getBean("student");User user=new User("qing");dao.save(user);}}
- spring+hibernate :annotation
- Spring下Hibernate Annotation注解
- Spring下Hibernate Annotation注解
- spring+hibernate Annotation方式整合
- spring + hibernate + annotation 简单整合
- Spring Security + Hibernate Annotation Example
- spring与带Annotation的hibernate集成
- spring与带Annotation的hibernate集成
- struts2+spring+hibernate集成(annotation版)
- struts2+hibernate+spring整合(annotation版)
- spring integration hibernate pom.xml (annotation)
- Maven + (Spring + Hibernate) Annotation + MySQL项目
- Maven + (Spring + Hibernate) Annotation + MySql Example
- Spring hibernate annotation 开发主键生成策略
- Spring +hibernate 声明式 事物 + annotation
- Hibernate annotation
- Hibernate Annotation
- Hibernate Annotation
- 日期类加减及Java中日期类操作算法大全 (转)
- Bluez相关的各种tools的使用(主要用到hcidump)
- xp关闭U盘的自动播放功能
- 关于Context []startup failed due to previous errors有效解决方式
- HTTP状态码
- spring+hibernate :annotation
- nat 心得
- bluetooth相关的入门文章
- linux上GIT的使用
- 怎样使男性长寿命?
- Makefile学习过程中遇到的问题
- HttpClient4 post上传文件, struts2 action接收
- 第一周项目2日期结构体
- 获取WebView加载HTML时网页中的内容