一、BOS项目概述
BOS(Business Operating System),业务操作系统,这个项目的是一个企业资源计划平台(ERP)。
1. 开发环境
|
开发环境 |
产品环境 |
操作系统 |
Windows |
Linux/centos |
开发工具 |
eclipse、IDEA |
|
数据库 |
MySQL |
MySQL |
Web容器 |
Tomcat7.0 |
Tomcat7.0 |
浏览器 |
FireFox(firebug)/GOOGLE Chrome/QQBrowser |
|
2. 技术选型
编号 |
工具 |
版本 |
说明 |
1 |
Struts 2 |
2.3.15 |
表现层MVC框架 |
2 |
Hibernate |
3.6.10 |
数据层持久化框架 |
3 |
Spring |
3.2.0 |
业务管理Ioc和AOP框架 |
4 |
Junit |
4 |
单元测试 |
5 |
jQuery |
1.8.3 |
JS框架 |
6 |
jQuery Easy UI |
1.3.2 |
JS前端UI框架 |
7 |
Ztree |
3.5 |
JS树型菜单插件 |
8 |
POI |
3.9 |
Office文档读写组件 |
9 |
Hessian |
4.0.33 |
RMI远程调用 |
10 |
Apache Shiro |
1.2.2 |
权限管理框架 |
11 |
Activiti |
5.13 |
工作流框架 |
二、搭建开发环境
1. 创建数据库环境
- 使用root用户登录MySQL数据库,创建一个数据库;
- 为本项目创建一个数据库用户
1
| create user zhuobo identified by ‘asdf’;
|
- 为新创建的用户授权访问bos数据库
1
| grant all on bos.* to zhuobo;
|
- 使用新的数据库用户登录MySQL
2. 搭建web项目环境
1. 创建动态web项目
项目的目录结构
2. 导入Struts、Spring、Hibernate、数据库驱动等jar包
3. 在web.xml
中配置struts、spring
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <filter> <filter-name>struts</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter>
<filter-mapping> <filter-name>struts</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping>
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param>
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
</web-app>
|
4. 创建struts.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts> <constant name="struts.devMode" value="true" />
<package name="p1" extends="struts-default" namespace="/"> <action name="page_*_*"> <result name="success">/WEB-INF/pages/{1}/{2}.jsp</result> </action> </package> </struts>
|
5. 创建jdbc.properties
1 2 3 4
| driverClass=com.mysql.jdbc.Driver jdbcUrl=jdbc:mysql://localhost:3306/bos user=zhuobo password=asdf
|
6. 创建applicationContext.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| <?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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:property-placeholder location="classpath:jdbc.properties"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${driverClass}"/> <property name="jdbcUrl" value="${jdbcUrl}"/> <property name="user" value="${user}"/> <property name="password" value="${password}"/> </bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="hibernateProperties"> <props> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.connection.autocommit">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> </props> </property> <property name="mappingDirectoryLocations"> <list> </list> </property> </bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean>
<context:component-scan base-package="com.zhuobo.bos"/>
<context:annotation-config/>
<tx:annotation-driven/> </beans>
|
7. 中文乱码问题
在web.xml
中设置guolvqi,使用utf-8编码
web.xml
1 2 3 4 5 6 7 8 9 10 11 12
| <filter> <filter-name>characterEncodingFilter</filter-name>
<filter-class>com.zhuobo.bos.web.filter.MyEncodingFilter</filter-class> </filter>
<filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
|
MyCharacterEncoding.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| public class MyEncodingFilter implements Filter{
@Override public void init(FilterConfig filterConfig) throws ServletException {} @Override public void destroy() {} @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding("UTF-8"); HttpServletRequest hsr = (HttpServletRequest)request; if(hsr.getMethod().equalsIgnoreCase("get")){ MyRequest myRequest = new MyRequest(hsr); chain.doFilter(myRequest, response); }else{ chain.doFilter(request, response); } } }
class MyRequest extends HttpServletRequestWrapper{
private HttpServletRequest request; private boolean isEncoding = false; public MyRequest(HttpServletRequest request) { super(request); this.request = request; } @Override public String getParameter(String name) { return getParameterMap().get(name)[0]; } @Override public Map<String, String[]> getParameterMap() { Map<String, String[]> map = request.getParameterMap(); if(isEncoding == true){ return map; } for(Entry<String, String[]> entry : map.entrySet()){ String[] values = entry.getValue(); for(int i=0;i<values.length;i++){ try { values[i] = new String(values[i].getBytes("ISO-8859-1"),"UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } isEncoding = true; return map; } }
|
三、EasyUI
jQuery EasyUI 是一个基于 jQuery 的框架,集成了各种用户界面插件。
1. JQuery第三方框架的使用
- 下载
- 查看demo
- 查看源码
- 使用源码,修改源码
2. layout布局
3. accordion折叠选项卡
4. tabs选项卡
tabs-tool动态添加选项卡
四、ztree树形插件
ztree是一个jQuery插件
1. 标准JSON数据
- 一个Under List标签
1
| <ul id="tree" class="ztree"></ul>
|
- 配置ztree参数
- 标准json数据
1 2 3 4 5 6 7 8 9
| var zNodes = [ {name:"节点一",children:[ {name:"二级节点一"}, {name:"二级节点二"}, {name:"二级节点三"} ]}, {name:"节点二"}, {name:"节点三"} ];
|
- 初始化ztree生成树
1 2 3
| $(document).ready(function () { $.fn.zTree.init($("#tree"), setting, zNodes); });
|
2. 简单JSON数据
- 配置ztree数据
1 2 3 4 5 6 7 8 9 10
| var setting = { check: { enable: true }, data: { simpleData: { enable: true } } };
|
- 简单json数据
1 2 3 4 5 6 7 8
| var nodes = [ {id:1, pId:0, name: "用户功能"}, {id:11, pId:1, name: "添加用户"}, {id:12, pId:1, name: "删除用户"}, {id:2, pId:0, name: "订单功能"}, {id:12, pId:2, name: "添加订单"}, {id:22, pId:2, name: "删除订单"} ];
|
3. 发送ajax请求获取菜单数据
有时候树形菜单的数据是从数据库中获取的,拼接为JSON数据返回客户端,客户端使用ztree便获取树形菜单。将一个包含json数据的目录拷贝到web
目录下,模拟从数据库中获取的数据。
1 2 3 4 5 6 7 8 9 10 11
|
$(document).ready(function(){ var url = "${pageContext.request.contextPath}/json/menu.json" $.get(url,function (data) { $.fn.zTree.init($("#treeDemo"), setting, data); }) });
|
4. 监听菜单点击事件
点击属性菜单,便新增一选项卡,在setting中可以设置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| var setting = { data: { simpleData: { enable:true, idKey: "id", pIdKey: "pId", rootPId: "" } }, callback:{ onClick:function (event, treeId, treeNode, clickFlag) { if (treeNode.isParent) return;
var tab = $("#tt").tabs("exists", treeNode.name); if (tab) { $("#tt").tabs("select", treeNode.name); } else { $('#tt').tabs('add',{ title: treeNode.name, content: '<div>'+treeNode.name+'</div>', closable: true }); } } } };
|