第一步、配置實體Bean:
@Entity
@Table(name = "t_bd_city")
public class City extends BaseObject {
/**
* 省份
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "fprovinceid")
private Province province;
}
第二步、手動提交保存方法:
public abstract class CoreDaoHibernate<Entity extends CoreObject> implements CoreObjectDao<Entity> {
/**
* Log variable for all child classes. Uses LogFactory.getLog(getClass())
* from Commons Logging
*/
protected final Log log = LogFactory.getLog(getClass());
private Class<Entity> persistentClass ;
private HibernateTemplate hibernateTemplate;
private SessionFactory sessionFactory;
public CoreDaoHibernate(){
Class<?> c = this.getClass();
Type t = c.getGenericSuperclass();
if(t instanceof ParameterizedType){
this.persistentClass = (Class<Entity>)((ParameterizedType) t).getActualTypeArguments()[0];
}
}
public HibernateTemplate getHibernateTemplate() {
return this.hibernateTemplate;
}
public SessionFactory getSessionFactory() {
return this.sessionFactory;
}
@Autowired
@Required
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
this.hibernateTemplate = new HibernateTemplate(sessionFactory);
}
/**
* {@inheritDoc}
*/
@Override
public Entity save(Entity object) {
Entity result = hibernateTemplate.merge(object);
hibernateTemplate.flush();
return result;
}
}
第三步、配置web.xml
<filter>
<filter-name>lazyLoadingFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>lazyLoadingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<decorator-mappers>
<mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
<param name="config" value="${decorators-file}"/>
</mapper>
</decorator-mappers>
</sitemesh>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="<%@ taglib uri="<html xmlns="<head>
<%@ include file="/common/meta.jsp"%>
<title><decorator:title /> | Demo</title>
<decorator:head />
</head>
<body
<decorator:getProperty property="body.id" writeEntireProperty="true"/>
<decorator:getProperty property="body.class" writeEntireProperty="true"/>>
<div id="page">
<div id="header" class="clearfix">
<jsp:include page="/common/header.jsp" />
</div>
<div id="content" class="clearfix">
<div id="main">
<%@ include file="/common/messages.jsp"%>
<h1>
<decorator:getProperty property="meta.heading" />
</h1>
<decorator:body />
</div>
<c:set var="currentMenu" scope="request">
<decorator:getProperty property="meta.menu" />
</c:set>
<div id="nav">
<div class="wrapper"></div>
<hr />
</div>
<!-- end nav -->
</div>
<div id="footer" class="clearfix">
<jsp:include page="/common/footer.jsp" />
</div>
</div>
</body>
</html>
第五部:測試
期待正確的結果。
<beans xmlns=" xmlns:xsi="http://www.springframework.org/schema/beans <!-- 攔截配置 --> <!-- 切入點 --> <!-- Enable @Transactional support --> 昨天參與了項目組的用例需求評審會,發現大家對用戶用例與系統用例存在部分差異,包括架構師與需求分析師對他的理解,最后經過總結明確如下:
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!--說明事務類別 read-only表示不支持事務,propagation的事務類別與EJB保持一致-->
<tx:method name="find*" read-only="true" />
<tx:method name="get*" read-only="true" />
<tx:method name="load*" read-only="true" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<!-- Dao層事務 說明你要攔截那些包下面的類的方法-->
<aop:advisor id="daoTx" advice-ref="txAdvice" pointcut="execution(* *..dao.impl.*.*(..))" order="0" />
<!-- service層事務 -->
<aop:advisor id="serviceTx" advice-ref="txAdvice" pointcut="execution(* *..service.impl.*.*(..))" order="1" />
</aop:config>
<tx:annotation-driven />
<!-- 事務管理 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
。。。下面是具體的dataSource配置
或下載附件http://www.aygfsteel.com/Files/yiqi/application-resources.rar
mvn
install:install-file
-DgeneratePom=true
-DgroupId=com.oracle
-DartifactId=ojdbc14
-Dversion=10.2.0.4.0 版本號
-Dpackaging=jar 打包方式
-Dfile=D:\sale_workspace\sale\third_lib\ojdbc-14.jar 本地文件路徑
1、通過對業務流程進行梳理,得出業務流程圖,通過“用戶用例”編寫對業務流程圖進行細化;
2、“用戶用例”的編寫主要目的:用于描述業務現狀,正常情況是怎么樣做的,出現異常了什么做的;不需要考慮“做什么”與“怎么做”,如果該業務的部分操作已經由系統實現,盡可能的規避原有的系統操作,以免被原來的系統框架限制;說簡單一點就是“什么人,在什么情況下,做了什么事,有什么結果”;
3、“系統用例”的編寫目的:主要是根據“用戶用例”分析得出,要系統要“做什么”,需要考慮有什么業務規則,但是該階段仍然不需要考慮怎么做;“系統用例”需要考慮做事要遵循哪些業務規則,提前告知應用設計師,設計時要考慮哪些問題,如何處理異常流程;