myeclipse没有直接的快捷键自动生成构造方法,可以有快捷键弹出source,接着点击自动生成构造方法的菜单。
忻府ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!
具体操作如下:工具里快捷键alt+shift+s
就弹出来Generate
Constructor
using
Fields
zip包,然后自动下载下来
1.预先定义好模板
2.界面输入相关参数
3.解析模板生成代码并下载
最后放出源代码:
package com.et.controller.system.createcode;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.et.controller.base.BaseController;
import com.et.util.DelAllFile;
import com.et.util.FileDownload;
import com.et.util.FileZip;
import com.et.util.Freemarker;
import com.et.util.PageData;
import com.et.util.PathUtil;
/**
* 类名称:FreemarkerController
* 创建人:Harries
* 创建时间:2015年1月12日
* @version
*/
@Controller
@RequestMapping(value=”/createCode”)
public class CreateCodeController extends BaseController {
/**
* 生成代码
*/
@RequestMapping(value=”/proCode”)
public void proCode(HttpServletResponse response) throws Exception{
PageData pd = new PageData();
pd = this.getPageData();
/* ============================================================================================= */
String packageName = pd.getString(“packageName”); //包名 ========1
String objectName = pd.getString(“objectName”); //类名 ========2
String tabletop = pd.getString(“tabletop”); //表前缀 ========3
tabletop = null == tabletop?””:tabletop.toUpperCase(); //表前缀转大写
String zindext = pd.getString(“zindex”); //属性总数
int zindex = 0;
if(null != zindext !””.equals(zindext)){
zindex = Integer.parseInt(zindext);
}
ListString[] fieldList = new ArrayListString[](); //属性集合 ========4
for(int i=0; i zindex; i++){
fieldList.add(pd.getString(“field”+i).split(“,fh,”)); //属性放到集合里面
}
MapString,Object root = new HashMapString,Object(); //创建数据模型
root.put(“fieldList”, fieldList);
root.put(“packageName”, packageName); //包名
root.put(“objectName”, objectName); //类名
root.put(“objectNameLower”, objectName.toLowerCase()); //类名(全小写)
root.put(“objectNameUpper”, objectName.toUpperCase()); //类名(全大写)
root.put(“tabletop”, tabletop); //表前缀
root.put(“nowDate”, new Date()); //当前日期
DelAllFile.delFolder(PathUtil.getClasspath()+”admin/ftl”); //生成代码前,先清空之前生成的代码
/* ============================================================================================= */
String filePath = “admin/ftl/code/”; //存放路径
String ftlPath = “createCode”; //ftl路径
/*生成controller*/
Freemarker.printFile(“controllerTemplate.ftl”, root, “controller/”+packageName+”/”+objectName.toLowerCase()+”/”+objectName+”Controller.java”, filePath, ftlPath);
/*生成service*/
Freemarker.printFile(“serviceTemplate.ftl”, root, “service/”+packageName+”/”+objectName.toLowerCase()+”/”+objectName+”Service.java”, filePath, ftlPath);
/*生成mybatis xml*/
Freemarker.printFile(“mapperMysqlTemplate.ftl”, root, “mybatis_mysql/”+packageName+”/”+objectName+”Mapper.xml”, filePath, ftlPath);
Freemarker.printFile(“mapperOracleTemplate.ftl”, root, “mybatis_oracle/”+packageName+”/”+objectName+”Mapper.xml”, filePath, ftlPath);
/*生成SQL脚本*/
Freemarker.printFile(“mysql_SQL_Template.ftl”, root, “mysql数据库脚本/”+tabletop+objectName.toUpperCase()+”.sql”, filePath, ftlPath);
Freemarker.printFile(“oracle_SQL_Template.ftl”, root, “oracle数据库脚本/”+tabletop+objectName.toUpperCase()+”.sql”, filePath, ftlPath);
/*生成jsp页面*/
Freemarker.printFile(“jsp_list_Template.ftl”, root, “jsp/”+packageName+”/”+objectName.toLowerCase()+”/”+objectName.toLowerCase()+”_list.jsp”, filePath, ftlPath);
Freemarker.printFile(“jsp_edit_Template.ftl”, root, “jsp/”+packageName+”/”+objectName.toLowerCase()+”/”+objectName.toLowerCase()+”_edit.jsp”, filePath, ftlPath);
/*生成说明文档*/
Freemarker.printFile(“docTemplate.ftl”, root, “说明.doc”, filePath, ftlPath);
//this.print(“oracle_SQL_Template.ftl”, root); 控制台打印
/*生成的全部代码压缩成zip文件*/
FileZip.zip(PathUtil.getClasspath()+”admin/ftl/code”, PathUtil.getClasspath()+”admin/ftl/code.zip”);
/*下载代码*/
FileDownload.fileDownload(response, PathUtil.getClasspath()+”admin/ftl/code.zip”, “code.zip”);
}
}
创建一个StringBuilder对象,通过append方法来为其添加html语句。
StringBuilder sb = new StringBuilder();
Properties fileProperties = getProperties("file");
Properties sqlProperties = getProperties("sql");
PrintStream printStream = new PrintStream(new FileOutputStream(
"report.html"));
sb.append("html");
sb.append("head");
sb.append("title每日运营报表/title");
sb.append("meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /");
sb.append("style type=\"text/css\"");
sb.append("TABLE{border-collapse:collapse;border-left:solid 1 #000000; border-top:solid 1 #000000;padding:5px;}");
sb.append("TH{border-right:solid 1 #000000;border-bottom:solid 1 #000000;}");
sb.append("TD{font:normal;border-right:solid 1 #000000;border-bottom:solid 1 #000000;}");
sb.append("/style/head");
sb.append("body bgcolor=\"#FFF8DC\"");
sb.append("div align=\"center\"");
sb.append("br/");
sb.append("br/");
ListMapString, Object result1 = getRpt(sqlProperties
.getProperty("sql1"));
for (Map.EntryString, Object m : result1.get(0).entrySet()) {
sb.append(fileProperties.getProperty("file1"));
sb.append(m.getValue());
}
sb.append("br/br/");
输出
sb.append("/div/body/html");
printStream.println(sb.toString());
package tests;
/**
* 随机生成32位字符串
*/
public class String32 {
public static String random(int length){//传入的字符串的长度
StringBuilder builder = new StringBuilder(length);
for(int i = 0; i length; i++){
int r = (int) (Math.random()*3);
int rn1=(int)(48+Math.random()*10);
int rn2=(int)(65+Math.random()*26);
int rn3=(int)(97+Math.random()*26);
switch(r){
case 0:
builder.append((char)rn1);
break;
case 1:
builder.append((char)rn2);
break;
case 2:
builder.append((char)rn3);
break;
}
}
return builder.toString();
}
public static void main(String[] args){
String s = String32.random(32);
System.out.println(s);
}
}
那就传分类的参数,去生成呗,,,,,从数据中确定下一个编号
~
~
~
做自动测试时,使用yaml文件做界面要素配置,出现一个问题,经过自己的尝试实现了xpath方式的读取。把代码分项出来。尤其是在使用xpath是,会出现yaml读取出错的情况。此时需要将xpath的内容使用双引号括起来。代码如下
6
logout: type:name value:logoutlogoutConfirm: type:xpath value:"//*[@id='queding']//td/*//button"
来自CODE的代码片
snippet_file_0.txt
读取yaml文件的java代码如下
package com.bfm.utilities;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.util.HashMap;import org.ho.yaml.Yaml;/*该类为获取yaml文件中的内容*/public class YamlReader { private HashMapString, HashMapString, String yml; @SuppressWarnings("unchecked") public HashMapString, HashMapString, String getYamlFile(String yamlFile) { File f = new File(yamlFile); try { this.yml = (HashMapString, HashMapString, String) Yaml.loadType(new FileInputStream(f.getAbsolutePath()), HashMap.class); } catch (FileNotFoundException e) { e.printStackTrace(); } return this.yml; } public static void main (String args[]){ YamlReader yr = new YamlReader(); yr.getYamlFile("E:\\workspace\\bfm\\src\\com\\bfm\\pageElements\\mainPageElements.yaml"); }}