Ejemplo n.º 1
0
        internal static void createDto(string path, string package, string basePackage, string tableName, string comment, string className, DataTable dt)
        {
            string        firstClassName = className.Substring(0, 1).ToLower() + className.Substring(1);
            StringBuilder sb             = new StringBuilder();

            sb.Append("package ").Append(package).Append(";").Append("\r\n\r\n");
            sb.Append("import ").Append("java.io.Serializable;").Append("\r\n");

            //sb.Append("/**").Append("\r\n");
            //sb.Append(" * ").Append(comment).Append("\r\n");
            //sb.Append(" * @creator 赵志豪\r\n");
            //sb.Append(" * @create-time ").Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("\r\n");
            //sb.Append(" * @email ").Append("*****@*****.**").Append("\r\n");
            //sb.Append(" * @version 1.0").Append("\r\n");
            //sb.Append(" */").Append("\r\n");

            sb.Append("public class ").Append(className).Append("Dto extends BaseDto<" + className + ">").Append(" implements Serializable {").Append("\r\n");
            sb.Append("\t").Append("private static final long serialVersionUID = 7904053207325003853L;").Append("\r\n\r\n");
            foreach (DataRow row in dt.Rows)
            {
                string dataTypeResult = DataTypeMapping.getDataType(row["dataType"].ToString());
                //if(dataTypeResult == "String"){
                string fieldName      = row["fieldName"].ToString();
                string firstFieldName = fieldName.Substring(0, 1).ToLower() + fieldName.Substring(1);

                sb.Append("\t").Append("/** ").Append(row["comment"].ToString()).Append(" */").Append("\r\n");
                sb.Append("\t").Append("private ").Append(dataTypeResult).Append(" ").Append(firstFieldName).Append(";").Append("\r\n");;
                //}
            }
            sb.Append("\r\n");
            //get set 封装
            foreach (DataRow row in dt.Rows)
            {
                string dataTypeResult = DataTypeMapping.getDataType(row["dataType"].ToString());
                //if (dataTypeResult == "String")
                //{
                string fieldName      = row["fieldName"].ToString();
                string firstFieldName = fieldName.Substring(0, 1).ToLower() + fieldName.Substring(1);
                //get
                sb.Append("\t").Append("/** ").Append(row["comment"].ToString()).Append(" */").Append("\r\n");
                sb.Append("\t").Append("public ").Append(dataTypeResult).Append(" get").Append(fieldName).Append("(){").Append("\r\n");
                sb.Append("\t\t").Append("return this.").Append(firstFieldName).Append(";").Append("\r\n");
                sb.Append("\t").Append("}").Append("\r\n\r\n");

                //set
                sb.Append("\t").Append("/** ").Append(row["comment"].ToString()).Append(" */").Append("\r\n");
                sb.Append("\t").Append("public ").Append("void").Append(" set").Append(fieldName).Append("(String ").Append(firstFieldName).Append("){").Append("\r\n");
                sb.Append("\t\t").Append("this.").Append(firstFieldName).Append(" = ").Append(firstFieldName).Append(";").Append("\r\n");
                sb.Append("\t").Append("}").Append("\r\n\r\n");
                //}
            }
            sb.Append("}");
            CodeGenerationFactory.write(path + "\\" + className + "Dto.java", path, sb.ToString());
        }
Ejemplo n.º 2
0
        internal static void createPojo(string path, string package, string basePackage, string tableName, string comment, string className, DataTable dt)
        {
            string        firstClassName = className.Substring(0, 1).ToLower() + className.Substring(1);
            StringBuilder sb             = new StringBuilder();

            sb.Append("package ").Append(package).Append(";").Append("\r\n\r\n");
            sb.Append("import ").Append(" java.io.Serializable;").Append("\r\n\r\n");
            sb.Append("import ").Append(" io.swagger.annotations.ApiModel;").Append("\r\n\r\n");
            sb.Append("import ").Append(" io.swagger.annotations.ApiModelProperty;").Append("\r\n\r\n");

            sb.Append("import java.util.Date;").Append("\r\n");
            //sb.Append("/**").Append("\r\n");
            //sb.Append(" * ").Append(comment).Append("\r\n");
            //sb.Append(" * @creator 赵志豪\r\n");
            //sb.Append(" * @create-time ").Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("\r\n");
            //sb.Append(" * @email ").Append("*****@*****.**").Append("\r\n");
            //sb.Append(" * @version 1.0").Append("\r\n");
            //sb.Append(" */").Append("\r\n");
            sb.Append("@ApiModel").Append("\r\n");
            sb.Append("public class ").Append(className).Append(" implements Serializable {").Append("\r\n");
            sb.Append("\t").Append("private static final long serialVersionUID = 1L;").Append("\r\n\r\n");
            foreach (DataRow row in dt.Rows)
            {
                string dataTypeResult = DataTypeMapping.getDataType(row["dataType"].ToString());
                string fieldName      = row["fieldName"].ToString();
                string firstFieldName = fieldName.Substring(0, 1).ToLower() + fieldName.Substring(1);

                sb.Append("\t").Append("/** ").Append(row["comment"].ToString()).Append(" */").Append("\r\n");
                sb.Append("\t").Append("@ApiModelProperty(value = ").Append("\"" + row["comment"].ToString() + "\")").Append("\r\n");
                sb.Append("\t").Append("private ").Append(dataTypeResult).Append(" ").Append(firstFieldName).Append(";").Append("\r\n");
            }
            sb.Append("\r\n");
            foreach (DataRow row in dt.Rows)
            {
                string dataTypeResult = DataTypeMapping.getDataType(row["dataType"].ToString());
                string fieldName      = row["fieldName"].ToString().Substring(0, 1).ToUpper() + row["fieldName"].ToString().Substring(1);
                string firstFieldName = fieldName.Substring(0, 1).ToLower() + fieldName.Substring(1);
                //get
                sb.Append("\t").Append("/** ").Append(row["comment"].ToString()).Append(" */").Append("\r\n");
                sb.Append("\t").Append("public ").Append(dataTypeResult).Append(" get").Append(fieldName).Append("(){").Append("\r\n");
                sb.Append("\t\t").Append("return this.").Append(firstFieldName).Append(";").Append("\r\n");
                sb.Append("\t").Append("}").Append("\r\n\r\n");

                //set
                sb.Append("\t").Append("/** ").Append(row["comment"].ToString()).Append(" */").Append("\r\n");
                sb.Append("\t").Append("public ").Append("void").Append(" set").Append(fieldName).Append("(").Append(dataTypeResult).Append(" ").Append(firstFieldName).Append("){").Append("\r\n");
                sb.Append("\t\t").Append("this.").Append(firstFieldName).Append(" = ").Append(firstFieldName).Append(";").Append("\r\n");
                sb.Append("\t").Append("}").Append("\r\n\r\n");
            }
            sb.Append("}");
            CodeGenerationFactory.write(path + "\\" + className + ".java", path, sb.ToString());
        }
Ejemplo n.º 3
0
        internal static void createVo(string path, string package, string basePackage, string tableName, string comment, string className, DataTable dt)
        {
            string        firstClassName = className.Substring(0, 1).ToLower() + className.Substring(1);
            StringBuilder sb             = new StringBuilder();

            sb.Append("package ").Append(package).Append(";").Append("\r\n\r\n");
            sb.Append("import ").Append("java.io.Serializable;").Append("\r\n");
            sb.Append("import com.fasterxml.jackson.databind.annotation.JsonSerialize;").Append("\r\n");
            sb.Append("import io.swagger.annotations.ApiModel;").Append("\r\n");
            sb.Append("import lombok.AllArgsConstructor;").Append("\r\n");
            sb.Append("import lombok.Builder;").Append("\r\n");
            sb.Append("import lombok.Data;").Append("\r\n");
            sb.Append("import lombok.NoArgsConstructor;").Append("\r\n");
            sb.Append("import lombok.Builder;").Append("\r\n");
            sb.Append("import io.swagger.annotations.ApiModelProperty;");
            //sb.Append("/**").Append("\r\n");
            //sb.Append(" * ").Append(comment).Append("\r\n");
            //sb.Append(" * @creator 赵志豪\r\n");
            //sb.Append(" * @create-time ").Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("\r\n");
            //sb.Append(" * @email ").Append("*****@*****.**").Append("\r\n");
            //sb.Append(" * @version 1.0").Append("\r\n");
            //sb.Append(" */").Append("\r\n");
            sb.Append("@Builder").Append("\r\n");
            sb.Append("@Data").Append("\r\n");
            sb.Append("@NoArgsConstructor").Append("\r\n");
            sb.Append("@AllArgsConstructor").Append("\r\n");
            sb.Append("@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)").Append("\r\n");
            sb.Append("@ApiModel").Append("\r\n");
            sb.Append("public class ").Append(className).Append("Vo ").Append(" implements Serializable {").Append("\r\n");
            sb.Append("\t").Append("private static final long serialVersionUID = 7904053207325003853L;").Append("\r\n\r\n");
            foreach (DataRow row in dt.Rows)
            {
                string dataTypeResult = DataTypeMapping.getDataType(row["dataType"].ToString());
                //if(dataTypeResult == "String"){
                string fieldName = row["columnName"].ToString();

                sb.Append("\t").Append("/** ").Append(row["comment"].ToString()).Append(" */").Append("\r\n");
                sb.Append("\t").Append("@ApiModelProperty(value = ").Append("\"" + row["comment"].ToString() + "\")").Append("\r\n");
                sb.Append("\t").Append("private ").Append(dataTypeResult).Append(" ").Append(fieldName).Append(";").Append("\r\n");;
                //}
            }
            sb.Append("\r\n");

            sb.Append("}");
            CodeGenerationFactory.write(path + "\\" + className + "Vo.java", path, sb.ToString());
        }
Ejemplo n.º 4
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (this.txtBox_filePath.Text.Trim() == "")
     {
         MessageBox.Show("请选择生成路径");
     }
     else
     {
         if (this.dgv_tables_info.SelectedRows.Count > 1)
         {
             CodeGenerationFactory.javaCodeFactory(this.txtBox_filePath.Text, this.txt_pakage.Text, this.dgv_tables_info.SelectedRows);
         }
         else
         {
             CodeGenerationFactory.javaCodeFactory(this.txtBox_filePath.Text, this.txt_pakage.Text, this.dgv_tables_info.SelectedRows[0], this.dgv_column_info.Rows);
         }
     }
     MessageBox.Show("文件生成完成");
 }
Ejemplo n.º 5
0
        public static void createDao(string path, string package, string basePackage, string tableName, string comment, string className, DataTable dt)
        {
            string        firstClassName = className.Substring(0, 1).ToLower() + className.Substring(1);
            StringBuilder sb             = new StringBuilder();

            sb.Append("package ").Append(package).Append(";").Append("\r\n\r\n");
            sb.Append("import ").Append("java.util.List;").Append("\r\n");
            sb.Append("import ").Append("org.apache.ibatis.annotations.Param;").Append("\r\n");
            sb.Append("import ").Append("org.apache.ibatis.session.RowBounds;").Append("\r\n");
            sb.Append("import ").Append("org.springframework.stereotype.Repository;").Append("\r\n\r\n");

            sb.Append("import ").Append(basePackage).Append(".entity.").Append(className).Append(";").Append("\r\n");
            sb.Append("import ").Append(basePackage).Append(".model.").Append(className).Append("Condition;").Append("\r\n");
            //sb.Append("/**").Append("\r\n");
            //sb.Append(" * ").Append(comment).Append("\r\n");
            //sb.Append(" * @creator 赵志豪\r\n");
            //sb.Append(" * @create-time ").Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("\r\n");
            //sb.Append(" * @email ").Append("*****@*****.**").Append("\r\n");
            //sb.Append(" * @version 1.0").Append("\r\n");
            //sb.Append(" */").Append("\r\n");
            sb.Append("@Repository(\"" + firstClassName + "DaoImpl\")").Append("\r\n");
            sb.Append("public interface I").Append(className).Append("Dao{").Append("\r\n\r\n");

            //查询所有数据
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 查询所有").Append(comment).Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append("List<").Append(className).Append("> list" + className + "All();").Append("\r\n\r\n");

            //查询总数
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 查询总数").Append("\r\n");
            sb.Append("\t *").Append("@param condition 查询条件类").Append("\r\n");
            sb.Append("\t *").Append("@return 总条数").Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append("int get" + className + "ByPageCount").Append("(@Param(\"condition\") " + className + "Model condition);").Append("\r\n\r\n");

            //查询分页数据
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 分页查询").Append("\r\n");
            sb.Append("\t *").Append("@param bounds RowBounds对象").Append("\r\n");
            sb.Append("\t *").Append("@param condition 查询条件类").Append("\r\n");
            sb.Append("\t *").Append("@return 总条数").Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append("List<").Append(className).Append("> list").Append(className).Append("ByPage(@Param(\"condition\") ").Append(className).Append("Model condition").Append(",RowBounds bounds);").Append("\r\n\r\n");
            string resultDataType = "Long";

            foreach (DataRow row in dt.Rows)
            {
                string fieldName = row["fieldName"].ToString().Substring(0, 1).ToUpper() + row["fieldName"].ToString().Substring(1);
                if (fieldName == "Id")
                {
                    resultDataType = DataTypeMapping.getDataType(row["dataType"].ToString());
                    break;
                }
            }
            //根据ID查询
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 根据ID查询").Append("\r\n");
            sb.Append("\t *").Append("@param id 主键").Append("\r\n");
            sb.Append("\t *").Append("@return ").Append(comment).Append("\r\n");;
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append(className).Append(" get" + className + "ById").Append("(@Param(\"id\") " + resultDataType + " id);").Append("\r\n\r\n");

            //新增
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 新增").Append("\r\n");
            sb.Append("\t *").Append("@param item ").Append(comment).Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append("void add(").Append(className).Append(" item);").Append("\r\n\r\n");

            //批量新增
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 批量新增").Append("\r\n");
            sb.Append("\t *").Append("@param List ").Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append("void batchInsert(").Append("List<" + className + "> arrayList);").Append("\r\n\r\n");


            //修改
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 修改").Append("\r\n");
            sb.Append("\t *").Append("@param item ").Append(comment).Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append("void update(").Append(className).Append(" item);").Append("\r\n\r\n");

            //删除
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 删除").Append("\r\n");
            sb.Append("\t *").Append("@param item ").Append(comment).Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append("void delByIds(").Append("List<" + resultDataType + "> ids);").Append("\r\n\r\n");
            sb.Append("}").Append("\r\n");
            //生成
            CodeGenerationFactory.write(path + "\\I" + className + "Dao.java", path, sb.ToString());
        }
Ejemplo n.º 6
0
        internal static void createService(string path, string package, string basePackage, string tableName, string comment, string className, DataTable dt)
        {
            string[] packages       = basePackage.Split('.');
            string   packageComBase = "";

            for (int i = 0; i < 2; i++)
            {
                packageComBase += packages[i] + ".";
            }
            string        firstClassName = className.Substring(0, 1).ToLower() + className.Substring(1);
            StringBuilder sb             = new StringBuilder();

            sb.Append("package ").Append(package).Append(";").Append("\r\n\r\n");
            sb.Append("import ").Append("java.util.List;").Append("\r\n");

            sb.Append("import ").Append(packageComBase).Append("base.page.PageResult;").Append("\r\n");
            sb.Append("import ").Append(basePackage).Append(".entity.").Append(className).Append(";").Append("\r\n");
            sb.Append("import ").Append(basePackage).Append(".dto.").Append(className).Append("Dto;").Append("\r\n");
            //sb.Append("/**").Append("\r\n");
            //sb.Append(" * ").Append(comment).Append("\r\n");
            //sb.Append(" * @creator 赵志豪\r\n");
            //sb.Append(" * @create-time ").Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("\r\n");
            //sb.Append(" * @email ").Append("*****@*****.**").Append("\r\n");
            //sb.Append(" * @version 1.0").Append("\r\n");
            //sb.Append(" */").Append("\r\n");
            sb.Append("public interface I").Append(className).Append("Service{").Append("\r\n\r\n");

            //查询所有数据
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 查询所有").Append(comment).Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append("List<").Append(className).Append("> list" + className + "All();").Append("\r\n\r\n");


            //根据条件查询
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 根据条件查询").Append(comment).Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append("List<").Append(className).Append("> list" + className + "ByCondition").Append("(" + className + "Dto condition);").Append("\r\n\r\n");

            //查询总数
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 查询总数").Append("\r\n");
            sb.Append("\t *").Append("@param condition 查询条件类").Append("\r\n");
            sb.Append("\t *").Append("@return 总条数").Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append("int get" + className + "ByPageCount").Append("(" + className + "Dto condition);").Append("\r\n\r\n");
            //分页方法

            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 分页查询").Append("\r\n");
            sb.Append("\t *").Append("@param pageResult 分页对象").Append("\r\n");
            sb.Append("\t *").Append("@param condition 查询条件类").Append("\r\n");
            sb.Append("\t *").Append("@return 总条数").Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append("void list").Append(className).Append("ByPage(").Append(className).Append("Dto condition);").Append("\r\n\r\n");



            string resultDataType = "Long";

            foreach (DataRow row in dt.Rows)
            {
                string fieldName = row["fieldName"].ToString().Substring(0, 1).ToUpper() + row["fieldName"].ToString().Substring(1);
                if (fieldName == "Id")
                {
                    resultDataType = DataTypeMapping.getDataType(row["dataType"].ToString());
                    break;
                }
            }
            //根据ID查询
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 根据ID查询").Append("\r\n");
            sb.Append("\t *").Append("@param id 主键").Append("\r\n");
            sb.Append("\t *").Append("@return ").Append(comment).Append("\r\n");;
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append(className).Append(" get" + className + "ById").Append("(" + resultDataType + " id);").Append("\r\n\r\n");

            //新增
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 新增").Append("\r\n");
            sb.Append("\t *").Append("@param item ").Append(comment).Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append(className).Append(" add(").Append(className).Append(" item);").Append("\r\n\r\n");

            //批量新增
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 批量新增").Append("\r\n");
            sb.Append("\t *").Append("@param List ").Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append("void batchInsert(").Append("List<" + className + "> arrayList);").Append("\r\n\r\n");

            //修改
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 修改").Append("\r\n");
            sb.Append("\t *").Append("@param item ").Append(comment).Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append(className).Append(" update(").Append(className).Append(" item);").Append("\r\n\r\n");


            //删除
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 删除").Append("\r\n");
            sb.Append("\t *").Append("@param item ").Append(comment).Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t").Append("void delByIds(").Append("List<" + resultDataType + "> ids);").Append("\r\n\r\n");
            sb.Append("}");

            CodeGenerationFactory.write(path + "\\I" + className + "Service.java", path, sb.ToString());
        }
Ejemplo n.º 7
0
        public static void createController(string path, string package, string basePackage, string tableName, string comment, string className, DataTable dt)
        {
            string mapping = "";

            string[] packages       = basePackage.Split('.');
            string   packageComBase = "";

            for (int i = 0; i < 2; i++)
            {
                packageComBase += packages[i] + ".";
            }
            if (packages.Length > 2)
            {
                for (int i = 2; i < packages.Length; i++)
                {
                    mapping += "/" + packages[i];
                }
            }
            char[] tableChar = tableName.ToCharArray();
            if (tableChar[1] == '_')
            {
                tableName = tableName.ToLower().Substring(2);
                string[] names = tableName.Split('_');
                foreach (string item in names)
                {
                    mapping += "/" + item;
                }
            }
            else
            {
                tableName = tableName.ToLower();
                string[] names = tableName.Split('_');
                foreach (string item in names)
                {
                    mapping += "/" + item;
                }
            }
            string        firstClassName = className.Substring(0, 1).ToLower() + className.Substring(1);
            StringBuilder sb             = new StringBuilder();

            sb.Append("package ").Append(package).Append(";").Append("\r\n\r\n");
            sb.Append("import ").Append("java.util.Map;").Append("\r\n");
            sb.Append("import ").Append("java.util.List;").Append("\r\n");
            sb.Append("import ").Append("javax.annotation.Resource;").Append("\r\n");
            sb.Append("import ").Append("org.springframework.context.annotation.Scope;").Append("\r\n");
            sb.Append("import ").Append("javax.servlet.http.HttpServletRequest;").Append("\r\n");
            sb.Append("import ").Append("javax.servlet.http.HttpServletResponse;").Append("\r\n");
            sb.Append("import ").Append("javax.servlet.http.HttpSession;").Append("\r\n");
            sb.Append("import ").Append("org.apache.commons.lang3.StringUtils;").Append("\r\n");
            sb.Append("import ").Append("com.alibaba.fastjson.JSONObject;").Append("\r\n");
            sb.Append("import ").Append("org.springframework.stereotype.Controller;").Append("\r\n");
            sb.Append("import ").Append("org.springframework.validation.BindingResult;").Append("\r\n");
            sb.Append("import ").Append("org.springframework.validation.DataBinder;").Append("\r\n");
            sb.Append("import ").Append("org.springframework.web.bind.annotation.InitBinder;").Append("\r\n");
            sb.Append("import ").Append("org.springframework.web.bind.annotation.ModelAttribute;").Append("\r\n");
            sb.Append("import ").Append("org.springframework.web.bind.annotation.RequestMapping;").Append("\r\n");
            sb.Append("import ").Append("org.springframework.web.bind.annotation.RequestMethod;").Append("\r\n");
            sb.Append("import ").Append("org.springframework.web.servlet.ModelAndView;").Append("\r\n");

            sb.Append("import ").Append(packageComBase).Append("adp.web.framework.controller.BaseController;").Append("\r\n");
            sb.Append("import ").Append(basePackage).Append(".service.").Append("I").Append(className).Append("Service;").Append("\r\n");
            sb.Append("import ").Append(basePackage).Append(".entity.").Append(className).Append(";").Append("\r\n");
            sb.Append("import ").Append(basePackage).Append(".model.").Append(className).Append("Form;").Append("\r\n\r\n");



            String lastMappingName = mapping.Substring(mapping.LastIndexOf("/"));

            sb.Append("@Controller(\"" + firstClassName + "Controller\")").Append("\r\n");
            sb.Append("@Scope(\"prototype\")").Append("\r\n");
            sb.Append("@Api(value = ").Append("\"" + lastMappingName + "\" , description = ").Append("\"" + comment + "\")").Append("\r\n");
            sb.Append("@RequestMapping(\"" + mapping + "\")").Append("\r\n");
            sb.Append("public class ").Append(className).Append("Controller extends BaseController {").Append("\r\n\r\n");
            sb.Append("\t@Resource(name = \"" + firstClassName + "ServiceImpl\")").Append("\r\n");
            sb.Append("\tprivate I").Append(className).Append("Service ").Append(firstClassName).Append("Service;").Append("\r\n\r\n\r\n\r\n");


            //分页查询
            //首页
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 分页查询").Append("\r\n");
            sb.Append("\t * @return ").Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t@RequestMapping(value = \"/listDataByPage\", method = RequestMethod.GET)").Append("\r\n");
            sb.Append("\t@ApiOperation(value = ").Append("\"查询" + comment + "\")").Append("\r\n");
            sb.Append("\t@ResponseBody").Append("\r\n");
            sb.Append("\t").Append("public Response listDataByPage(@ModelAttribute " + className + "Model model){").Append("\r\n");

            sb.Append("\t\t").Append(firstClassName).Append("Service.list").Append(className).Append("ByPage(model);").Append("\r\n");
            sb.Append("\t\t").Append("JSONObject root = model.getPageResult().toPageJson();").Append("\r\n");
            sb.Append("\t\t").Append("return Response.SUCCESS(root.toJSONString())").Append("\r\n");

            sb.Append("\t").Append("}").Append("\r\n\r\n");



            //保存
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 保存").Append(comment).Append("\r\n");
            sb.Append("\t * @return ").Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t@ApiOperation(value = ").Append("\"保存" + comment + "\")").Append("\r\n");
            sb.Append("\t@RequestMapping(value = \"/save\", method = RequestMethod.PUT)").Append("\r\n");
            sb.Append("\t@ResponseBody").Append("\r\n");
            sb.Append("\tpublic Response save(@ModelAttribute " + className + "Entity model){").Append("\r\n");
            sb.Append("\t\t").Append("if(null == model.getId()){").Append("\r\n");
            sb.Append("\t\t\t").Append(firstClassName).Append("Service.add(model);").Append("\r\n");
            sb.Append("\t\t").Append("}else{").Append("\r\n");
            sb.Append("\t\t\t").Append(firstClassName).Append("Service.update(model);").Append("\r\n");
            sb.Append("\t\t").Append("}").Append("\r\n");
            sb.Append("\t\t").Append("return Response.SUCCESS(true);").Append("\r\n");

            sb.Append("\t").Append("}").Append("\r\n\r\n");


            //删除
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 删除").Append(comment).Append("\r\n");
            sb.Append("\t * @return ").Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t@ApiOperation(value = ").Append("\"删除" + comment + "\")").Append("\r\n");
            sb.Append("\t@RequestMapping(value = \"/del\", method = RequestMethod.DELETE)").Append("\r\n");
            sb.Append("\t@ResponseBody").Append("\r\n");
            sb.Append("\tpublic Response del(@ModelAttribute " + className + "Model model){").Append("\r\n");
            sb.Append("\t\t").Append("if(model.getSelIds() == null || model.getSelIds().size() == 0)").Append("\r\n");
            sb.Append("\t\t\t").Append("throw new ServiceException(UpCoopExceptionCode.SYSTEM_ERROR)").Append("\r\n");
            sb.Append("\t\t").Append(firstClassName).Append("Service.delByIds(model.getSelIds());").Append("\r\n");
            sb.Append("\t\t").Append("return Response.SUCCESS(true);").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n");
            sb.Append("}").Append("\r\n");

            CodeGenerationFactory.write(path + "\\" + className + "Controller.java", path, sb.ToString());
        }
Ejemplo n.º 8
0
        internal static void createServiceImpl(string path, string package, string basePackage, string tableName, string comment, string className, DataTable dt)
        {
            string[] packages       = basePackage.Split('.');
            string   packageComBase = "";

            for (int i = 0; i < 2; i++)
            {
                packageComBase += packages[i] + ".";
            }
            string        firstClassName = className.Substring(0, 1).ToLower() + className.Substring(1);
            StringBuilder sb             = new StringBuilder();

            sb.Append("package ").Append(package).Append(";").Append("\r\n\r\n");
            sb.Append("import ").Append("java.util.List;").Append("\r\n");
            sb.Append("import javax.annotation.Resource;").Append("\r\n");
            sb.Append("import org.springframework.stereotype.Service;").Append("\r\n");;
            sb.Append("import org.springframework.transaction.annotation.Transactional;").Append("\r\n\r\n");
            sb.Append("import org.apache.ibatis.session.RowBounds;").Append("\r\n");
            sb.Append("import ").Append(packageComBase).Append("base.page.PageResult;").Append("\r\n");
            sb.Append("import ").Append(basePackage).Append(".service.").Append("I").Append(className).Append("Service;").Append("\r\n");
            sb.Append("import ").Append(basePackage).Append(".entity.").Append(className).Append(";").Append("\r\n");
            sb.Append("import ").Append(basePackage).Append(".dto.").Append(className).Append("Dto;").Append("\r\n");
            sb.Append("import ").Append(basePackage).Append(".dao.").Append("I").Append(className).Append("Dao;").Append("\r\n");
            //sb.Append("/**").Append("\r\n");
            //sb.Append(" * ").Append(comment).Append("\r\n");
            //sb.Append(" * @creator 赵志豪\r\n");
            //sb.Append(" * @create-time ").Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("\r\n");
            //sb.Append(" * @email ").Append("*****@*****.**").Append("\r\n");
            //sb.Append(" * @version 1.0").Append("\r\n");
            //sb.Append(" */").Append("\r\n");
            sb.Append("@Service(\"" + firstClassName + "ServiceImpl\")").Append("\r\n");
            sb.Append("@Transactional(value = \"transactionManager\")").Append("\r\n");
            sb.Append("public class ").Append(className).Append("ServiceImpl implements I").Append(className).Append("Service{").Append("\r\n\r\n");
            sb.Append("\t@Resource(name = \"" + firstClassName + "DaoImpl\")").Append("\r\n");
            sb.Append("\tprivate I").Append(className).Append("Dao ").Append(firstClassName).Append("Dao;").Append("\r\n\r\n\r\n\r\n");
            //查询所有数据
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 查询所有").Append(comment).Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t@Override").Append("\r\n");
            sb.Append("\t").Append("public List<").Append(className).Append("> list" + className + "All(){").Append("\r\n");
            sb.Append("\t\t").Append("return ").Append(firstClassName).Append("Dao.list").Append(className).Append("All();").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n\r\n");

            //根据条件查询
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 根据条件查询").Append(comment).Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t@Override").Append("\r\n");
            sb.Append("\t").Append("public ").Append("List<").Append(className).Append("> list" + className + "ByCondition").Append("(" + className + "Dto condition){").Append("\r\n");
            sb.Append("\t\t").Append("return ").Append(firstClassName).Append("Dao.list").Append(className).Append("ByPage(condition,null);").Append("\r\n");
            sb.Append("\t}").Append("\r\n");

            //查询总数
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 查询总数").Append("\r\n");
            sb.Append("\t *").Append("@param condition 查询条件类").Append("\r\n");
            sb.Append("\t *").Append("@return 总条数").Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t@Override").Append("\r\n");
            sb.Append("\t").Append("public int get" + className + "ByPageCount").Append("(" + className + "Dto condition){").Append("\r\n");
            sb.Append("\t\t").Append("return ").Append(firstClassName).Append("Dao.get").Append(className).Append("ByPageCount(condition);").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n\r\n");

            //分页方法
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 分页查询").Append("\r\n");
            sb.Append("\t *").Append("@param pageResult 分页对象").Append("\r\n");
            sb.Append("\t *").Append("@param condition 查询条件类").Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t@Override").Append("\r\n");
            sb.Append("\t").Append("public void list").Append(className).Append("ByPage(").Append(className).Append("Dto condition){").Append("\r\n");
            sb.Append("\t\t").Append("int rows = ").Append(firstClassName).Append("Dao.get").Append(className).Append("ByPageCount(condition);").Append("\r\n");
            sb.Append("\t\t").Append("pageResult.setRows(rows);").Append("\r\n");
            sb.Append("\t\t").Append("RowBounds rowBounds = new RowBounds(condition.pageResult.getCurrentPageIndex(),condition.pageResult.getPageSize());").Append("\r\n");
            sb.Append("\t\t").Append("List<").Append(className).Append("> list = ").Append(firstClassName).Append("Dao.list").Append(className).Append("ByPage(condition,rowBounds);").Append("\r\n");
            sb.Append("\t\t").Append("pageResult.setResult(list);").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n\r\n");


            string resultDataType = "Long";

            foreach (DataRow row in dt.Rows)
            {
                string fieldName = row["fieldName"].ToString().Substring(0, 1).ToUpper() + row["fieldName"].ToString().Substring(1);
                if (fieldName == "Id")
                {
                    resultDataType = DataTypeMapping.getDataType(row["dataType"].ToString());
                    break;
                }
            }
            //根据ID查询
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 根据ID查询").Append("\r\n");
            sb.Append("\t *").Append("@param id 主键").Append("\r\n");
            sb.Append("\t *").Append("@return ").Append(comment).Append("\r\n");;
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t@Override").Append("\r\n");
            sb.Append("\t").Append("public ").Append(className).Append(" get" + className + "ById").Append("(" + resultDataType + " id){").Append("\r\n");
            sb.Append("\t\t").Append("return ").Append(firstClassName).Append("Dao.get").Append(className).Append("ById(id);").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n\r\n");


            //新增
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 新增").Append("\r\n");
            sb.Append("\t *").Append("@param item ").Append(comment).Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t@Override").Append("\r\n");
            sb.Append("\t").Append("public ").Append(className).Append(" add(").Append(className).Append(" item){").Append("\r\n");
            sb.Append("\t\t").Append(firstClassName).Append("Dao.add(item);").Append("\r\n");
            sb.Append("\t\t").Append("return item;").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n\r\n");


            //批量新增
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 批量新增").Append("\r\n");
            sb.Append("\t *").Append("@param List ").Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t@Override").Append("\r\n");
            sb.Append("\t").Append("public void").Append(" batchInsert(").Append("List<" + className + "> arrayList){").Append("\r\n\r\n");
            sb.Append("\t\t").Append(firstClassName).Append("Dao.batchInsert(arrayList);").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n\r\n");

            //修改
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 修改").Append("\r\n");
            sb.Append("\t *").Append("@param item ").Append(comment).Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t@Override").Append("\r\n");
            sb.Append("\t").Append("public ").Append(className).Append(" update(").Append(className).Append(" item){").Append("\r\n");
            sb.Append("\t\t").Append(firstClassName).Append("Dao.update(item);").Append("\r\n");
            sb.Append("\t\t").Append("return item;").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n\r\n");


            //删除
            sb.Append("\t/**").Append("\r\n");
            sb.Append("\t * 删除").Append("\r\n");
            sb.Append("\t *").Append("@param item ").Append(comment).Append("\r\n");
            sb.Append("\t */").Append("\r\n");
            sb.Append("\t@Override").Append("\r\n");
            sb.Append("\t").Append("public void").Append(" delByIds(List<" + resultDataType + "> ids){").Append("\r\n");
            sb.Append("\t\t").Append(firstClassName).Append("Dao.delByIds(ids);").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n\r\n");
            sb.Append("}");
            CodeGenerationFactory.write(path + "\\" + className + "ServiceImpl.java", path, sb.ToString());
        }
Ejemplo n.º 9
0
        internal static void createMapper(string path, string package, string basePackage, string tableName, string comment, string className, DataTable dt)
        {
            string firstClassName = className.Substring(0, 1).ToLower() + className.Substring(1);
            string entityPackage  = package.Substring(0, package.LastIndexOf(".")) + ".entity.";

            StringBuilder sb = new StringBuilder();

            sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").Append("\r\n");
            sb.Append("<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" ").Append("\"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">").Append("\r\n");
            sb.Append("<mapper namespace=\"" + package + ".I" + className + "Dao\">").Append("\r\n");
            sb.Append("\t").Append("<resultMap type=\"" + entityPackage + className + "\" id=\"" + firstClassName + "ResultMap\" >").Append("\r\n");
            foreach (DataRow row in dt.Rows)
            {
                string fieldName      = row["fieldName"].ToString();
                string firstFieldName = fieldName.Substring(0, 1).ToLower() + fieldName.Substring(1);
                sb.Append("\t\t").Append("<!-- " + row["comment"] + " -->").Append("\r\n");
                sb.Append("\t\t").Append("<result property=\"" + firstFieldName + "\" column=\"" + row["columnName"].ToString() + "\" />").Append("\r\n");
            }
            sb.Append("\t").Append("</resultMap>").Append("\r\n\r\n\r\n");
            sb.Append("\t").Append("<sql id=\"allColumnSql\">").Append("\r\n");
            for (int i = 0; i < dt.Rows.Count - 1; i++)
            {
                sb.Append("\t\t").Append("o." + dt.Rows[i]["columnName"].ToString() + ",").Append("\r\n");
            }
            sb.Append("\t\t").Append("o." + dt.Rows[dt.Rows.Count - 1]["columnName"].ToString()).Append("\r\n");

            sb.Append("\t").Append("</sql>").Append("\r\n\r\n\r\n");

            sb.Append("\t").Append("<sql id=\"searchConditionSql\">").Append("\r\n");
            foreach (DataRow row in dt.Rows)
            {
                string dataTypeResult = DataTypeMapping.getDataType(row["dataType"].ToString());
                if (dataTypeResult == "String")
                {
                    string fieldName      = row["fieldName"].ToString();
                    string firstFieldName = fieldName.Substring(0, 1).ToLower() + fieldName.Substring(1);

                    sb.Append("\t\t").Append("<if test=\"condition." + firstFieldName + " != null and condition." + firstFieldName + " != ''\">").Append("\r\n");

                    sb.Append("\t\t\t").Append("AND o.").Append(row["columnName"].ToString()).Append(" like '%${condition.").Append(firstFieldName).Append("}%'").Append("\r\n");
                    sb.Append("\t\t").Append("</if>").Append("\r\n");
                }
            }
            sb.Append("\t").Append("</sql>").Append("\r\n\r\n");
            //查询全部
            sb.Append("\t").Append("<select id=\"list" + className + "All\" resultMap=\"" + firstClassName + "ResultMap\">").Append("\r\n");
            sb.Append("\t\t").Append("SELECT <include refid=\"allColumnSql\"/>").Append("\r\n");
            sb.Append("\t\t").Append("FROM " + tableName + " o").Append("\r\n");
            sb.Append("\t").Append("</select>").Append("\r\n\r\n");

            //查询总数
            sb.Append("\t").Append("<select id=\"get" + className + "ByPageCount\" resultType=\"int\">").Append("\r\n");
            sb.Append("\t\t").Append("SELECT count(1)").Append("\r\n");
            sb.Append("\t\t").Append("FROM " + tableName + " o").Append("\r\n");
            sb.Append("\t\t").Append("WHERE 1=1 <include refid=\"searchConditionSql\"/>").Append("\r\n");
            sb.Append("\t").Append("</select>").Append("\r\n\r\n");

            //查询数据
            sb.Append("\t").Append("<select id=\"list" + className + "ByPage\" resultMap=\"" + firstClassName + "ResultMap\">").Append("\r\n");
            sb.Append("\t\t").Append("SELECT <include refid=\"allColumnSql\"/>").Append("\r\n");
            sb.Append("\t\t").Append("FROM " + tableName + " o").Append("\r\n");
            sb.Append("\t\t").Append("WHERE 1=1 <include refid=\"searchConditionSql\"/>").Append("\r\n");
            sb.Append("\t").Append("</select>").Append("\r\n\r\n");


            //根据ID获取数据

            sb.Append("\t").Append("<select id=\"get" + className + "ById\" resultMap=\"" + firstClassName + "ResultMap\">").Append("\r\n");
            sb.Append("\t\t").Append("SELECT <include refid=\"allColumnSql\"/>").Append("\r\n");
            sb.Append("\t\t").Append("FROM " + tableName + " o").Append("\r\n");
            sb.Append("\t\t").Append("WHERE o.ID = #{id}").Append("\r\n");
            sb.Append("\t").Append("</select>").Append("\r\n\r\n");

            //新增

            sb.Append("\t").Append("<insert id=\"add\" parameterType=\"" + entityPackage + className + "\"").Append(" useGeneratedKeys=\"true\" keyProperty=\"id\">").Append("\r\n");
            sb.Append("\t\t").Append("INSERT INTO ").Append(tableName).Append("\r\n");
            sb.Append("\t\t").Append("(").Append("\r\n");
            sb.Append("\t\t").Append("<trim suffixOverrides=\",\"").Append(">").Append("\r\n");
            for (int i = 1; i < dt.Rows.Count; i++)
            {
                DataRow row           = dt.Rows[i];
                string  fielName      = row["fieldName"].ToString();
                string  firstFielName = fielName.Substring(0, 1).ToLower() + fielName.Substring(1);
                sb.Append("\t\t").Append("<if test=\"" + firstFielName + " != null \">").Append("\r\n");
                sb.Append("\t\t").Append(row["columnName"].ToString()).Append(",").Append("\r\n");
                sb.Append("\t\t").Append("</if>").Append("\r\n");
            }
            sb.Append("\t\t").Append("</trim>").Append("\r\n");

            sb.Append("\t\t").Append(")").Append("\r\n");
            sb.Append("\t\t").Append("VALUES").Append("\r\n");
            sb.Append("\t\t").Append("(").Append("\r\n");
            sb.Append("\t\t").Append("<trim suffixOverrides=\",\"").Append(">").Append("\r\n");
            for (int i = 1; i < dt.Rows.Count; i++)
            {
                DataRow row           = dt.Rows[i];
                string  fielName      = row["fieldName"].ToString();
                string  firstFielName = fielName.Substring(0, 1).ToLower() + fielName.Substring(1);
                sb.Append("\t\t").Append("<if test=\"" + firstFielName + " != null \">").Append("\r\n");
                sb.Append("\t\t").Append("#{").Append(firstFielName).Append("}").Append(",").Append("\r\n");
                sb.Append("\t\t").Append("</if>").Append("\r\n");
            }
            sb.Append("\t\t").Append("</trim>").Append("\r\n");
            string fielNameLast      = dt.Rows[dt.Rows.Count - 1]["fieldName"].ToString();
            string firstFielNameLast = fielNameLast.Substring(0, 1).ToLower() + fielNameLast.Substring(1);

            sb.Append("\t\t").Append(")").Append("\r\n");
            sb.Append("\t").Append("</insert>").Append("\r\n\r\n");
            //批量新增
            sb.Append("\t").Append("<insert id=\"batchInsert\" >").Append("\r\n");
            sb.Append("\t\t").Append("INSERT INTO ").Append(tableName).Append("\r\n");
            sb.Append("\t\t").Append("(").Append("\r\n");
            for (int i = 1; i < dt.Rows.Count - 1; i++)
            {
                DataRow row = dt.Rows[i];
                sb.Append("\t\t").Append(row["columnName"].ToString()).Append(",").Append("\r\n");
            }
            sb.Append("\t\t").Append(dt.Rows[dt.Rows.Count - 1]["columnName"].ToString()).Append("\r\n");
            sb.Append("\t\t").Append(")").Append("\r\n");
            sb.Append("\t\t").Append("VALUES").Append("\r\n");
            sb.Append("\t\t").Append("<foreach collection=\"list\" index=\"index\" item=\"item\" separator=\",\">").Append("\r\n");
            sb.Append("\t\t").Append("(").Append("\r\n");
            for (int i = 1; i < dt.Rows.Count - 1; i++)
            {
                DataRow row           = dt.Rows[i];
                string  fielName      = row["fieldName"].ToString();
                string  firstFielName = fielName.Substring(0, 1).ToLower() + fielName.Substring(1);
                sb.Append("\t\t").Append("#{item.").Append(firstFielName).Append("}").Append(",").Append("\r\n");
            }
            fielNameLast      = dt.Rows[dt.Rows.Count - 1]["fieldName"].ToString();
            firstFielNameLast = fielNameLast.Substring(0, 1).ToLower() + fielNameLast.Substring(1);
            sb.Append("\t\t").Append("#{item.").Append(firstFielNameLast).Append("}").Append("\r\n");
            sb.Append("\t\t").Append(")").Append("\r\n");
            sb.Append("\t\t").Append("</foreach>").Append("\r\n");;
            sb.Append("\t").Append("</insert>").Append("\r\n\r\n");

            //修改
            sb.Append("\t").Append("<update id=\"update\" parameterType=\"" + entityPackage + className + "\">").Append("\r\n");
            sb.Append("\t\t").Append("UPDATE ").Append(tableName).Append("\r\n");
            sb.Append("\t\t").Append("<trim prefix=\"set\" suffixOverrides=\",\">").Append("\r\n");
            for (int i = 1; i < dt.Rows.Count; i++)
            {
                DataRow row           = dt.Rows[i];
                string  fielName      = row["fieldName"].ToString();
                string  firstFielName = fielName.Substring(0, 1).ToLower() + fielName.Substring(1);
                sb.Append("\t\t").Append("<if test=\"" + firstFielName + " != null \">").Append("\r\n");
                sb.Append("\t\t").Append(row["columnName"].ToString()).Append(" = ").Append("#{" + firstFielName + "}").Append(",").Append("\r\n");
                sb.Append("\t\t").Append("</if>").Append("\r\n");
            }
            sb.Append("\t\t").Append("</trim>").Append("\r\n");
            sb.Append("\t\t").Append("WHERE ID = #{id}").Append("\r\n");
            sb.Append("\t").Append("</update>").Append("\r\n\r\n");

            //删除
            sb.Append("\t").Append("<delete id=\"delByIds\">").Append("\r\n");
            sb.Append("\t\t").Append("DELETE FROM ").Append(tableName).Append("\r\n");

            sb.Append("\t\t").Append("WHERE ID IN").Append("\r\n");
            sb.Append("\t\t").Append("<foreach collection=\"list\" index=\"index\" item=\"item\" open=\"(\" separator=\",\" close=\")\">").Append("\r\n");
            sb.Append("\t\t\t").Append("#{item}").Append("\r\n");;
            sb.Append("\t\t").Append("</foreach>").Append("\r\n");;
            sb.Append("\t").Append("</delete>").Append("\r\n\r\n");
            sb.Append("</mapper>");

            CodeGenerationFactory.write(path + "\\I" + className + "Mapper.xml", path, sb.ToString());
        }
Ejemplo n.º 10
0
        internal static void createForm(string path, string package, string basePackage, string tableName, string comment, string className, DataTable dt)
        {
            string[] packages       = basePackage.Split('.');
            string   packageComBase = "";

            for (int i = 0; i < 2; i++)
            {
                packageComBase += packages[i] + ".";
            }
            string        firstClassName = className.Substring(0, 1).ToLower() + className.Substring(1);
            StringBuilder sb             = new StringBuilder();

            sb.Append("package ").Append(package).Append(";").Append("\r\n\r\n");

            sb.Append("import ").Append(basePackage).Append(".entity.").Append(className).Append(";").Append("\r\n");
            sb.Append("import ").Append(packageComBase).Append("base.form.BaseForm;").Append("\r\n");
            sb.Append("import ").Append(packageComBase).Append("base.page.PageResult;").Append("\r\n");
            sb.Append("import ").Append(basePackage).Append(".dto.").Append(className).Append("Condition;").Append("\r\n");
            //sb.Append("/**").Append("\r\n");
            //sb.Append(" * ").Append(comment).Append("\r\n");
            //sb.Append(" * @creator 赵志豪\r\n");
            //sb.Append(" * @create-time ").Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Append("\r\n");
            //sb.Append(" * @email ").Append("*****@*****.**").Append("\r\n");
            //sb.Append(" * @version 1.0").Append("\r\n");
            //sb.Append(" */").Append("\r\n");

            sb.Append("public class ").Append(className).Append("Form ").Append("extends BaseForm<").Append(className).Append(">{").Append("\r\n\r\n");
            sb.Append("\t").Append("private String").Append(" selIds;").Append("\r\n\r\n");
            sb.Append("\t").Append("private ").Append(className).Append(" item = new ").Append(className).Append("();").Append("\r\n\r\n");
            sb.Append("\t").Append("private ").Append(className).Append("Condition condition = new ").Append(className).Append("Condition();").Append("\r\n\r\n");


            //getitem
            sb.Append("\t").Append("public String").Append(" getSelIds(){").Append("\r\n");
            sb.Append("\t\t").Append("return selIds;").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n");
            //setitem
            sb.Append("\t").Append("public ").Append("void").Append(" setSelIds").Append("(String").Append(" selIds){").Append("\r\n");
            sb.Append("\t\t").Append("this.selIds").Append(" = selIds;").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n\r\n");

            //getitem
            sb.Append("\t").Append("public ").Append(className).Append(" getItem(){").Append("\r\n");
            sb.Append("\t\t").Append("return item;").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n");
            //setitem
            sb.Append("\t").Append("public ").Append("void").Append(" setItem").Append("(").Append(className).Append(" item){").Append("\r\n");
            sb.Append("\t\t").Append("this.item").Append(" = item;").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n\r\n");


            //getcondition
            sb.Append("\t").Append("public ").Append(className).Append("Condition").Append(" getCondition(){").Append("\r\n");
            sb.Append("\t\t").Append("return condition;").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n\r\r\n");

            //setcondition
            sb.Append("\t").Append("public ").Append("void").Append(" setCondition").Append("(").Append(className).Append("Condition").Append(" condition){").Append("\r\n");
            sb.Append("\t\t").Append("this.condition").Append(" = condition;").Append("\r\n");
            sb.Append("\t").Append("}").Append("\r\n\r\n");
            sb.Append("}").Append("\r\n\r\n");
            CodeGenerationFactory.write(path + "\\" + className + "Form.java", path, sb.ToString());
        }