Domain:

public class Department {
private Long id;
private Set<User> users = new HashSet<User>();
private Department parent;
private Set<Department> children = new HashSet<Department>(); private String name;
private String description;
}
public class Role {
private Long id;
private String name;
private String description;
private Set<User> users = new HashSet<User>();
}
public class User {
private Long id;
private Department department;
private Set<Role> roles = new HashSet<Role>(); private String loginName; // 登录名
private String password; // 密码
private String name; // 真实姓名
private String gender; // 性别
private String phoneNumber; // 电话号码
private String email; // 电子邮件
private String description; // 说明 }

对应xml

Department.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="cn.itcast.oa.domain">
<class name="Department" table="itcast_department">
<id name="id">
<generator class="native" />
</id>
<property name="name" />
<property name="description" /> <!-- users属性,本类与User的一对多 -->
<set name="users">
<key column="departmentId"></key>
<one-to-many class="User" />
</set> <!-- parent属性,本类与Department(上级)的多对一 -->
<many-to-one name="parent" class="Department" column="parentId"></many-to-one> <!-- children属性,本类与Department(下级)的一对多 -->
<set name="children">
<key column="parentId"></key>
<one-to-many class="Department" />
</set> </class> </hibernate-mapping>

Role.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="cn.itcast.oa.domain"> <class name="Role" table="itcast_role">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="description"/> <!-- users属性,本类与User的多对多 -->
<set name="users" table="itcast_user_role">
<key column="roleId"></key>
<many-to-many class="User" column="userId"></many-to-many>
</set> </class> </hibernate-mapping>

User.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="cn.itcast.oa.domain"> <class name="User" table="itcast_user">
<id name="id">
<generator class="native"/>
</id>
<property name="loginName"/>
<property name="password"/>
<property name="name"/>
<property name="gender" />
<property name="phoneNumber"/>
<property name="email"/>
<property name="description"/> <!-- department属性,本类与Department的多对一 -->
<many-to-one name="department" class="Department" column="departmentId"></many-to-one> <!-- roles属性,本类与Role的多对多 -->
<set name="roles" table="itcast_user_role">
<key column="userId"></key>
<many-to-many class="Role" column="roleId"></many-to-many>
</set> </class> </hibernate-mapping>

applicationContext.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:tx="http://www.springframework.org/schema/tx"
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/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 自动扫描与装配bean -->
<context:component-scan base-package="cn.itcast.oa"></context:component-scan> <!-- 加载外部的properties配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/> <!-- 配置数据库连接池(c3p0) -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 基本信息 -->
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="user" value="${username}"></property>
<property name="password" value="${password}"></property>
<!-- 其他配置 -->
<!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: -->
<property name="initialPoolSize" value=""></property>
<!--连接池中保留的最小连接数。Default: -->
<property name="minPoolSize" value=""></property>
<!--连接池中保留的最大连接数。Default: -->
<property name="maxPoolSize" value=""></property>
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: -->
<property name="acquireIncrement" value=""></property>
<!-- 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: -->
<property name="maxStatements" value=""></property>
<!-- maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: -->
<property name="maxStatementsPerConnection" value=""></property>
<!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: -->
<property name="maxIdleTime" value=""></property>
</bean> <!-- 配置SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean> <!-- 配置声明式的事务管理(采用基于注解的方式) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/> </beans>

hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration>
<session-factory> <!-- 数据库信息(连接信息写到spring的配置文件中) -->
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<!--
<property name="connection.url">jdbc:mysql:///itcastoa_20120216</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
--> <!-- 其他配置 -->
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property> <!-- 导入映射配置 -->
<mapping resource="cn/itcast/oa/domain/User.hbm.xml" />
<mapping resource="cn/itcast/oa/domain/Department.hbm.xml" />
<mapping resource="cn/itcast/oa/domain/Role.hbm.xml" /> </session-factory>
</hibernate-configuration>

structs.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"> <struts>
<!-- 配置为开发模式 -->
<constant name="struts.devMode" value="true" />
<!-- 配置扩展名为action -->
<constant name="struts.action.extension" value="action" /> <package name="default" namespace="/" extends="struts-default"> <!-- 测试用的action,当与Spring整合后,class属性写的就是Spring中bean的名称 -->
<action name="test" class="testAction">
<result name="success">/test.jsp</result>
</action> <!-- 岗位管理 -->
<action name="roleAction_*" class="roleAction" method="{1}">
<result name="list">/WEB-INF/jsp/roleAction/list.jsp</result>
<result name="addUI">/WEB-INF/jsp/roleAction/addUI.jsp</result>
<result name="editUI">/WEB-INF/jsp/roleAction/editUI.jsp</result>
<result name="toList" type="redirectAction">roleAction_list</result>
</action> </package> </struts>

java_SSH整合1的更多相关文章

  1. [原创]mybatis中整合ehcache缓存框架的使用

    mybatis整合ehcache缓存框架的使用 mybaits的二级缓存是mapper范围级别,除了在SqlMapConfig.xml设置二级缓存的总开关,还要在具体的mapper.xml中开启二级缓 ...

  2. kindeditor4整合SyntaxHighlighter,让代码亮起来

    这一篇我将介绍如何让kindeditor4.x整合SyntaxHighlighter代码高亮,因为SyntaxHighlighter的应用非常广泛,所以将kindeditor默认的prettify替换 ...

  3. spring源码分析之freemarker整合

    FreeMarker是一款模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页.电子邮件.配置文件.源代码等)的通用工具. 它不是面向最终用户的,而是一个Java类库,是一款程 ...

  4. FullCalendar应用——整合农历节气和节日

    FullCalendar用来做日程管理功能非常强大,但是唯一不足的地方是没有将中国农历历法加进去,今天我将结合实例和大家分享如何将中国农历中的节气和节日整合到FullCalendar中,从而增强其实用 ...

  5. SAP CRM 将组件整合至导航栏中

    到现在,我们已经可以让组件独立地显示.我们只是运行它.让它显示在Web UI中.让我们把组件整合进导航栏,使我们可以在正常登录Web UI时访问它. 步骤一: 为你的UI组件主窗体创建一个内向插件. ...

  6. Atitit.你这些项目不都是模板吗?不是原创  集成和整合的方式大总结

    Atitit.你这些项目不都是模板吗?不是原创  集成和整合的方式大总结 1.1. 乔布斯的名言:创新即整合(Creativity is just connecting things).1 1.2. ...

  7. github入门到上传本地项目【网上资源整合】

    [在原文章的基础上,修改了描述的不够详细的地方,对内容进行了扩充,整合了网上的一些资料] [内容主要来自http://www.cnblogs.com/specter45/p/github.html#g ...

  8. 三大框架SSH整合

    三大框架SSH整合 -------------------------------Spring整合Hibernate------------------------------- 一.为什么要整合Hi ...

  9. SSH框架整合(代码加文字解释)

    一.创建数据库并设置编码. A) create database oa default character set utf8. 二.MyEclipse工程 A) 在Myeclipse里创建web工程, ...

随机推荐

  1. 新版本ubuntu13.10软件安装

    问题1:如何解决ubunt13.04不能和主机共享文件的问题 . 安装VMware Tools 网上有很多的资料,这里没有给出. . 设置共享文件夹目录 ) 在VMware虚拟机窗口,选择VM-> ...

  2. 一些不错的英文歌曲MV,留个存档!

    Lambada [[http://www.yinyuetai.com/video/265213]]Trouble Is A Friend [[http://www.yinyuetai.com/vide ...

  3. python中yield用法

    在介绍yield前有必要先说明下Python中的迭代器(iterator)和生成器(constructor). 一.迭代器(iterator) 在Python中,for循环可以用于Python中的任何 ...

  4. 50道经典的JAVA编程题(汇总)

    这是一次不可思议的编程历程.从2013年的最后一天开始做这份题,中间连续好几天的考试,包括java考试(今天考试的JAVA编程题),直到今天完成了.挺有成就感的...废话不多说了,来电实质性的吧. 全 ...

  5. Row Border in DataGrid 表格边框

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. jxse2.6连接外网rdv一直连接不上,而相同的代码用jxse2.7却能连上

    一直以为2.6中的bug会少一些,所以用2.6做开发:之前测试一直是在同一台 机器上,所以没啥问题:最近在外网设置了一个rdv,却一直连不上,困扰了n久,尝试各种方式都不起作用.最后想起以前开发的代码 ...

  7. [iOS UI进阶 - 5.0] 手势解锁Demo

    A.需求 1.九宫格手势解锁 2.使用了绘图和手势事件   code source: https://github.com/hellovoidworld/GestureUnlockDemo     B ...

  8. HTTP协议状态码详解

    HTTP状态码,我都是现查现用. 我以前记得几个常用的状态码,比如200,302,304,404, 503. 一般来说我也只需要了解这些常用的状态码就可以了.  如果是做AJAX,REST,网络爬虫, ...

  9. 自己学会汉化DevExpress控件[转]

    1. 文档导读 本文档以颜色区分内容的重要性和不同性,阅读本文档时请注意以下事项: 1. 红色部分表示需要注意的重点内容:(加粗的尤甚) 2. 蓝色部分表示相应于前版本新增的内容: 3. 紫色部分表示 ...

  10. cocos2d-x Mask的实现及优化

    转自:http://blog.ch-wind.com/cocos2d-x%E4%B8%ADmask%E7%9A%84%E5%AE%9E%E7%8E%B0%E5%8F%8A%E4%BC%98%E5%8C ...