日期:2014-05-19  浏览次数:20846 次

[讨论]J2EE项目自动生成工具
最近在做一个代码自动生成工具,下面的代码是自动生成的,欢迎大家讨论生成的代码有什么地方需要修改的。
变量名和包名等信息都是生成的时候配置文件配置的。
在线演示地址: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:http://jshuwei.org.cn <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