SSI框架整合流程.doc_第1页
SSI框架整合流程.doc_第2页
SSI框架整合流程.doc_第3页
SSI框架整合流程.doc_第4页
SSI框架整合流程.doc_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

SSI+memcached整合详解使用架构细则ibatis-26+spring-framework-3.1.1+struts-+memcached框架详解所包含的jarantlr.jar, aopalliance.jar, aspectjweaver.jar, bonecp-0.7.1-rc2.jar, cglib-nodep-2.1_3.jar, commons-collections-3.1.jar, commons-fileupload-1.2.2.jar, commons-io-2.0.1.jar, commons-lang-2.5.jar, commons-logging.jar, commons-pool-1.3.jar, dom4j-1.6.1.jar, freemarker-2.3.18.jar, freemarker-2.3.18.jar, guava-11.0.2.jar, ibatis-26.jar, javassist-3.11.0.GA.jar, json-lib-2.1-jdk15.jar, jstl-1.2.jar, jta.jar, jxl.jar, log4j-1.2.16.jar, mysql-connector-java-5.1.7-linux-bin.jar, ognl-3.0.4.jar, org.springframework.aop-3.1.1.RELEASE.jar, org.springframework.asm-3.1.1.RELEASE.jar, org.springframework.beans-3.1.1.RELEASE.jar, org.springframework.context-3.1.1.RELEASE.jar, org.springframework.core-3.1.1.RELEASE.jar, org.springframework.expression-3.1.1.RELEASE.jar, org.springframework.jdbc-3.1.1.RELEASE.jar, org.springframework.orm-3.1.1.RELEASE.jar, org.springframework.transaction-3.1.1.RELEASE.jar, org.springframework.web-3.1.1.RELEASE.jar, slf4j-api-1.6.2.jar, spy-2.4.jar, spymemcached-2.8.1.jar, struts2-core-.jar, struts2-json-plugin-.jar, struts2-spring-plugin-.jar, xwork-core-.jarStruts一:构建框架1:在web.xml中配置struts的拦截器struts2org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 /*2:典型的Struts配置文件(struts.xml)-引入其他status文档-配置userAction,class对应Spring配置的bean的ID,method对应要调用的方法,result声明方法返回值到跳转的页面或者要返回的数据类型1.htmllogin.jsp3:与配置信息对应的Action类(UserAction):package action;import org.apache.struts2.ServletActionContext;import iservice.IUserService;import com.opensymphony.xwork2.ActionSupport;import com.rdg.model.UserInfo;public class UserAction extends ActionSupport -定义用户Idprivate String userId;-定义用户密码private String userPass;-定义新闻排序方式private String newsOrder;-声明UserService,具体实现见后续章节中的Spring部分private IUserService UserService;public void setUserService(IUserService userService) UserService = userService;public String getUserId() return userId;public void setUserId(String userId) this.userId = userId;public String getUserPass() return userPass;public void setUserPass(String userPass) this.userPass = userPass;public void setNewsOrder(String newsOrder) this.newsOrder = newsOrder;public String getNewsOrder() return newsOrder;-验证用户登录,方法名为执行成功后的跳转页面public String index()try UserInfo user=new UserInfo();user.setId(userId);user.setPass(userPass);UserInfo newUser=UserService.userLogin(user);ServletActionContext.getRequest().getSession().setAttribute(user, newUser);if(newUser!=null)return SUCCESS;elsereturn ERROR; catch (Exception e) / TODO Auto-generated catch blocke.printStackTrace();return ERROR;public String UNOrder()UserInfo user=new UserInfo();user.setId(UserInfo)ServletActionContext.getRequest().getSession().getAttribute(user).getId();user.setNewsOrder(newsOrder);return UserService.updateUser(user);Spring一:构建框架1:在web.xml中配置spring的监听和字符集过滤,默认过滤为utf8 org.springframework.web.context.ContextLoaderListener contextConfigLocation classpath:applicationContext*.xml -字符集过滤 characterEncodingFilterorg.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 2:典型的spring配置文件配置pool数据源和依赖注入-数据源名称和类-数据源驱动 -连接URL -数据库用户名 -数据库密码 -设置connection的空闲存活时间 -设置测试connection的间隔时间 -每个分区的最大连接数 -每个分区的最小连接数 -设置分区个数-设置分区中的connection增长数量 -设置statement缓存个数 -设置connection助手线程个数 -将数据源注入dao的属性中 -数据库交互类集成dao类,则可直接使用数据源-将dao类注入到service的属性中-将service注入到Action中3: spring配置文件中用到的类-userDao类(扩展自UserInfoDAOImpl,UserInfoDAOImpl中定义基本的方法,扩展中定义扩展方法,在扩展中注入dao进行操作)package com.rdg.dao.impl;import com.rdg.dao.base.UserInfoDAOImpl;public class UserInfoDAO extends UserInfoDAOImpl -调用父类的构造方法public UserInfoDAO() / TODO Auto-generated constructor stubsuper();-userService类package service;import iservice.IUserService;import java.util.List;import net.spy.memcached.MemcachedClient;import com.rdg.dao.base.UserInfoDAO;import com.rdg.model.UserInfo;import com.rdg.model.UserInfoExample;public class UserInfoManager implements IUserService private UserInfoDAO userDao;private MemcachedClient memcachedClient;public void setMemcachedClient(MemcachedClient memcachedClient) this.memcachedClient = memcachedClient;public void setUserDao(UserInfoDAO userDao) this.userDao = userDao;-验证用户登录public UserInfo userLogin(UserInfo user) UserInfo users=userDao.selectByPrimaryKey(user.getId();if(user!=null)return users;elsereturn null;-更新用户信息public String updateUser(UserInfo user) tryUserInfoExample ue=new UserInfoExample();ue.createCriteria().andIdEqualTo(user.getId();int i=userDao.updateByExampleSelective(user, ue);userDao.updateByPrimaryKeySelective(user);return list;catch(Exception e)e.printStackTrace();return error;- userAction类package action;import org.apache.struts2.ServletActionContext;import iservice.IUserService;import com.opensymphony.xwork2.ActionSupport;import com.rdg.model.UserInfo;public class UserAction extends ActionSupport private String userId;private String userPass;private String newsOrder;private IUserService UserService;public void setUserService(IUserService userService) UserService = userService;public String getUserId() return userId;public void setUserId(String userId) this.userId = userId;public String getUserPass() return userPass;public void setUserPass(String userPass) this.userPass = userPass;public void setNewsOrder(String newsOrder) this.newsOrder = newsOrder;public String getNewsOrder() return newsOrder;-验证用户登录,方法名为登录后的跳转页面public String index()try UserInfo user=new UserInfo();user.setId(userId);user.setPass(userPass);UserInfo newUser=UserService.userLogin(user);ServletActionContext.getRequest().getSession().setAttribute(user, newUser);if(newUser!=null)return SUCCESS;elsereturn ERROR; catch (Exception e) / TODO Auto-generated catch blocke.printStackTrace();return ERROR;-修改用户信息public String UNOrder()UserInfo user=new UserInfo();-从用户登录时存入session中的用户信息中取出用户Iduser.setId(UserInfo)ServletActionContext.getRequest().getSession().getAttribute(user).getId();-修改用户实体信息user.setNewsOrder(newsOrder);-调用修改方法return UserService.updateUser(user);Ibatis一:构建框架1:Ibatis基础配置信息(pool方式)(1) 配置数据源bean(这里仍以与spring IOC集成方式为例)-数据源名称和类,此处为使用连接池连接,class使用的是连接池数据源-数据源驱动,此处使用的是mysql数据库,加载mysql的数据库驱动包 -连接URL,这里使用的是mysql的连接字符串,主机地址为localhost,数据库名为test -数据库用户名 -数据库密码 -设置connection的空闲存活时间 -设置测试connection的间隔时间 -每个分区的最大连接数 -每个分区的最小连接数 -设置分区个数-设置分区中的connection增长数量 -设置statement缓存个数 -设置connection助手线程个数 -将数据源注入dao的属性中 -数据库交互类集成dao类,则可直接使用数据源以上就是Ibatis使用连接池连接MySql数据库的配置信息,将配置好的数据源注入dao类则可使用,Ibatis使用方法常用的分为两种,一种是使用Ibatis官方提供的程序自动生成类,只需在service中调用生成好的dao类的各个方法即可实现数据库的增删改查等常用操作,另一种是手动创建各个配置文件与编写映射等SQL语句,此处以手动创建为例做说明(2):创建核心配置文件(sql-map-config.xml) -配置实体类与数据库的映射XML路径(3):创建和数据库对应的实体类package com.rdg.model;import com.rdg.model.base.UserInfoBase;import java.io.Serializable;public class UserInfo extends UserInfoBase implements Serializable private String id; private String pass; private String newsOrder; private static final long serialVersionUID = 1L; public String getId() return id; public void setId(String id) this.id = id; public String getPass() return pass; public void setPass(String pass) this.pass = pass; public String getNewsOrder() return newsOrder; public void setNewsOrder(String newsOrder) this.newsOrder = newsOrder;(4):创建实体类与数据库的映射XML(user_info_SqlMap.xml) -命名空间-配置实体类与数据库字段映射map -查询数据库的SQL语句,返回值为User实体-更新用户newsorder的SQL语句,返回值为int类型(5):在dao层中的应用,调用父类的方法和配置文件中配置的方法名来调用进行各种数据库的操作,这是基础操作的类,注入dao的类是继承自这个类的,具体说明见Spring部分package com.rdg.dao.base;import com.rdg.model.UserInfo;import com.rdg.model.UserInfoExample;import java.util.List;import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;public class UserInfoDAOImpl extends SqlMapClientDaoSupport implements UserInfoDAO public UserInfoDAOImpl() super(); public int countByExample(UserInfoExample example) Integer count = (Integer) getSqlMapClientTemplate().queryForObject(user_info.countByExample, example); return count; public int deleteByExample(UserInfoExample example) int rows = getSqlMapClientTemplate().delete(user_info.deleteByExample, example); return rows; public int deleteByPrimaryKey(String id) UserInfo _key = new UserInfo(); _key.setId(id); int rows = getSqlMapClientTemplate().delete(user_info.deleteByPrimaryKey, _key); return rows; public String insert(UserInfo record) Object newKey = getSqlMapClientTemplate().insert(user_info.insert, record); return (String) newKey; public String insertSelective(UserInfo record) Object newKey = getSqlMapClientTemplate().insert(user_info.insertSelective, record); return (String) newKey; SuppressWarnings(unchecked) public List selectByExample(UserInfoExample example) List list = getSqlMapClientTemplate().queryForList(user_info.selectByExample, example); return list; public UserInfo selectByPrimaryKey(String id) UserInfo _key = new UserInfo(); _key.setId(id); UserInfo record = (UserInfo) getSqlMapClientTemplate().queryForObject(user_info.selectByPrimaryKey, _key); return record; public int updateByExampleSelective(UserInfo record, UserInfoExample example) UpdateByExampleParms parms = new UpdateByExampleParms(record, example); int rows = getSqlMapClientTemplate().update(user_info.updateByExampleSelective, parms); return rows; public int updateByExample(UserInfo record, UserInfoExample example) UpdateByExampleParms parms = new UpdateByExampleParms(record, example); int rows = getSqlMapClientTemplate().update(user_info.updateByExample, parms); return rows; public int updateByPrimaryKeySelective(UserInfo record) int rows = getSqlMapClientTemplate().update(user_info.updateByPrimaryKeySelective, record); return rows; public int updateByPrimaryKey(UserInfo record) int rows = getSqlMapClientTemplate().update(user_info.updateByPrimaryKey, record); return rows; protected static class UpdateByExampleParms extends UserInfoExample private Object record; public UpdateByExampleParms(Obj

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论