Spring Hibernate 整合项目案例之@Entity注解
来源:互联网 发布:舞台灯光编程软件 编辑:程序博客网 时间:2024/06/08 08:19
Hibernate: insert into users (username) values (?)
数据库中的表名为users-->对应java实体类Users{Users.java或者users.java(不区分大小写)}
或者使用注解@table(name=“users”)
列名username-->对应实体类Users中的属性username
实体Users类的代码:(Users.java)
import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;@Entitypublic class Users {private int id;private String username;@Id@GeneratedValuepublic int getId() {return id;}public void setId(int id) {this.id = id;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}}
配置文件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:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"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/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"><context:annotation-config /><context:component-scan base-package="com.wangwang" /> <beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><value>classpath:jdbc.properties</value></property></bean> <bean id="dataSource" destroy-method="close"class="org.apache.commons.dbcp.BasicDataSource"><property name="driverClassName"value="${jdbc.driverClassName}" /><property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /></bean> <bean id="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="annotatedClasses"><list><value>com.wangwang.model.Users</value></list></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop><prop key="hibernate.show_sql">true</prop></props></property></bean></beans>
<!--注意红色字体部分,原因前面介绍过,spring2.5以后注解开启则将LocalSessionFactoryBean换成AnnotationSessionFactory
0 0
- Spring Hibernate 整合项目案例之@Entity注解
- Spring Hibernate 整合项目案例之@Entity注解
- Spring整合hibernate(注解)遇到unknown entity问题
- Hibernate注解之Entity
- spring,hibernate,struts2三大框架注解方式整合案例
- spring hibernate 整合 注解
- hibernate注解整合spring
- spring 之ioc注解,案例,整合单元测试(02)
- spring和hibernate注解整合
- spring+hibernate开发中关于项目中@Entity注解报错
- Spring3+Hibernate+Struts2整合之注解整合
- flex cairngorm和spring,hibernate整合案例
- struts2+spring+hibernate整合-案例与注意事项
- spring 整合hibernate项目配置文件
- hibernate Entity注解
- hibernate注解ENTITY
- Hibernate中的@Entity注解
- Hibernate注解使用以及Spring整合
- linux 下的mongodb安装
- hdu-2521-反素数
- 基于C语言的代码文件组织
- 台湾与大陆的计算机术语翻译差异
- java中的comparable和comparator接口
- Spring Hibernate 整合项目案例之@Entity注解
- USACO Broken Necklace
- 二叉树(一)
- js正则表达式验证
- Selenium入门(三)如何获取京东的商品列表
- 从NI Multisim软件导出到Mentor Graphics PADS Layout软件之使用指南
- sprintf函数的使用
- hdu1019 Least Common Multiple
- 【直方图面积】Maximal Rectangle