系统模块数据库的搭建

系统模块数据库的搭建
@override 识别需要1.6编译器
搭建环境:拷贝资源:修改环境;
界面是固定的样子,需要一个WEB-INF/jsp/common/common.jsp:
Code:
<%@ taglib prefix="s" uri="/struts-tags" %> //都是在struts2中调用
<script language="javascript" src="${pageContext.request.contextPath}/js/jquery-1.4.2.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/js/jquery-plugin-
deleteconfirm.js"></script>
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/css/blue/pageCommon.css" />
下面三个是所有页面都需要的文件;
maven搭建开发环境练习;
------
表的建立首先要确定表与表之间的关联关系,同时避免设计成三角类型;
岗位,部门,用户:
岗位\用户 多对多
用户\部门 1对多
然后---
domain:User Department Post
Set<User>
映射文件:*.hbm.xml
<hibernate-mapping>
<class name="com.itcast.oa.domain.Post">
<id name="pid" type="java.lang.Long" length="5">
<column name="pid"></column>
<generator class="increment"></generator>
</id>
<property name="pname" length="20"></property>
<property name="description" length="50"></property>
<set name="users" table="user_post">
<key>
<column name="pid"></column>
</key>
<many-to-many class="com.itcast.oa.domain.User" column="uid"></many-to-many>
</set>
</class>
</hibernate-mapping>

<!--一对多的话,一的一方不维护,Department不维护,inverse="true"-->
<set name="users" inverse="true">
<key>
<column name="did"></column>
</key>
<one-to-many class="com.itcast.oa.domain.User"/>
</set>

<!--多对多的话,都维护,默认的是inverse为false-->
<set name="posts" table="user_post">
<key>
<column name="uid"></column>
</key>
<many-to-many class="com.itcast.oa.domain.Post" column="pid"></many-to-many>
</set>
<!--多对一,多个用户是一个部门,-->
<many-to-one name="department" column="did"
class="com.itcast.oa.domain.Department"></many-to-one>

将这些文件整到hibernate.cfg.xml中;建数据库:编码集为utf8-bin
----
测试建表:
public class CreateTable {
@Test
public void testCreateTable(){
Configuration configuration = new Configuration();
configuration.configure("hibernate/hibernate.cfg.xml");
configuration.buildSessionFactory();
}
}

posted @ 2014-02-27 17:51  教程学习  阅读(229)  评论(0)    收藏  举报