第一步、配置实体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>
posted @
2012-06-18 23:24 民工二代 阅读(308) |
评论 (0) |
编辑 收藏
摘要: 在线创建Oracle分区表
第一步,检查源表是否可以在线重定义;
第二步、创建一张分区表做为中间表;
第三步、拷备源表中的记录;
第四步、同步更新数据;
第五步、转换完成
阅读全文
posted @
2012-06-18 09:23 民工二代 阅读(344) |
评论 (0) |
编辑 收藏
最近因为开发需要,自己做了一个小的Demo部署在网上,具体网址
http://www.17chuxing.com,实现一个类似公交查询的功能,目前基本上能够正常运行。
现在总结一下,以便以后查询使用;
一、技术方面
1、demo的整体技术结构采用比较简单的Struts+spring+hibernate,struts 可以定义全局的异常、返回值、拦截器,hibernate采用统一的Spring-hibernate模板进行数据提交,减少开发量。如果采用hiberante懒加载方式,需要手工flush(),web.xml需要增加lazyLoadingFilter;
<filter>
<filter-name>lazyLoadingFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
2、数据量较小采用了mySql作为数据库,采用mysql需要注意的是早期的mysql版本,表名区分大小写,a 与A的结果不一样;
3、在展现层方面采用sitemesh装饰器对展现的页面进行渲染(包括样式、页头、页脚、统计代码),保证每个网页的风格一致性,并且可以减少一定开发工作量;
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
4、采用gzipFilter对请求进行压缩,减少每次请求所需网络流量;
<filter>
<filter-name>gzipFilter</filter-name>
<filter-class>net.sf.ehcache.constructs.web.filter.GzipFilter</filter-class>
</filter>
5、首页尽可能减少跳转(redirect),因为每次跳转都需要一定的时间;
二、部署流程
1、申请域名
2、选择虚拟机托管商
3、部署程序
4、申请备案
三、其他方面;
1、向搜索引擎提交网站
2、其它思考点,通过rewrite 技术实现反写,生成相应的静态文件;
<filter>
<filter-name>rewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<!-- sets up log level (will be logged to context log)
can be: TRACE, DEBUG, INFO (default), WARN, ERROR, FATAL, log4j, commons, sysout:{level} (ie, sysout:DEBUG)
if you are having trouble using normal levels use sysout:DEBUG -->
<init-param>
<param-name>logLevel</param-name>
<param-value>commons</param-value>
</init-param>
<!-- set the amount of seconds the conf file will be checked for reload
can be a valid integer (0 denotes check every time,
-1 denotes no reload check, default -1) -->
<init-param>
<param-name>confReloadCheckInterval</param-name>
<param-value>-1</param-value>
</init-param>
</filter>
posted @
2012-04-25 13:16 民工二代 阅读(514) |
评论 (0) |
编辑 收藏
调试环境:struts,Spring,jsp
第一步:安装插件
在pom.xml文档中增加相应依赖:
<dependency>
<groupId>org.sitemesh</groupId>
<artifactId>sitemesh</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-sitemesh-plugin</artifactId>
<version>2.3.1.2</version>
</dependency>
第二步:配置监听
在web.xml文档中,增加过滤器
<!-- sitemesh 装饰器 -->
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-name>sitemesh</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
第三部:配置装饰器
在WEB-INF文件夹下,新建装饰器配置文档:decorators.xml
文档内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE decorators PUBLIC "-//OpenSymphony//SiteMesh 1.5 Decorators//EN" "
http://www.opensymphony.com/sitemesh/dtd/sitemesh_1_5_decorators.dtd">
<decorators defaultdir="/decorators"><!--文件夹可以修改-->
<!-- 放弃装饰部分 -->
<excludes>
<pattern>/40*.jsp</pattern>
<pattern>/*ajax=true*</pattern>
<pattern>/scripts/dojo/*</pattern>
<pattern>/struts/dojo/*</pattern>
<pattern>/resources/*</pattern>
</excludes>
<!--装饰名称,可以设置多个-->
<decorator name="default" page="default.jsp">
<pattern>*</pattern>
</decorator>
</decorators>
第四步 在WEB-INF文件夹下,新建sitemesh配置文档:sitemesh.xml
<sitemesh>
<property name="decorators-file" value="/WEB-INF/decorators.xml"/>
<excludes file="${decorators-file}"/>
<page-parsers>
<parser default="true" class="com.opensymphony.module.sitemesh.parser.FastPageParser"/>
<parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.FastPageParser"/>
<parser content-type="text/html;charset=ISO-8859-1" class="com.opensymphony.module.sitemesh.parser.FastPageParser"/>
</page-parsers>
<decorator-mappers>
<mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
<param name="config" value="${decorators-file}"/>
</mapper>
</decorator-mappers>
</sitemesh>
第五部:编写装饰模板并引用标签
在<decorators defaultdir="/decorators">指定的文件下,新加模板:default.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page"%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<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>
第五部:测试
期待正确的结果。
posted @
2012-03-15 09:00 民工二代 阅读(1537) |
评论 (0) |
编辑 收藏