网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

自定义模板生成java代码 idea 自定义模板代码

自定义接口的JAVA代码

三个错:

成都创新互联是一家专业提供金秀企业网站建设,专注与网站设计制作、成都做网站、H5高端网站建设、小程序制作等业务。10年已为金秀众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。

1.Chicken 类里的howtoeat方法改howtoEat;

2.Apple类和Orange 放到Fruit 类外面。

3。Chicken 类的构造方法需要给重量参数,因为你只定义了一个构造方法。

我调试的没问题,改后代码:

interface Edible{

public String howtoEat();

}

class Animal{

}

class Chicken extends Animal implements Edible,Comparable{

int weight;

public Chicken(int weight){

this.weight=weight;

}

public String howtoEat(){

return "fry it";

}

public int compareTo(Object o){

return weight-((Chicken)o).weight;

}

}

class Tiger extends Animal{

}

abstract class Fruit implements Edible

{}

class Apple extends Fruit {

public String howtoEat(){

return "Make apple cider";

}

class Orange extends Fruit{

public String howtoEat(){

return "Make orange juice";

}

}

}

public class Test{

public static void main(String[] args){

Object[] objects={new Tiger(),new Chicken(10),new Apple()};

for(int i=0;iobjects.length;i++){

showObject(objects[i]);

}

}

public static void showObject(Object object){

if(object instanceof Edible)

System.out.println(((Edible)object).howtoEat());

}

}

java代码生成器怎么用

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”);

}

}

编写intellij idea 自动生成代码java.ft 怎么编辑

1、选择“Create New Project”

2、选择Java,然后点击Next

3、点击Next

4、填写项目名,然后点击Finish

5、在“src”目录上右击,选择“New”-“Java Class”

6、填写类名,然后点击OK

7、程序写完后点击绿色的箭头

8、选择第一项

9、完成。程序的输出显示在屏幕下方

如何创建自定义的java包

不知道你用的是什么平台,如果用的是Eclipse的话你只要在源代码的第一行加上package com.prefect.ecommerce; 如果是unix平台的话,你源代码里要是直接有package com.prefect.ecommerce;的话系统会直接自动给你生成的!classpath里面一般设置成“.”就好了

要是你想打jar包的话最好用Eclipse 在unix下要开一个终端输入jar命令

当然xp下如果你安装了jdk并设置好了全局变量也可以,具体的jar命令我想你的书上也有吧

求助,如何将FineReport建立好的表模板转换成java代码大神们帮帮忙

关键的关键是没有必要啊,你做好模板,放到服务器下面,配置好FR自带的Servlet形式的服务器,打开浏览器访问就可以了呀。 查看原帖

求采纳

如何使用Freemarker生成java代码

Freemarker是一个模板框架。我们可以通过Freemarker进行代码生成或页面的静态生成。 现在简单的说一下怎样使用Freemarker Freemarker的主要生成类

public boolean generate(String templateFileName, Map data,

String fileName) {

try {

//取得模板的位置

String templateFileDir=templateFileName.substring(0, templateFileName.lastIndexOf("/"));

//取得模板的名字

String templateFile=templateFileName.substring(templateFileName.lastIndexOf("/"), templateFileName.length());

//取得生成文件的路径

String genFileDir=fileName.substring(0, fileName.lastIndexOf("/"));

Template template = ConfigurationHelper.getConfiguration(templateFileDir).getTemplate(templateFile);

File fileDir=new File(genFileDir);

org.apache.commons.io.FileUtils.forceMkdir(fileDir);

File output = new File(fileName);

if(output.exists()){

//如何代码已存在不重复生成

return false;

}

Writer writer = new FileWriter(output);

template.process(data, writer);

writer.close();

} catch (TemplateException e) {

e.printStackTrace();

return false;

} catch (IOException e) {

e.printStackTrace();

return false;

}

return true;

}

代码中的Map 是模板所需要的数据,我们可以通过面向对像的方法把数据存在模板中public boolean genDaoInterface(String fileName){

DaoModel daoModel=new DaoModel();

//设置Dao实现类的包名

daoModel.setPackageName(DaoConstant.PACKAGE);

//取得接口名

String className=StringUtils.substringBefore(fileName,".");

//设置接口名

daoModel.setClassName(className);

MapString, Object data = new HashMapString, Object();

data.put("model", daoModel);

//设置生成的位置

String filePath=new String("src/"+package2path(DaoConstant.PACKAGE)+"/"+fileName);

//代码生成

return super.generate(DaoConstant.INTERFACE_TEMPLATE, data, filePath);

}

data.put("model", daoModel);由这句代码可看出我们将可以在模板中直接调用这些数据package ${model.packageName};

public interface ${model.className} extends BaseHibernateDao {

}


当前题目:自定义模板生成java代码 idea 自定义模板代码
本文来源:http://bjjierui.cn/article/dodegpd.html

其他资讯