首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

SSI调整-搭建Struts2+Spring+Ibatis框架 带源码

2012-07-01 
SSI整合--搭建Struts2+Spring+Ibatis框架 带源码Struts2+Spring+ibatis是J2EE的最新流行框架。以下是部分搭

SSI整合--搭建Struts2+Spring+Ibatis框架 带源码

Struts2+Spring+ibatis是J2EE的最新流行框架。

以下是部分搭建过程及源码:

1.先组合实现ibatis+Spring3支持,删除hibernate.cfg.xml文件,修改applicationContext.xml文件的内容,增加SessionFactory和dataSource的设置。

2.通过MyEclipse的向导方式,生成POJO类和对应的映射文件。

3.修改applicationContext.xml文件中<property name="mappingResources">元素的内容。

4.编写DAO接口和实现类。

5.修改applicationContext.xml文件,增加对Dao实现类的配置。

6.组合Struts2和Spring3,修改web.xml文件,增加struts2的所需要的过滤器配置。

7.增加struts2相应类库,增加struts2与spring的配置jar包。

8.拷贝struts.xml文件到src根目录下,再修改struts.xml文件,进行常量配置。

9.修改web.xml文件,配置Spring监听器,和上下文变量。并增加OpenSessionInViewFilter的设置。

10.写入action类。

11.配置struts.xml文件。

12.修改applicationContext.xml

13.编写Jsp文件。

14.加载运行项目。

?

1.文档说明:

我的Csdnhttp://blog.csdn.net/zl563143188

spring3.1 http://static.springsource.org/spring/docs/3.1.0.M2/spring-framework-reference/html/
struts2 http://struts.apache.org/2.x/docs/home.html
hibernate http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/
这是我的QQ空间,欢迎参观 http://user.qzone.qq.com/563143188

程序源码下载地址10MB:http://115.com/file/c2re58pm#

最新程序源码下载地址,一直在更新中............................... http://zz563143188.iteye.com/blog/1462413

程序lib下载地址100MB:http://115.com/file/c2re52n6#

数据库下载地址(可以将数据转为sql,或者mysql,默认access)http://115.com/file/andcz97r#

由于涉及技术比较多,一般很难运行成功,需要技术指导联系 QQ 563143188,电话 13823045912 张林

Struts2、Spring、Hibernate三者整合的过程示例

SSH简单整合(Struts2.2.3.1+Spring3.1.0+Hibernate4)

Struts2+Spring+Hibernate搭建全解!

Hibernate4 Struts2 Spring3整合

?

功能介绍:

1.支持 Hibernate连接AccessHibernate连接sqlsever Hibernate连接mysql

2.支持 Spring连接access数据库 spring连接mysql spring连接sqlsever数据库

3.支持 Spring动态数据源加载 Spring连接ibaits Spring JDBC连接

4.支持 Spring的事务管理 Spring AOP实现 Spring的权限管理

5.支持 Spring MVC及Spring国际化标签 Spring文件上传下载

6.支持 Spring 数据源加载属性文件

7.支持 struts2+hibernate4+spring3 及struts2+itbaits+spring设计结构

8.支持 ext+json+treepanel实现动态树

9.支持 jasperreport+ireport+excel打印

10.支持 freemarker 生成文件

11.支持 sitemesh修饰网站

12. 支持oscahe缓存 hibernate+ehcache缓存

13. 支持 struts2国际化

14 支持 velocity模板设计

15.支持 ext+dwr+json处理数据

16.支持 jquery图表制作

17.支持 log4j日志处理

18.支持 hibernate与ibaits同时访问数据库

19.支持 java读dll,ocx控制

20.支持 SSH、SSI框架同时使用

21.支持 Spring实时调度任务

22.支持随意更改BaseDaoImpl<T extends BaseModel,PK extends BasePK> extends BaseDaoIbaSpringImpl<T,PK>

二.下面是具体的代码实现:

1.顶层DAOp实现 :BaseDaoIbaSpringImpl
package com.senlo.analyze.core.common.dao.Impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.senlo.analyze.core.common.bean.BaseModel;
import com.senlo.analyze.db.impOrExp.bean.TableBean;

@Repository
public class BaseDaoIbaSpringImpl<T extends BaseModel> extends
SqlMapClientDaoSupport {
private String namespace;

@Autowired
@Resource(name = "sqlMapClient")
private SqlMapClient sqlMapClient;

@PostConstruct
public void initSqlMapClient() {
super.setSqlMapClient(sqlMapClient);
}

public int getCount(String and) {
int count = 0;
try {
Object obj = getSqlMapClientTemplate().queryForObject(
namespace + ".getCount", and);
if (obj != null)
count = Integer.parseInt(obj + "");
} catch (Exception e) {
System.out.println(namespace + ".getCount(String)异常"
+ e.getMessage());
}
return count;
}

public int getMaxId(String and) {
int count = 0;
try {
Object obj = getSqlMapClientTemplate().queryForObject(
namespace + ".getMaxId", and);
if (obj != null)
count = Integer.parseInt(obj + "");
} catch (Exception e) {
System.out.println(namespace + ".getMaxId(String)异常"
+ e.getMessage());
}
return count;
}

public List<T> getList(String and) {
List<T> list = new ArrayList<T>();
try {

list = getSqlMapClientTemplate().queryForList(
namespace + ".getList", and);
} catch (Exception e) {
System.out.println(namespace + ".getList(" + and + ")异常!"
+ e.getMessage());
}
return list;
}

@SuppressWarnings("unchecked")
public List<T> getPageList(String and, int pageSize, int pageNo) {
List<T> list = new ArrayList<T>();
try {
int startIndex = (pageNo - 1) * pageSize;
list = getSqlMapClientTemplate().queryForList(
namespace + ".getList", and, startIndex, pageSize);
} catch (Exception e) {
System.out.println(namespace + ".getList(" + and + ")异常!"
+ e.getMessage());
}
return list;
}

/*
* @SuppressWarnings("unchecked") public List<T> getRowList(String and, int
* pageSize, int pageNo) { List<T> list = new ArrayList<T>(); try { int
* startIndex = (pageNo - 1) * pageSize; list =
* client.queryForList(namespace + ".getList", and , startIndex, pageSize);
* } catch (Exception e) { epln(namespace + ".getList(" + and + ")异常!" +
* e.getMessage()); } return list; }
*/
@SuppressWarnings("unchecked")
public List<T> getRowList(String and, int pageSize, int pageNo) {
List<T> list = new ArrayList<T>();
try {
int startIdx = (pageNo - 1) * pageSize;
int endIdx = pageNo * pageSize;
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("condition", and);
map.put("startIdx", startIdx);
map.put("endIdx", endIdx);
list = getSqlMapClientTemplate().queryForList(
namespace + ".getRowList", map);
} catch (Exception e) {
System.out.println(namespace + ".getRowList(" + and + ")异常!"
+ e.getMessage());
}
return list;
}

public List<TableBean> getListBySQL(String Sql) {
List<TableBean> list = new ArrayList<TableBean>();
try {
list = getSqlMapClientTemplate().queryForList(
namespace + ".getListBySQL", Sql);
} catch (Exception e) {
System.out.println(namespace + ".getListBySQL(" + Sql + ")异常!"
+ e.getMessage());
}
return list;
}

public int deleteByAnd(String and) {
int cnt = 0;
try {
cnt = getSqlMapClientTemplate().delete(namespace + ".delete", and);
} catch (Exception e) {
System.out.println(namespace + ".deleteByAnd(" + and + ")异常!"
+ e.getMessage());
}
return cnt;
}

public boolean updateById(T bean) {
boolean flag = false;
try {
flag = getSqlMapClientTemplate().update(namespace + ".updateById",
bean) > 0;
} catch (Exception e) {
System.out.println(namespace + ".updateById(" + bean + ")异常!"
+ e.getMessage());
}
return flag;
}

public T getBeanById(String id) {
T bean = null;
List<T> list = getList(" and fid='" + id + "'");
if (list.size() > 0) {
bean = list.get(0);
}
return bean;
}

public String insert(T bean) {
try {
getSqlMapClientTemplate().insert(namespace + ".insert", bean);
return "1";
} catch (Exception e) {
System.out.println(namespace + ".insert(" + bean + ")异常!"
+ e.getMessage());
return "0";
}
}

public String getNamespace() {
return namespace;
}

public void setNamespace(String namespace) {
this.namespace = namespace;
}

}


2.顶层IBaseDao接口
public interface IBaseIbaDao<M extends BaseModel> {
public int getMaxId(String and);

public int getCount(String and);

public List<M> getList(String and);

@SuppressWarnings("unchecked")
public List<M> getPageList(String and, int pageSize, int pageNo);

public String insert(M bean);

public M getBeanById(String id);

public boolean updateById(M bean);

public int deleteByAnd(String and);

public List<M> getRowList(String and, int pageSize, int pageNo);
}


3.与顶层DAO的中间层类BaseDaoImpl
package com.senlo.analyze.core.common.dao.Impl;
//BaseHibernateDaoImpl,BaseHibernateSpringDaoImpl,BaseDaoIbaImp,BaseDaoIbaSpringImp
//BaseHibernate4SpringDaoImpl,BaseHibernate3SpringDaoImpl 方法与数据连接
public class BaseDaoImpl<T extends BaseModel,PK extends BasePK> extends BaseDaoIbaSpringImp <T,PK> {}

4.具体的DAO层接口
package com.senlo.analyze.main.dao;

import com.senlo.analyze.core.common.dao.IBaseIbaDao;
import com.senlo.analyze.main.bean.SampleResult;

public interface SampleResultIbaDao extends IBaseIbaDao<SampleResult> {

}


5.具体的DAO层实现 BaseDaoImpl
package com.senlo.analyze.main.dao.Impl;

import org.springframework.stereotype.Repository;

import com.senlo.analyze.core.common.dao.Impl.BaseDaoIbaSpringImpl;
import com.senlo.analyze.main.bean.SampleResult;
import com.senlo.analyze.main.dao.SampleResultIbaDao;
import com.senlo.analyze.main.service.SampleResultSvr;

@Repository ("sampleResultIbaDaoImpl")
public class SampleResultIbaDaoImpl extends BaseDaoIbaSpringImpl<SampleResult>
implements SampleResultIbaDao {

public SampleResultIbaDaoImpl() {
super.setNamespace("sampleResult");
}

}

5.ibaits的sampleResult的xml文件,与数据库对应

<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE sqlMap
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="sampleResult">
<resultMap id="sampleResult_map" column="fid" />
<result property="item" column="item" />
<result property="fullName" column="fullName" />
<result property="itemResult" column="itemResult" />
<result property="reRange" column="reRange" />
<result property="unit" column="unit" />
<result property="prompt" column="prompt" />
<result property="sampleTrayID" column="sampleTrayID" />
<result property="sampleLocation" column="sampleLocation" />
<result property="testDate" column="testDate" />
<result property="remark" column="remark" />
<result property="isReTest" column="isReTest" />
<result property="testMomentSign" column="testMomentSign" />
<result property="reTestSign" column="reTestSign" />
<result property="itemID" column="itemID" />
<result property="reagentTrayID" column="reagentTrayID" />
<result property="modifySign" column="modifySign" />
<result property="modifyTime" column="modifyTime" />
<result property="originalityResult" column="originalityResult" />
<result property="modifyUserName" column="modifyUserName" />
<result property="testResult" column="testResult" />
<result property="reactionChroma" column="reactionChroma" />

</resultMap>
<select id="getMaxId" resultresultresultMap="sampleResult_map"
parameterresultMap="sampleResult_map"
parameterresultMap="sampleResult_map"
parameterparameterparameterparameterparameterparameter})
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
public class TIbatisDao {
@Autowired
// SampleResultSvr dao;
MenuSvr svr;

@Test
public void showData() {
String sql = "";
// List<SampleResult> list = dao.getList(sql);
// System.out.println(list.size() + "------ibaits");
// List<Menu> list2 = dao2.FindAll();
// System.out.println(list2.size());
}

@Test
public void tree() {
ArrayList<JSONTreeNode> TreeNodeArray = null;
StringBuffer parentIDBuffer = new StringBuffer();

List<Menu> listPID = svr.FindAll(" and leaf=0 ");
parentIDBuffer.append("|");

// parentIDBuffer.append(listPID.get(i).getText());// 这里是取得父结点

String parentIDString = parentIDBuffer.toString();
List<Menu> listLeaf = svr.FindAll(" and 1=1 ");
TreeNodeArray = new ArrayList<JSONTreeNode>();

for (int i = 0; i < listPID.size(); i++) {

for (int j = 0; j < listLeaf.size(); j++) {
Menu mBean = listLeaf.get(j);
JSONTreeNode TreeNode = new JSONTreeNode();
TreeNode.setId(mBean.getFid());
TreeNode.setText(mBean.getText());
TreeNode.setDescription(mBean.getRemark());
TreeNode.setHref(mBean.getHref()); // TreeNode.setId
TreeNode.setHrefTarget(mBean.getHrefTarget());
if (listPID.get(i).getFid() != listLeaf.get(j).getPid()) //子节点
// //TreeNode.setId
{
TreeNode.setCls("folder");
TreeNode.setLeaf(false);
TreeNode.setExpandable(false);
} else // 父节点
{

TreeNode.setCls("file");
TreeNode.setLeaf(true);
TreeNode.setExpandable(false);
}
TreeNodeArray.add(TreeNode);
}
}

JSONArray JsonArray = JSONArray.fromObject(TreeNodeArray); // 得到JSON数组

System.out.println(JsonArray.toString());

}
}

由于配置文件太多 详细说明:http://zz563143188.iteye.com/admin/blogs/1462413

1 楼 lsd1830 2012-06-22   你好,想学习下SSI,资料挺好,但代码无资料链接了,能否发一份给我:747490952@qq.com
万福!

热点排行