JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java SE 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Re:代換特殊字串有何好方法 [Re:hawkhero]
jason_chan19





發文: 175
積分: 1
於 2008-05-07 11:02 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
利用Groovy的template engines也可以做到,如下:

1
2
3
4
5
6
7
8
<myFile.template>
 
name:${myname} id:${myid} email:${myemail}
 
or
 
name:$myname id:$myid email:$myemail
 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<Main.groovy>
 
import java.io.*;
import groovy.text.*
 
class Main {
 
    static void main(args) {
      def url = Main.class.getResource("./myFile.template");
      
      def file = new File(url.getFile());
      def binding = ['myname': 'John',
                     'myid' : '001',
                     'myemail' : 'john@org.tw'];
    
      def engine = new SimpleTemplateEngine();
      def template = engine.createTemplate(file);
      def writable = template.make(binding);
      println writable;     //可得到 name:John id:001 email:john@org.tw
                   
  }
}
 


可以參考 http://groovy.codehaus.org/Groovy+Templates

至於Groovy的介紹請參考
http://groovy.codehaus.org/

Groovy...

* is an agile and dynamic language for the Java Virtual Machine
* builds upon the strengths of Java but has additional power features inspired by languages like Python, Ruby and Smalltalk
* makes modern programming features available to Java developers with almost-zero learning curve
* supports Domain-Specific Languages and other compact syntax so your code becomes easy to read and maintain
* makes writing shell and build scripts easy with its powerful processing primitives, OO abilities and an Ant DSL
* increases developer productivity by reducing scaffolding code when developing web, GUI, database or console applications
* simplifies testing by supporting unit testing and mocking out-of-the-box
* seamlessly integrates with all existing Java objects and libraries
* compiles straight to Java bytecode so you can use it anywhere you can use Java


jason_chan19 edited on 2008-05-07 11:13
reply to postreply to post
你若不想做,會找到一個藉口、你若想做,會找到一個方法
話題樹型展開
人氣 標題 作者 字數 發文時間
1334 代換特殊字串有何好方法 hawkhero 214 2008-05-06 13:43
1024 Re:代換特殊字串有何好方法 qrtt1 63 2008-05-06 19:50
1076 Re:代換特殊字串有何好方法 jason_chan19 1800 2008-05-07 11:02
1088 Re:代換特殊字串有何好方法 hawkhero 15 2008-05-07 15:00
» JWorld@TW »  Java SE 討論區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8