[讨论]J2EE项目自动生成工具

09-09-23 jshuwei
最近在做一个代码自动生成工具,下面的代码是自动生成的,欢迎大家讨论生成的代码有什么地方需要修改的。

变量名和包名等信息都是生成的时候配置文件配置的。

在线演示地址:http://java.jshuwei.org.cn:8080

代码看得闲累的话直接下载源代码吧:查看源代码(代码附件太大,只能放我自己博客中提供下载了,请见谅!)

BaseAction.java:

package cn.org.jshuwei.j2ee.test.action;

import cn.org.jshuwei.j2ee.test.core.JshuweiContext;
import cn.org.jshuwei.j2ee.util.StringUtil;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Copyright 2009 huwei(jshuwei.org.cn)
 * Generate by huwei's generate Util
 * 本类由胡伟j2ee自动生成工具生成,欢迎与作者交流讨论, 
 * <p>联系方式:<br>Web:[url]http://jshuwei.org.cn[/url] <br>Email:huwei@jshuwei.org.cn<br>QQ:772627301<p/>
 */

public class BaseAction extends ActionSupport  implements ServletRequestAware, ServletResponseAware {
	private static final long serialVersionUID = 1L;

    protected HttpServletRequest request;
    protected HttpServletResponse response;
    private String serviceId;
	private String serviceName;
	private int eventCode;
	protected Object requestObj;
	private int id;
	private int start;
	private int limit = 25;

    public void setServletRequest(HttpServletRequest httpServletRequest) {
        request = httpServletRequest;
    }

    public void setServletResponse(HttpServletResponse httpServletResponse) {
        response = httpServletResponse;
    }

    public HttpServletRequest getRequest() {
        return request;
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }

    public HttpServletResponse getResponse() {
        return response;
    }

    public void setResponse(HttpServletResponse response) {
        this.response = response;
    }

    public String getServiceId() {
        return serviceId;
    }

    public void setServiceId(String serviceId) {
        this.serviceId = serviceId;
    }

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public int getEventCode() {
        return eventCode;
    }

    public void setEventCode(int eventCode) {
        this.eventCode = eventCode;
    }

    public Object getRequestObj() {
        return requestObj;
    }

    public void setRequestObj(Object requestObj) {
        this.requestObj = requestObj;
    }
    
    public int getId() {
    	return id;
    }
    
    public void setId(int id) {
    	this.id = id;
    }
    
    public int getStart() {
    	return start;
    }
    
    public void setStart(int start) {
    	this.start = start;
    }
    
    public int getLimit() {
    	return limit;
    }
    
    public void setLimit(int limit) {
    	this.limit = limit;
    }
    
    @SuppressWarnings("unchecked")
    public JshuweiContext generateJshuweiContext() {
    	JshuweiContext jshuweiContext = new JshuweiContext();
    	if (serviceId != null || !"".equals(serviceId))
            jshuweiContext.setServiceId(serviceId);
    	if (serviceName != null || !"".equals(serviceName))
            jshuweiContext.setServiceName(serviceName);
    	if (eventCode != 0)
            jshuweiContext.setEventCode(eventCode);
        if (eventCode % 100 ==1)
    		setRequestObj(new Integer[]{start,limit});
    	if (eventCode % 100 ==2 || eventCode % 100 ==6)
    		setRequestObj(new Integer(id));
    	if (eventCode % 100 ==3) {
    		List list = new ArrayList();
    		list.add(generateEntity());
    		list.add(new Integer[]{start,limit});
    		setRequestObj(list);
    	}
    	if (eventCode % 100 ==4 || eventCode % 100 ==5)
    		setRequestObj(generateEntity());
    	if (requestObj != null)
            jshuweiContext.setRequestObj(requestObj);
……
<p>

省去n多代码(字数有限制),配置文件和web端代码,实在是太多了,各位还是直接下载源代码直接查看讨论吧!

附件太大了,这里上传不了,只能发到我自己的博客里下载!

[该贴被jshuwei于2009-09-23 12:53修改过]

    

1
banq
2009-09-23 14:02
说说你的代码生成工具的架构以及特点。包括简要使用步骤,需要哪些输入条件,能够输出哪些?等等

这是我刚才看到老外的一个Struts Hibernate代码生成框架,虽然框架本身设计不敢恭维,但是代码生成的文档还是可供参考的:

https://jt.dev.java.net/files/documents/5553/101913/JtWizard.doc

项目网址:

https://jt.dev.java.net/

不过JT生成的代码一个最大问题是没有领域模型了,甚至没有Java代码了,完全是依赖数据库表,是数据库表驱动开发方式。这也是很多代码生成工具的问题,如果能生成领域模型,那么就是DDD框架,或是DSL自动生成或是MDA工具了。

[该贴被banq于2009-09-23 14:43修改过]

猜你喜欢