如何使Netbeans的模板创建多个文件? [英] How to make Netbeans' templates that creates more than 1 file?

查看:107
本文介绍了如何使Netbeans的模板创建多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Netbeans最强大的功能之一是使用一些FreeMarker模板生成代码。我有一些问题,我希望有人可以帮助我。

One of the most awesome features of Netbeans is to generate code using some FreeMarker templates. I have some questions about it, I hope someone here can help me.

如何在Netbeans上创建一个不仅仅生成1个文件的模板?

How can I make a template on Netbeans that generates more than just 1 file?

例如,我使用JSF Pages From Entity Beans向导生成 CRUD文件。因此它为我拥有的每个实体自动创建4个文件:

For example, I use the "JSF Pages From Entity Beans" wizard to generate CRUD files. So it creates automatically 4 files for each entity I have:

- Create.xhtml
- Edit.xhtml
- List.xhtml
- View.xhtml

这非常有用,因为你通常需要创建,编辑,列出或查看数据库中的某些记录。所以我知道我可以通过单击工具 - >模板 - > JavaServer Faces - > JSF实体 - > View.xhtml 来单独编辑每个模板。然后我可以改变生成 View.xhtml 的方式。然后在C:\ Users \yourname\.netbeans \6.9 \ config \Templates\JSF \ JSF_From_Entity_Wizard \ view.ftl上创建一个FTL文件。

This is very useful, because you often needs to create, edit, list or view some records from your database. So I know I can edit each template individually by clicking on Tools -> Templates -> JavaServer Faces -> JSF entity -> View.xhtml. And then I can change the way View.xhtml is generated. Then a FTL file is created on "C:\Users\yourname\.netbeans\6.9\config\Templates\JSF\JSF_From_Entity_Wizard\view.ftl".

但我想要更多,我还需要一个搜索页面。我的问题是我如何制作或更改像JSF Pages From Entity Beans这样的模板,它不仅生成1个文件,而且每个实体生成4个文件。所以我可以更改此模板以生成5个文件:

But I want more, I need also a Search page. My question is how can I make or change a template like "JSF Pages From Entity Beans" that generates not only 1 file, but 4 for each entity. So I can change this template to generate 5 files:

- Create.xhtml
- Edit.xhtml
- List.xhtml
- View.xhtml
- Search.xhtml (for example)

提前致谢!

推荐答案

您可以创建自己的项目模板。以下是执行此操作的一些说明:

You could create your own project template. Here's some instructions for doing that:

http://netbeans.dzone.com/tips/hack-your-own-custom-project-t

所以,您可以创建一个新项目并使用JSF Pages From Entity Beans向导,然后添加您自己的文件。然后你将从上面的链接的第2步开始并创建模板。

So, you could create a new project and use the "JSF Pages From Entity Beans" wizard and then add your own files. Then you would follow from step 2 of the above link and create the template.

编辑在给予这个更多的想法后我想你是什么我真正想要的是创建一个文件模板模块:

Edit After giving this some more thought I think that what you're really looking for is creating a File Template Module:

http://platform.netbeans.org/tutorials/60/nbm-filetemplates.html

编辑2:根据您的评论,我在Geertjan的博客上发布了一个网址,以简要说明如何从单个向导创建多个文件 *。但是,经过多次反思,我明白这也不是你想要的。您真正想要的是能够将另一个文件添加到现有向导(来自实体的JSF)。这当然是可能的,但不像创建自己的向导那么简单,因为执行此类操作的唯一方法是修改该特定模块的源代码(JSF支持)。

Edit 2: Based on your comment I'm posting a url to Geertjan's blog for a short description on how to create multiple files from a single wizard*. However, after more reflection I understand that this is also not what you want. What you really want is the ability to add another file to an existing wizard (JSF from Entity). This is of course possible but not as simple as creating your own wizard as the only way to do such a thing is to modify the source code for that particular module (JSF Support).

*了解上述教程仅显示了如何创建自己的新建文件向导的片段。假设有几个方面已经被理解,而没有讨论过。

*Understand that the above tutorial is showing only a snippet of how to create your own New File wizard. There are a few aspects that are assumed to be understood already and not discussed.

这篇关于如何使Netbeans的模板创建多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆