浏览 2589 次
锁定老帖子 主题:seam框架CRUD
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2010-03-12
首先,配置数据源context.xml 将这个文件放在<catalina_home>的conf目录下,我用的是tomcat6 context.xml 内容如下:
<Resource name="jdbc/BBS" auth="Container" type="javax.sql.DataSource" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://192.168.1.1:1433;DatabaseName=infodb1" username="sa" password="sa" maxActive="4" maxIdle="2" maxWait="5000" />
在这里,我用的数据库是sql server2005 ,如果改为mysql数据库的话,需要修改driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" 配置seam 的components.xml,该文件放在WEB-INF目录下。 <?xml version="1.0" encoding="UTF-8"?> <components xmlns="http://jboss.com/products/seam/components" xmlns:core="http://jboss.com/products/seam/core" xmlns:persistence="http://jboss.com/products/seam/persistence" xmlns:security="http://jboss.com/products/seam/security" xmlns:transaction="http://jboss.com/products/seam/transaction" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd http://jboss.com/products/seam/spring http://jboss.com/products/seam/spring-2.1.xsd"> <core:init debug="false" /> <core:manager concurrent-request-timeout="500" conversation-id-parameter="cid" conversation-timeout="120000" /> <transaction:entity-transaction entity-manager="#{em}" /> <persistence:entity-manager-factory name="BBS" /> <persistence:managed-persistence-context auto-create="true" entity-manager-factory="#{BBS}" name="em" /> <security:identity authenticate-method="#{authenticator.authenticate}" /> <core:pojo-cache cfg-resource-name="#{facesContext.externalContext.context.getRealPath('/WEB-INF/cache.xml')}" /> </components> 接着,我们写一个dao的接口
注意 <transaction:entity-transaction entity-manager="#{em}" />
接着,我们写一个dao的接口
public interface UserDAO { public void saveUser(User user); } @Name(" UserDAO ") @AutoCreate public class UserDAOImpl implements UserDAO { @In private EntityManager em; public void saveUser(User user) throws PersistenceException { em.persist(user); } }
@In 在faces层: @In private UserDAO userDAO; 这样就可以引入DAO进行操作了
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |