`
javawhf
  • 浏览: 7196 次
  • 性别: Icon_minigender_1
  • 来自: 广州
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

也谈我开发SSH框架

阅读更多
下面是本人在业余时间搞的框架的简要介绍,无所谓推广,跟大家一起分享和交流
1.可视化代码生成工具,参考界面
基本原理还是从数据库中生成出来,目前支持mysql和Oracle的数据源,支持外键生成many-to-one关系,可以生成元数据,参考下面元数据介绍;
2.元数据
对象的基本属性,合法性和其他的一些扩展属性的描述,生成代码时可以根据数据库的定义生成,如:数据库字段注释,类型等;
可以用来描述界面,获取关联对象等;
3.RBAC的角色权限控制,并集成ACEGI
4.日志,Lucene等等

详细参考开源http://code.google.com/p/whfframework
分享到:
评论
5 楼 abs1285 2012-07-05  
 
import whf.framework.entity.AbstractEntity; 
import whf.framework.tools.generator.db.Column; 
import whf.framework.tools.generator.db.Table; 
import whf.framework.util.BeanUtils;

这些都需要whfframework 的jar包啊,从哪里可以下载,或提供一下
4 楼 sun_soledad 2009-02-05  
好东西,记号
3 楼 javawhf 2008-09-02  
对于实体,从数据库中的描述即可,如下代码:
package whf.framework.tools.generator;

import whf.framework.entity.AbstractEntity;
import whf.framework.tools.generator.db.Column;
import whf.framework.tools.generator.db.Table;
import whf.framework.util.BeanUtils;

/**
 * @author wanghaifeng
 *
 */
public class EntityGenerator extends AbstractGenerator {
	private String packageName;

	private String className;

	private String[] props;

	private String[] types;
	
	private Table table;

	public EntityGenerator(String packageName, String className, String[] types, String[] props) {
		this.packageName = packageName;
		this.className = className;
		this.types = types;
		this.props = props;
	}

	public EntityGenerator(String packageName, Table table) {
		this.packageName = packageName;
		this.table = table;
	}

	public String[] getProps(){
		return this.props;
	}
	
	protected void gen() {
		super.setPackageName(this.packageName+".entity");
		super.setSuperClassName(AbstractEntity.class.getName());
		super.setImplementsSerializable(true);
//		super.setInterfaces(new String[]{"I"+this.table.getBoClassName()});
		if(table == null){
			super.setClassName(this.className);
			for (int i = 0; props != null && i < props.length; i++) {
				if(!BeanUtils.hasProperty(AbstractEntity.class, props[i])){
					super.addProp(types[i], props[i],true, true, props[i]);
				}
			}
		} else {
			super.setClassName(table.getBoClassName());
			for(Column col: table.getColumns()){
				String pn = col.getPropertyName();
				if(!BeanUtils.hasProperty(AbstractEntity.class, pn)){
					super.addProp(col.getPropertyType(), col.getPropertyName(), true, true, col.getColumnComment());
//					if(!col.isForeign()){
//						super.addProp(col.getPropertyType(), pn,true, true);
//					}else{
//						String refTableName = col.getReferencedTable();
//						String refBo = Utils.getBoClassName(refTableName, table.getTablePre());
//						String dt = this.packageName+".entity."+refBo;
//						String p = pn;
//						if(p.toLowerCase().endsWith("id")){
//							p = p.substring(0, p.length() - 2);
//						}
//						super.addProp(dt, p, true, true);
//					}
				}
			}
		}
	}

	public static void main(String[] args) throws Exception {

	}
}

对于其他使用模板,如下:
<?xml version="1.0" encoding="UTF-8"?>
<root>
	<comment>
		<![CDATA[
		{0}:boClassName
		{1}:bo variable
		{2}:rootPackage
		{3}:tableName
		{4}:subModule
		{5}:now
		{6}:IBOClassName
		]]>
	</comment>
	<java>
		<bo></bo>
		<dao>
		<![CDATA[
package {2}.dao;

import {2}.entity.{0};

/**
 * 数据访问对象接口
 * @author wanghaifeng
 * @email king@126.com
 * @modify {5}
 */
public interface {0}DAO extends whf.framework.dao.DAO<{0}> {

}
		]]>
		</dao>
		<daoImp>
		<![CDATA[
package {2}.dao;

import {2}.entity.{0};

/**
 * 数据访问对象具体实现
 * @author wanghaifeng
 * @email king@126.com
 * @modify {5}
 */
public class {0}DAOImp extends whf.framework.dao.DAOImp<{0}> implements {0}DAO {

}
		]]>
		</daoImp>
		<service>
		<![CDATA[
package {2}.service;

import {2}.entity.{0};

/**
 * 服务对象接口
 * @author wanghaifeng
 * @email king@126.com
 * @modify {5}
 */
public interface {0}Service extends whf.framework.service.Service<{0}> {

}
		]]>
		</service>
		<serviceImp>
		<![CDATA[
package {2}.service;

import whf.framework.exception.ServiceNotFoundException;
import {2}.entity.{0};
import {2}.dao.{0}DAO;
import whf.framework.util.BeanFactory;

/**
 * 服务对象具体实现,委托相应的dao对象实现相关操作
 * @author wanghaifeng
 * @email king@126.com
 * @modify {5}
 */
public class {0}ServiceImp extends whf.framework.service.ServiceImp<{0}> implements {0}Service {
	public void set{0}DAO({0}DAO {1}DAO) {
		this.entityDAO = {1}DAO;
	}
	
	/**
	 * 静态的简单的服务获取方法
	 */
	public static {0}Service get{0}Service() throws ServiceNotFoundException {
		return ({0}Service)BeanFactory.getService({0}ServiceImp.class) ;
	}
}
		]]>
		</serviceImp>
		<webservice>
		<![CDATA[
package {2}.webservice;

import javax.jws.WebService;

import {2}.entity.{6};

import whf.framework.exception.CreateException;
import whf.framework.exception.NotFoundException;
import whf.framework.exception.RemoveException;
import whf.framework.exception.UpdateException;

/**
 * web服务接口,定义远程服务可以使用的方法
 * @author wanghaifeng
 * @email king@126.com
 * @modify {5}
 */
@WebService(targetNamespace="http://whf.framework/{0}Service")
public interface {0}ServiceWS {

	public void create({6} {1}) throws CreateException;

	public void update({6} {1}) throws UpdateException;

	public void remove({6} {1}) throws RemoveException;

	public void remove(long id) throws RemoveException;

	public void remove(long[] ids) throws RemoveException;

	public {6} findByPrimaryKey(long id) throws NotFoundException;

}
		]]>
		</webservice>
		<webserviceImp>
		<![CDATA[
package {2}.webservice;

import javax.jws.WebService;

import {2}.entity.{6};
import {2}.service.{0}Service;

import whf.framework.exception.CreateException;
import whf.framework.exception.NotFoundException;
import whf.framework.exception.RemoveException;
import whf.framework.exception.UpdateException;

/**
 * web服务的实现,委托具体的本地服务类实现相关操作
 * @author wanghaifeng
 * @email king@126.com
 * @modify 2006-10-31
 */
@WebService(serviceName = "{0}Service", endpointInterface = "{2}.service.{0}ServiceWS")
public class {0}ServiceWSImp implements {0}ServiceWS {
	/**
	 * 委托服务
	 */
	private {0}Service service;

	public void setService({0}Service service) {
		this.service = service;
	}

	public void create({6} {1}) throws CreateException {
		this.service.create({1});
	}

	public void update({6} {1}) throws UpdateException {
		this.service.update({1});
	}

	public void remove({6} {1}) throws RemoveException {
		this.service.remove({1});
	}

	public void remove(long id) throws RemoveException {
		this.service.remove(id);
	}

	public void remove(long[] ids) throws RemoveException {
		this.service.remove(ids);
	}

	public {6} findByPrimaryKey(long id) throws NotFoundException {
		return this.service.findByPrimaryKey(id);
	}
} 
		]]>
		</webserviceImp>
		<dispatch-action>
		<![CDATA[
package {2}.web;

import whf.framework.web.struts.WebDispatchAction;

/**
 * @author wanghaifeng
 * @email king@126.com
 * @modify {5}
 */
public class {0}Action extends WebDispatchAction {

}
		]]>
		</dispatch-action>
	</java>
	<xml>
		<meta>
		<![CDATA[
	<meta package="{2}"> 
		<rowsPerPage>10</rowsPerPage>
		<name>{0}</name>
		<description/>
		<serviceName>{0}Service</serviceName>
		<daoName>{0}DAO</daoName>
		<modelClass>{0}</modelClass>
		<actionClass>{0}Action</actionClass>
		<serviceClass>{0}ServiceImp</serviceClass>
		<daoClass>{0}DAOImp</daoClass>
		<persistenceTable>{3}</persistenceTable>
		<parentModelClass/>
	</meta> 
		]]>
		</meta>
		<spring>
	<![CDATA[
	<bean id="{4}.{0}DAO" class="{2}.dao.{0}DAOImp">
		<property name="daoSupport">
			<ref bean="daoSupport"/>
		</property>
	</bean>
	<bean id="{4}.{0}Service" parent="txProxyTemplate">
		<property name="transactionManager">
			<ref bean="transactionManager"/>
		</property>
		<property name="target">
			<bean id="{4}.{0}ServiceTarget" class="{2}.service.{0}ServiceImp">
				<property name="{1}DAO">
					<ref bean="{4}.{0}DAO"/>
				</property>
			</bean>
		</property>
	</bean>
	]]>
		</spring>
		<spring2>
		<![CDATA[
	<bean id="{0}DAO" class="{2}.dao.{0}DAOImp"> 
		<property name="sessionFactory"><ref bean="sessionFactory"/></property> 
	</bean> 
	<bean id="{0}Service" parent="txProxyTemplate"> 
		<property name="target"> 
			<bean class="{2}.service.{0}ServiceImp"> 
				<property name="{1}DAO"><ref bean="{0}DAO"/></property> 
			</bean> 
		</property>
	</bean> 
		]]>
		</spring2>
		<hibernate></hibernate>
		<struts>
		<![CDATA[
	<form-bean name="{4}{0}Form" 	type="{2}.entity.{0}"/> 

	<action path="/{4}/{0}" type="{2}.web.{0}Action" name="{4}{0}Form" scope="request" parameter="webMethod" validate="true">
		<forward name="list" 	path="/common/global/list_jsp"/>
		<forward name="edit" 	path="/common/global/edit_jsp"/>
		<forward name="view" 	path="/common/global/view_jsp"/>
	</action>
		]]>
		</struts>
		<webservice>
		<![CDATA[
	<bean id="{0}WS" class="org.codehaus.xfire.spring.remoting.XFireExporter">
        <property name="serviceFactory">
            <ref bean="xfire.serviceFactory"/>
        </property>
        <property name="xfire">
            <ref bean="xfire"/>
        </property>
        <property name="serviceBean">
            <ref bean="{0}Service"/>
        </property>
        <property name="serviceClass">
            <value>{2}.service.{0}ServiceWSImp</value>
        </property>
    </bean>
		]]>
		</webservice>
	</xml>
	<jsp>
		<edit>
		<![CDATA[
<%@page contentType="text/html;charset=UTF-8"%>
<%@ page import="whf.framework.web.Constants"%>

<%@taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/tlds/framework.tld" prefix="framework"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><bean:write name="STRUTS-META" property="name" /></title>
<jsp:include page="/inc/select.jsp" />
</head>
<body>

<html:form action="<%=  (String)request.getAttribute(Constants.STRUTS_PATH) %>" method="post">
<html:hidden property="webMethod" />
<framework:ext />
<framework:table pkStyle="" navPosition="none" pageSize="1" displayStyle="form" editable="true" useStrutsForm="true">
<framework:caption><span class="whf_object_title"><framework:attr source="STRUTS-META" attr="name" /></span></framework:caption>
</framework:table>
<html:submit><bean:message key="form.submit" /></html:submit>
<html:reset><bean:message key="form.reset" /></html:reset>
</html:form>

</body>
</html> 
		]]>
		</edit>
		<list>
		<![CDATA[
<%@page contentType="text/html;charset=UTF-8"%>
<%@ page import="whf.framework.web.Constants"%>

<%@taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/tlds/framework.tld" prefix="framework"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><framework:attr source="STRUTS-META" attr="name" /></title>
<jsp:include page="/inc/select.jsp" />
</head>

<body>
<html:form action='<%=  (String)request.getAttribute(Constants.STRUTS_PATH) %>' method="post">
<html:hidden property="webMethod" value="list" />
<framework:ext />
<framework:table pkStyle="checkbox" navPosition="both" queryString="">
<framework:caption><span class="whf_object_title"><framework:attr source="STRUTS-META" attr="name" /></span></framework:caption>
</framework:table>
<framework:funcbtn operation="prepareCreate" validationFunction="" valueKey="form.create" />
<framework:funcbtn operation="prepareUpdate" validationFunction="selectionMoreThanOne" valueKey="form.update" />
<framework:funcbtn operation="duplicate" 	validationFunction="selectionMoreThanOne" valueKey="form.duplicate" />
<framework:funcbtn operation="delete" 		validationFunction="selectionMoreThanOne" valueKey="form.delete" />
<html:reset><bean:message key="form.reset" /></html:reset>
</html:form>

</body>
</html> 
		]]>
		</list>
		<view>
		<![CDATA[
<%@page contentType="text/html;charset=UTF-8"%>
<%@ page import="whf.framework.web.Constants"%>

<%@taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/tlds/framework.tld" prefix="framework"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><bean:write name="STRUTS-META" property="name" /></title>
<jsp:include page="/inc/select.jsp" />
</head>
<body>

<html:form action="<%=  (String)request.getAttribute(Constants.STRUTS_PATH) %>" method="post">
<html:hidden property="id" />
<html:hidden property="webMethod" />
<framework:table pkStyle="" navPosition="none" pageSize="1" displayStyle="form">
<framework:caption><span class="whf_object_title"><framework:attr source="STRUTS-META" attr="name" /></span></framework:caption>
</framework:table>
<input type='button' onclick='window.history.back()' value='<bean:message key="form.return" />' />
<html:reset><bean:message key="form.reset" /></html:reset>
</html:form>

</body>
</html> 
		]]>
		</view>
	</jsp>
</root>
2 楼 longlongriver 2008-09-02  
不错!楼主可以参考我的实现:http://www.iteye.com/topic/232219
另外,能否介绍一下你的代码生成器的设计思路,供大家参考参考!
1 楼 javawhf 2008-09-02  
上述工作完成后,相关的代码简单的表现为:
列表:
<framework:table pkStyle="checkbox_counter" navPosition="both" queryString="<%= queryString %>">
<framework:caption><span class="whf_object_title"><framework:attr source="STRUTS-META" attr="name" /></span></framework:caption>
</framework:table>


编辑:
<framework:table pkStyle="" border="1" cellspacing="0" cellpadding="0" navPosition="none" pageSize="1" displayStyle="form" editable="true" useStrutsForm="true" view="SYSTEM-OBJECT-VIEW">
<framework:caption><span class="whf_object_title"><bean:write name="STRUTS-META" property="name" /></span></framework:caption>
</framework:table>


主从表编辑:
<input type="hidden" name="UPDATING_PROPERTY_NAME" value="properties" />
<html:hidden property="webMethod" />
<framework:table pkStyle="" border="1" cellspacing="0" cellpadding="0" navPosition="none" pageSize="1" displayStyle="form" editable="true" useStrutsForm="true" view="SYSTEM-OBJECT-VIEW">
<framework:caption><span class="whf_object_title"><bean:write name="STRUTS-META" property="name" /></span></framework:caption>
</framework:table>

<framework:table id="ObjectProperty" pkStyle="checkbox_counter" pkSuffix="true" namePrefix="Property" border="1" cellspacing="0" cellpadding="0" boClassName="whf.framework.meta.entity.ObjectProperty"  navPosition="bottom" pageSize="100" editable="true" useStrutsForm="true" dataSourceName=".sortedProperties">
</framework:table>


查看:
<html:form action="<%=  (String)request.getAttribute(Constants.STRUTS_PATH) %>" method="post">
<html:hidden property="id" />
<html:hidden property="webMethod" />
<framework:table pkStyle="" border="1" cellspacing="0" cellpadding="0" navPosition="none" pageSize="1" displayStyle="form" useStrutsForm="true">
<framework:caption><span class="whf_object_title"><framework:attr source="STRUTS-META" attr="name" /></span></framework:caption>
</framework:table>
<input type='button' onclick='window.history.back()' value='<bean:message key="form.return" />' />
</html:form>


对于真正使用过程可以通过定义公共jsp文件,而对于服务器端都作了第一层封装处理,如果没有特殊处理,你不需要写一行代码;

相关推荐

    浅谈SSH学习要点

    SSH框架,全称为Struts+Spring+Hibernate,是Java企业级开发中常用的一种技术栈,主要用于构建基于MVC(Model-View-Controller)设计模式的Web应用。在本篇文章中,我们将深入探讨这三个组件的核心概念和进阶用法,...

    ssh商城代码

    Hibernate太重,他想作的事太多了,我个人觉得,像hibernate事务,完全鸡肋,而缓存,大部分时候也用不上,需要用到的场景,完全可以自已开发,更轻,而数据关系变得复杂后,hibernate越难驾驭,分布式事务的时候,...

    java ajax angular jquery ionic 框架视频教程

    通过上述知识点的学习,开发者可以全面了解JavaWeb、jQuery、Ajax、SSM/SSH框架以及Angular/Ionic结合开发移动应用的相关技术细节。这些技术不仅适用于京东商城移动端项目的开发,也能广泛应用于其他类型的Web和移动...

    2019年软件工程师个人工作总结.doc

    展望未来,我计划继续优化SSH框架,开发OA系统,同时做好现有项目的维护工作。我还将不断学习最新的技术知识,提升个人能力,以期为公司创造更大的价值。我相信,通过不懈的努力和持续的学习,我能够在软件工程师的...

    08年9月 帆都软件面试 笔试题

    从提供的信息来看,此面试题重点考察了面试者的JavaWeb开发能力,特别是对MVC设计模式的理解以及相关框架的运用,如Struts和SSH整合。 首先,MVC(Model-View-Controller)是一种广泛应用于Web开发的设计模式。...

    浅谈解决Hibernate懒加载的4种方式

    在当今的软件开发领域中,Hibernate作为一个非常流行的Java持久层框架,被广泛应用于企业级应用开发中。然而,Hibernate的懒加载特性虽然能够提升应用性能,但在某些场景下也会给开发者带来诸多不便。本文将浅谈解决...

    java面试技巧及笔试汇集

    SSH(Spring、Struts、Hibernate)是经典的Java企业级开发框架,面试中可能会涉及Spring的依赖注入、AOP、MVC模式,Struts的Action、Result、Interceptor,以及Hibernate的ORM映射和SQL操作。 九、数据库 1. SQL...

    浅谈Vue 自动化部署打包上线

    Vue.js是一款流行的前端框架,用于构建用户界面。在项目开发过程中,自动化部署打包是提高效率、减少错误的关键步骤。本文将深入探讨Vue项目的自动化部署打包上线,帮助开发者了解如何实现这一过程。 首先,自动化...

Global site tag (gtag.js) - Google Analytics