??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲青青久久,久久精品国产精品亚洲综合,五月激情综合http://www.aygfsteel.com/rain1102/category/37638.html<br/><font color="green" style="font-family: 华文行楷;font-size:16px;">子曰Q危邦不入,乱邦不居。天下有道则见,无道则隐?lt;/font><font color="#3C1435"></font>zh-cnSun, 04 Apr 2010 02:26:21 GMTSun, 04 Apr 2010 02:26:21 GMT60Grails五行代码实现囄上传与展C?/title><link>http://www.aygfsteel.com/rain1102/archive/2010/04/01/317219.html</link><dc:creator>Eric.Zhou</dc:creator><author>Eric.Zhou</author><pubDate>Thu, 01 Apr 2010 11:52:00 GMT</pubDate><guid>http://www.aygfsteel.com/rain1102/archive/2010/04/01/317219.html</guid><wfw:comment>http://www.aygfsteel.com/rain1102/comments/317219.html</wfw:comment><comments>http://www.aygfsteel.com/rain1102/archive/2010/04/01/317219.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/rain1102/comments/commentRss/317219.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/rain1102/services/trackbacks/317219.html</trackback:ping><description><![CDATA[<p>域中写如下代码:<font color="#ff3300"><code><br /> class Something{<br /> byte[] image<br /> }</code></font></p> <p>控制器中展示囄的方?/p> <p><font color="#ff3300"><code>def image= {<br /> def something = Something.get( params.id )<br /> byte[] image = something.image<br /> response.outputStream << image<br /> }<br /> </code></font></p> <p>面展示</p> <p><font color="#ff3300"><code><img src="${createLink(controller:'something', action:'image', id: something.id)}"/></code></font></p> <!--adcode--><img src ="http://www.aygfsteel.com/rain1102/aggbug/317219.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/rain1102/" target="_blank">Eric.Zhou</a> 2010-04-01 19:52 <a href="http://www.aygfsteel.com/rain1102/archive/2010/04/01/317219.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用Grails和Rome产生Rss [转蝲]http://www.aygfsteel.com/rain1102/archive/2008/09/07/227606.htmlEric.ZhouEric.ZhouSun, 07 Sep 2008 14:53:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/09/07/227606.htmlhttp://www.aygfsteel.com/rain1102/comments/227606.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/09/07/227606.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/227606.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/227606.htmlGrails本n好像q没有生rss的插件。如果要用grails产生RssQ可以用Rome。方法大概如下:

下蝲需要的库文?/h2>

?a >https://rome.dev.java.net/下蝲RomeQ之后把rome-xxx.jar攑ֈ你的grails目的lib目录下。这里xxx是版本号。比如我的是rome-1.0RC1.jar

再到http://www.jdom.org/下蝲JDom。之后同h把jdom.jar攑ֈlib目录下?/p>

书写代码

创徏一个controllerQ当然你也可以在你已l有的controller里面增加相应Ҏ。这里我们创Z个叫做FeedController的类?br />

 1 import com.sun.syndication.feed.synd.*;   
 2 import com.sun.syndication.io.SyndFeedOutput;   
 3                
 4 class FeedController {   
 5        
 6     def supportedFormats = [ "rss_0.90""rss_0.91""rss_0.92""rss_0.93""rss_0.94""rss_1.0""rss_2.0""atom_0.3"]   
 7   
 8                   
 9                                 
10        
11     def rss = {   
12                
13             render(text: getFeed("rss_1.0"), contentType:"text/xml", encoding:"UTF-8")   
14        
15     }   
16        
17     def atom = {   
18                
19             render(text: getFeed("atom_1.0"), contentType:"text/xml", encoding:"UTF-8")   
20                        
21     }   
22   
23     // or specify your own feed type   
24     def all = {   
25             def format = params.id   
26             if (supportedFormats.contains(format)) {   
27                 render(text: getFeed(format), contentType:"text/xml", encoding:"UTF-8")   
28             } else {   
29                 response.sendError(response.SC_FORBIDDEN);   
30             }                  
31     }   
32        
33        
34     def getFeed(feedType) {   
35            
36         def items = Post.list(max: 5, sort: "created", order: "desc")   
37                
38         def entries = []   
39         items.each { item ->   
40             def desc = new SyndContentImpl(type: "text/plain", value: item.description);   
41             def entry = new SyndEntryImpl(title: item.name + " - " + item.summary,    
42                     link: 'http://www.ondev.net/item/show/' + item.name,   
43                     publishedDate: item.created, description: desc);   
44             entries.add(entry);   
45   
46         }   
47         SyndFeed feed = new SyndFeedImpl(feedType: feedType, title: '标题',   
48                 link: 'http://www.ondev.net', description: '说明性文?/span>',   
49                 entries: entries);   
50            
51         StringWriter writer = new StringWriter();   
52         SyndFeedOutput output = new SyndFeedOutput();   
53         output.output(feed,writer);   
54         writer.close();   
55            
56         return writer.toString();   
57   
58            
59     }   
60        
61 }  
62 

之后讉K相应的页面,比如?a >http://www.ondev.net/feed/rss可以了

原脓地址Q?http://www.ondev.net/story/show/75



Eric.Zhou 2008-09-07 22:53 发表评论
]]>
lGrailsd验证码插件之jcaptcha-1.0http://www.aygfsteel.com/rain1102/archive/2008/08/28/225433.htmlEric.ZhouEric.ZhouThu, 28 Aug 2008 14:54:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/08/28/225433.htmlhttp://www.aygfsteel.com/rain1102/comments/225433.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/08/28/225433.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/225433.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/225433.html 而jcaptcha-1.0l于出来? 比v0.2轻量了很? 而且0.2里面有不无用的东西...
现在grails-app下面主要的文件就剩下JcaptchaController.groovy, JcaptchaService.groovy, JcaptchaTagLib.groovy?
JcaptchaTagLib.groovy里面其实也就定义了两个标{? 一个用户图片验?jpeg), 一个用于语音验?wav).
JcaptchaController.groovy里面则定义了主要两个action(jpeg和wav)用于JcaptchaTagLib.groovy的两个标{调?
JcaptchaService.groovy则定义了四个常用Ҏ, 主要是boolean validateResponse(captchaName, id, response)用于验证输入验证码是否正?br />
下面看看使用验证码代?
首先需要在Config.groovy, d:
import Java.awt.Font
import Java.awt.Color
import com.octo.captcha.service.multitype.GenericManageableCaptchaService
import com.octo.captcha.engine.GenericCaptchaEngine
import com.octo.captcha.image.gimpy.GimpyFactory
import com.octo.captcha.component.word.wordgenerator.RandomWordGenerator
import com.octo.captcha.component.image.wordtoimage.ComposedWordToImage
import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator
import com.octo.captcha.component.image.backgroundgenerator.GradientBackgroundGenerator
import com.octo.captcha.component.image.color.SingleColorGenerator
import com.octo.captcha.component.image.textpaster.NonLinearTextPaster

jcaptchas { 
        imageCaptcha = new GenericManageableCaptchaService( 
            new GenericCaptchaEngine( 
                new GimpyFactory( 
                    new RandomWordGenerator( 
                        "abcdefghijklmnopqrstuvwxyz1234567890" 
                    ), 
                    new ComposedWordToImage( 
                        new RandomFontGenerator(                 // 生成囄文字的字体以及字号大,可以是多U字体,会随机出现?br />                             20, // min font size 
                            30, // max font size 
                            [new Font("Arial", 0, 10)] as Font[] 
                        ), 
                        new GradientBackgroundGenerator(       // 配置验证囄的大和背景色以及过渡色
                            140, // width 
                            35, // height 
                            new SingleColorGenerator(new Color(255, 255, 255)), 
                            new SingleColorGenerator(new Color(200, 200, 200)) 
                        ), 
                        new NonLinearTextPaster( 
                            4, // minimal length of text 
                            4, // maximal length of text 
                            new Color(11, 11, 11) 
                        ) 
                    ) 
                ) 
            ), 
            180, // minGuarantedStorageDelayInSeconds 
            180000 // maxCaptchaStoreSize 
        )


面中添?
< input id="captchaResponse" maxlength="30" name="captchaResponse" type="text" />
< jcaptcha:jpeg name="imageCaptcha" width="100px" height="25px" >< /jcaptcha:jpeg >

Controller里面要做验证
if (!jcaptchaService.validateResponse("imageCaptcha", session.id, params.captchaResponse)){
    flash.message = message(code:'pinpin.login.invalid.jcaptcha')
    return
}

Eric.Zhou 2008-08-28 22:54 发表评论
]]>
groovy中list去除重复数据http://www.aygfsteel.com/rain1102/archive/2008/08/02/219567.htmlEric.ZhouEric.ZhouSat, 02 Aug 2008 05:55:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/08/02/219567.htmlhttp://www.aygfsteel.com/rain1102/comments/219567.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/08/02/219567.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/219567.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/219567.html 1. 循环list中的所有元素然后删除重?br />     public   static   List  removeDuplicate(List list)  {
      for  ( int  i  =   0 ; i  <  list.size()  -   1 ; i ++ ) 
{
          for  ( int  j  =  list.size()  -   1 ; j  >  i; j -- ) 
{
               if  (list.get(j).equals(list.get(i))) 
{
                  list.remove(j);
                }

            }

          } 

        return list;
    }

2. 通过HashSett除重复元素
    public   static   List  removeDuplicate(List list)  {
        HashSet h  =   new
 HashSet(list);
        list.clear();
        list.addAll(h);
        return list;
     }

在groovy中当然也可以使用上面的两U方? 但groovy自己提供了uniqueҎ来去除重复数?br />     def list = [1, 2, 3, 2, 4, 1, 5]
    list.unique()  // [1, 2, 3, 4, 5]


Eric.Zhou 2008-08-02 13:55 发表评论
]]>
Grails Yahoo! UI Library (YUI) Pluginhttp://www.aygfsteel.com/rain1102/archive/2008/07/29/218550.htmlEric.ZhouEric.ZhouTue, 29 Jul 2008 14:38:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/07/29/218550.htmlhttp://www.aygfsteel.com/rain1102/comments/218550.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/07/29/218550.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/218550.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/218550.htmlThis plugin provides integration with the Yahoo! UI Library. When installing the plugin, it downloads and installs automatically the latest YUI 2.5.2 distribution in your application, and registers itself to be used with the adapative AJAX tags. It also contains two helper tags to easily include additional YUI javascript and css files as well.

Installation

To install the YUI plugin type this command from your project's root folder:

grails install-plugin yui
The complete YUI distribution is downloaded and installed under your project's web-appjsyui2.5.2 folder.

Usage

To use Grails' adaptive AJAX support just add the folowing line in the head section:

<g:javascript library="yui" />
If you want to include additional YUI javascript and css files include them using:
<yui:javascript dir="calendar" file="calendar-min.js" />
<yui:javascript dir="calendar" file="calendar-min.js" version="2.5.2" />
// version to be used in case multiple version installed
<yui:stylesheet dir="calendar/assets" file="calendar.css" />
Refer to the Ajax section of the Grails reference documentation for usage.

Overriding default javascript files

By default only yahoo-dom-event.js and connection-min.js are included when using <g:javascript library="yui" />. Adding additional libraries to the default list can be done in a BootStrap (+) class:

import org.codehaus.groovy.grails.plugins.web.taglib.JavascriptTagLib

class BootStrap { def init = { servletContext -> JavascriptTagLib.LIBRARY_MAPPINGS.yui += ["yui/2.5.2/calendar/calendar-min", "yui/2.5.2/container/container-min"] } def destroy = { } }

It's also possible to replace all default included javascript libraries. For example if you want to use the YUI debug javascript files in development mode:
import grails.util.GrailsUtil
import org.codehaus.groovy.grails.plugins.web.taglib.JavascriptTagLib

class BootStrap { def init = { servletContext -> if (GrailsUtil.isDevelopmentEnv()) { JavascriptTagLib.LIBRARY_MAPPINGS.yui = ["yui/2.5.2/yahoo/yahoo-debug", "yui/2.5.2/dom/dom-debug", "yui/2.5.2/event/event-debug", "yui/2.5.2/connection/connection-debug"] } } def destroy = { } }

Serving YUI Files from Yahoo! Servers

It's also possible to serve the javascript from the Yahoo! servers. First delete the yui folder from web-appjs after installing the plugin. Then, in a BootStrap class, override the mapping which contains the javascript files to include by default:

import org.codehaus.groovy.grails.plugins.web.taglib.JavascriptTagLib

class BootStrap { def init = { servletContext -> JavascriptTagLib.LIBRARY_MAPPINGS.yui = [] } def destroy = { } }

The only drawback is that you need to include the references to the javascript files manually. Probably the easiest way is to do this in the main.gsp layout.

Upgrading

If you want to upgrade:

  • Delete the plugin from the project's plugins folder
  • (Optional) Delete the previous YUI version folder from web-appjsyui
  • Re-install the plugin by executing grails install-plugin yui


Eric.Zhou 2008-07-29 22:38 发表评论
]]>
Grails初始化系l数?/title><link>http://www.aygfsteel.com/rain1102/archive/2008/07/28/218206.html</link><dc:creator>Eric.Zhou</dc:creator><author>Eric.Zhou</author><pubDate>Mon, 28 Jul 2008 15:02:00 GMT</pubDate><guid>http://www.aygfsteel.com/rain1102/archive/2008/07/28/218206.html</guid><wfw:comment>http://www.aygfsteel.com/rain1102/comments/218206.html</wfw:comment><comments>http://www.aygfsteel.com/rain1102/archive/2008/07/28/218206.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/rain1102/comments/commentRss/218206.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/rain1102/services/trackbacks/218206.html</trackback:ping><description><![CDATA[<span style="font-size: 7pt; color: black; font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial"><span style="font-size: 12pt"><span style="color: black; font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">比如当应用启动时候往user表中d一条数?修改</span><span lang="EN-US" style="color: black; font-family: Arial; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"> grails-app\config\BootStrap.groovy </span><span style="color: black; font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">的代码:<br />   <p style="line-height: 14.25pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-size: 8.5pt; color: black; font-family: 'Lucida Console'"><span style="font-size: 10pt">class BootStrap {</span></span></p> <p style="line-height: 14.25pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-size: 8.5pt; color: black; font-family: 'Lucida Console'"><span style="font-size: 10pt">    def init = { servletContext -></span></span></p> <p style="line-height: 14.25pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-size: 8.5pt; color: black; font-family: 'Lucida Console'"><span style="font-size: 10pt">        def user = new Users(id:1,username:'rain'</span></span></p> <p style="line-height: 14.25pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-size: 8.5pt; color: black; font-family: 'Lucida Console'"><span style="font-size: 10pt">           ,password:'1102')</span></span></p> <p style="line-height: 14.25pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-size: 8.5pt; color: black; font-family: 'Lucida Console'"><span style="font-size: 10pt">        user.password = user.password.encodeAsPassword()</span></span></p> <p style="line-height: 14.25pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-size: 8.5pt; color: black; font-family: 'Lucida Console'"><span style="font-size: 10pt">        user.save()</span></span></p> <p style="line-height: 14.25pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-size: 8.5pt; color: black; font-family: 'Lucida Console'"><span style="font-size: 10pt">    }</span></span></p> <p style="line-height: 14.25pt; text-align: left; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" align="left"><span style="font-size: 8.5pt; color: black; font-family: 'Lucida Console'"><span style="font-size: 10pt">    def destroy = { }</span></span></p> <span style="font-size: 8.5pt; color: black; font-family: 'Lucida Console'"><span style="font-size: 10pt">}</span></span></span></span></span><img src ="http://www.aygfsteel.com/rain1102/aggbug/218206.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/rain1102/" target="_blank">Eric.Zhou</a> 2008-07-28 23:02 <a href="http://www.aygfsteel.com/rain1102/archive/2008/07/28/218206.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Grails中用SHA 对密码加?/title><link>http://www.aygfsteel.com/rain1102/archive/2008/07/28/218205.html</link><dc:creator>Eric.Zhou</dc:creator><author>Eric.Zhou</author><pubDate>Mon, 28 Jul 2008 15:00:00 GMT</pubDate><guid>http://www.aygfsteel.com/rain1102/archive/2008/07/28/218205.html</guid><wfw:comment>http://www.aygfsteel.com/rain1102/comments/218205.html</wfw:comment><comments>http://www.aygfsteel.com/rain1102/archive/2008/07/28/218205.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/rain1102/comments/commentRss/218205.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/rain1102/services/trackbacks/218205.html</trackback:ping><description><![CDATA[ҎGrails的命名规? ?span lang="EN-US">grails-app\utils </span><span>中创Z个名?/span><span> </span><span lang="EN-US">PasswordCodec</span><span lang="EN-US"> </span><span>?/span><span lang="EN-US"> Groovy </span><span>c?一下类名必需?/span><span lang="EN-US"> XXXCodec)</span> , 代码如下:<br /> <br /> import <a title="Java爱好? href="http://www.aygfsteel.com/rain1102" >Java</a>.security.MessageDigest<br /> import sun.misc.BASE64Encoder<br /> /**<br />  *<br />  * @author eric<br />  */<br /> class PasswordCodec {<br />     static encode = {str -><br />         MessageDigest md = MessageDigest.getInstance('SHA')<br />         md.update(str.getBytes('UTF-8'))<br />         return (new BASE64Encoder()).encode(md.digest())<br />     }<br /> }<br /> 写好以后,使用如下:<br /> user.save()user.password = user.password.<span style="color: red">encodeAsPassword</span>()<br /> user.save()<br /> <br /> def user = User.findByUserNameAndPassword(params.userName, params.password.<span style="color: red">encodeAsPassword</span>())<br /> <br /> <br /><img src ="http://www.aygfsteel.com/rain1102/aggbug/218205.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/rain1102/" target="_blank">Eric.Zhou</a> 2008-07-28 23:00 <a href="http://www.aygfsteel.com/rain1102/archive/2008/07/28/218205.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在NetBeans IDE中创建Grails插g[转]http://www.aygfsteel.com/rain1102/archive/2008/07/28/218004.htmlEric.ZhouEric.ZhouMon, 28 Jul 2008 03:35:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/07/28/218004.htmlhttp://www.aygfsteel.com/rain1102/comments/218004.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/07/28/218004.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/218004.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/218004.htmlCreating a Grails Plugin in NetBeans IDE

Let's create a plugin for Grails. Grails is, after all, modular and pluggable. Here's the ultimate simple Grails plugin, just to give an idea what is involved, from start to finish. The most useful references I have found so far are these:

Between those three, you should have enough to figure things out. I still found it hard, despite those instructions and so to avoid having to figure things out again some time in the future, I'll write absolutely everything here.

Creating the Plugin

  1. On the command line, run this:
    grails create-plugin SamplePlugin

    Now you have a Grails plugin. However, at the same time it is just another Grails application, which means you can simply open it in NetBeans IDE. (I.e., there is no import process and no NetBeans artifacts are added to the plugin in order to be able to open it in the IDE.)

     

  2. So open the plugin in the IDE. The Projects window isn't very interesting, it just shows you the same as you would normally see for Grails applications:

    The Files window (Ctrl-2) however, shows a lot more:

    Open the "SamplePluginGrailsPlugin.groovy" file and there you see the following:

    class SamplePluginGrailsPlugin {
        def version = 0.1
        def dependsOn = [:]
        def doWithSpring = {
        // TODO Implement runtime spring config (optional)
        }
        def doWithApplicationContext = { applicationContext ->
        // TODO Implement post initialization spring config (optional)
        }
        def doWithWebDescriptor = { xml ->
        // TODO Implement additions to web.xml (optional)
        }
        def doWithDynamicMethods = { ctx ->
        // TODO Implement registering dynamic methods to classes (optional)
        }
        def onChange = { event ->
        // TODO Implement code that is executed when this class plugin class is changed
        // the event contains: event.application and event.applicationContext objects
        }
        def onApplicationChange = { event ->
        // TODO Implement code that is executed when any class in a GrailsApplication changes
        // the event contain: event.source, event.application and event.applicationContext objects
        }
        }

    I.e., you have hooks for integrating your code into meaningful places in the plugin.

     

  3. Now we'll create code that will let our plugin provide a new "constraint". (If you don't know what that is, you will know by the time you finish reading all this.) To do so, we will need to extend org.codehaus.groovy.grails.validation.AbstractConstraint, in a package within src/groovy:
    import org.codehaus.groovy.grails.validation.AbstractConstraint
        import org.springframework.validation.Errors
        class BestFrameworkConstraint extends AbstractConstraint {
        private static final String DEFAULT_MESSAGE_CODE = "default.answer.invalid.message";
        public static final String NAME = "oneCorrectResponse";
        private boolean validateConstraint
        //The parameter which the constraint is validated against:
        @Override
        public void setParameter(Object constraintParameter) {
        if (!(constraintParameter instanceof Boolean))
        throw new IllegalArgumentException("Parameter for constraint ["
        + NAME + "] of property ["
        + constraintPropertyName + "] of class ["
        + constraintOwningClass + "] must be a boolean value");
        this.validateConstraint = ((Boolean) constraintParameter).booleanValue()
        super.setParameter(constraintParameter);
        }
        //Returns the default message for the given message code in the current locale:
        @Override
        protected void processValidate(Object target, Object propertyValue, Errors errors) {
        if (validateConstraint && !validate(target, propertyValue)) {
        def args = (Object[]) [constraintPropertyName, constraintOwningClass,
        propertyValue]
        super.rejectValue(target, errors, DEFAULT_MESSAGE_CODE,
        "not." + NAME, args);
        }
        }
        //Returns whether the constraint supports being applied against the specified type:
        @Override
        boolean supports(Class type) {
        return type != null && String.class.isAssignableFrom(type);
        }
        //The name of the constraint, which the user of the plugin will use
        //when working with your plugin.
        @Override
        String getName() {
        return NAME;
        }
        //Validate this constraint against a property value,
        //In this case, ONLY "Grails" is valid, everything else will cause an error:
        @Override
        boolean validate(target, propertyValue) {
        propertyValue ==~ /^Grails$/
        }
        }

     

  4. Next, back in the Groovy plugin class that we looked at earlier, hook the above class into the plugin, using the "doWithSpring" closure to do so:
    def doWithSpring = {
        org.codehaus.groovy.grails.validation.ConstrainedProperty.registerNewConstraint(
        BestFrameworkConstraint.NAME,
        BestFrameworkConstraint.class);
        }

     

  5. Now, back on the command line, navigate to within the "SamplePlugin" folder. There, run the following:
    grails package-plugin

    Back in the IDE, examine the ZIP file that the above command created:

That ZIP file is your Grails plugin.

Installing the Plugin

Now we will install our plugin in a new application.

  1. First, create a new Grails application by going to the New Project wizard (Ctrl-Shift-N) and choosing Groovy | Grails Application. Click Next and type "SampleApplication" and then click Finish.

     

  2. After the IDE has finished running the "grails create-app" command for you, you will see the new application open in the IDE. Right-click it and choose "Plugins", as shown here:

     

  3. In the Grails Plugins dialog, notice that the list gets filled with many potential plugins that you might want to install, from the Grails plugins repository. Instead, we'll install our own. Click Browse and browse to the ZIP file that we created three steps ago and notice that it appears in the text field at the bottom of the dialog:

     

  4. Click "Install" and then a progress bar appears, ending with the plugin being installed. Notice that you can also uninstall it:

     

  5. Take a look at your application and notice (in the Files window) what's happened to the plugin. It's been unzipped, plus the ZIP file is still there. And all that's been done in the "plugins" folder. Nothing else has changed, which means that uninstallation is as simple as removing the folder from the "plugins" folder:

    Thanks to "convention over configuration", Grails knows exactly where everything is—so that, for example, the "plugin.xml" file that you see above, if found within the folder structure you see above, is the indicator to Grails that a plugin is available for use.

Using the Functionality Provided By the Plugin

  1. Let's now use our plugin. Create a domain class called "Quiz", after right-clicking the "Domain Classes" node and choosing "Create new Domain Class":

     

  2. Right-click the "Controllers" node and choose "Create new controller". Type "Quiz" and then click Finish. Use the Groovy editor to add one line for adding the scaffolding (and uncomment the other line):

     

  3. Back in the "Quiz" domain class, add your property and use the "oneCorrectResponse" constraint defined in your plugin, as shown here:

    Note: The "oneCorrectResponse" constraint that you see above is the name of the constraint defined in the plugin.

     

  4. And then add the message to the messages.properties file, which is within the "Messages Bundles" node:

     

  5. Run the application and you will see that your constraint will prevent anything other than "Grails" from being considered acceptable, when "Create" is clicked below:

Congratulations, you've created, installed, and used your first Grails plugin!



Eric.Zhou 2008-07-28 11:35 发表评论
]]>
Grails中用Fck-editorhttp://www.aygfsteel.com/rain1102/archive/2008/07/26/217648.htmlEric.ZhouEric.ZhouSat, 26 Jul 2008 05:32:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/07/26/217648.htmlhttp://www.aygfsteel.com/rain1102/comments/217648.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/07/26/217648.html#Feedback2http://www.aygfsteel.com/rain1102/comments/commentRss/217648.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/217648.htmlhttp://svn.codehaus.org/grails-plugins/grails-fck-editor/tags/RELEASE_0_3/grails-fck-editor-0.3.zip ?br /> 攑ֈ盘?比如 D:/down/grails-fck-editor-0.3.zip
安装: grails install-plugin D:/down/grails-fck-editor-0.3.zip
q里我用的是grails1.0.3, 在干装的时候会报错..
Grails Bug: If the plugin wasn't loaded it should be in the failed plugins list,
but is not. Please report the issue.
Java.lang.IllegalArgumentException: Grails Bug: If the plugin wasn't loaded it s
hould be in the failed plugins list, but is not. Please report the issue.

q时候到自己的工E目录下扑ֈplugins文g? 解压grails-fck-editor-0.3.zip到当前目?
在页面里使用fck标签:
<fck:editor id="content" name="content" height="400">
          ${fieldValue(bean:news,field:'content')}
</fck:editor>

启动目,


Eric.Zhou 2008-07-26 13:32 发表评论
]]>
Grails中sortableColumn标签改写支持ajaxhttp://www.aygfsteel.com/rain1102/archive/2008/07/23/217039.htmlEric.ZhouEric.ZhouWed, 23 Jul 2008 14:49:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/07/23/217039.htmlhttp://www.aygfsteel.com/rain1102/comments/217039.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/07/23/217039.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/217039.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/217039.html前两天从同事那里得来需? 要求一个主面里面使用ajax加蝲一个表? q且需要表头点M后可以排? 刚才看了一下grails中的sortableColumn标签源码, 该标{最后其实就是生成了一个普通的link.
${link(action:action, params:linkParams) { title }}
很简? 只需要修改link的生成方? 使用remoteLink来生成就可以?
def update = attrs.remove("update")
...
${remoteLink(action:action,update:update, params:linkParams) { title }}
当然update那个值需要传q来? 面里面改写成:
<g:sortableColumnEric property="id" title="Id" update="userlist"/>
一切ok.
有了排序, 当然分页也要q样? 实现应该差不?..
把所有的link(linkTagAttrs.clone())改ؓremoteLink(linkTagAttrs.clone())
q里也别忘了要传个update参数q来?
修改def linkTagAttrs = [action:action]?
def update = attrs.remove("update")
def linkTagAttrs = [action:action, update:update]

面里就要改?
<g:paginateEric update="userlist" total="${User.count()}" maxsteps="3"/>



Eric.Zhou 2008-07-23 22:49 发表评论
]]>
Grails的域c验证详解[转]http://www.aygfsteel.com/rain1102/archive/2008/07/21/216470.htmlEric.ZhouEric.ZhouMon, 21 Jul 2008 14:47:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/07/21/216470.htmlhttp://www.aygfsteel.com/rain1102/comments/216470.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/07/21/216470.html#Feedback3http://www.aygfsteel.com/rain1102/comments/commentRss/216470.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/216470.html在Grails里,我们可以通过定义U束属性来验证一个领域类的实例。约束属性在一个叫“constraints”闭包的定义。可以ؓ领域c里的每个属性定义约束?br />
class User {
String login
String password
String email
Date age

static constraints = {
login(length:5..15,blank:false,unique:true)
password(length:5..15,blank:false)
email(email:true,blank:false)
age(min:new Date(),nullable:false)
}
}

constraints必须声明为static?/p>

同时Q每个属性的U束属性都有与之对应的错误消息QError message codeQ,当表单未能通过验证的时候,会q回q些错误消息?br /> q些错误消息?strong>grails-app/i18n/message.properties里定义?br /> 例如我们要让User的email为空时返?Please enter your email"Q则可以在message.properties定义Q?br /> user.email.blank=Please enter your email
如果用户没有自定义错误消息,pȝ则会用默认的讄。当焉认的消息肯定不会是你惌?#8230;…

Grails提供很多验证属性,可以满一些基本的验证需求:

blank
验证属性能否ؓI,不允ؓI则设ؓfalse?br /> Note: 如果在form里ؓI提交,则属性的值是一个空字符Ԍ而不是null?br /> Example: login(blank:false)
Error message code: className.propertyName.blank

creditCard
如果要求属性ؓ信用卡号码,则设为true?br /> Example: cardNumber(creditCard:true)
Error message code: className.propertyName.creditCard.invalid

email
如果要求属性ؓemial地址Q则设ؓtrue?br /> Example: contactEmail(email:true)
Error message code: className.propertyName.email.invalid

inList
如果要求属性的值必Mؓ规定的|则定义规定的倹{?br /> Example: name(inList:["Joe", "Fred", "Bob"] )
Error message code: className.propertyName.not.inList

length
U束字符串或者数l的长度?br /> q个U束属性在0.5版本是被取消Q用size代替?/font>
Example: login(length:5..15)
Error message code:
className.propertyName.length.toolong
className.propertyName.length.tooshort

matches
应用正则表达式对字符串进行验证?br /> Example: login(matches:"[a-zA-Z]+")
Error message code: className.propertyName.matches.invalid

max
讑֮属性的最大|值的cd必须跟属性一栗?br /> Example:
age(max:new Date())
price(max:999F)
Error message code: className.propertyName.max.exceeded

maxLength
讑֮字符串或者数l的最大长度?br /> ?.5版本中被取消Q由maxSize代替?/font>
Example: login(maxLength:5)
Error message code: className.propertyName.maxLength.exceeded

maxSize
讑֮一个数字或者集合的最大大?br /> ?.5版本中不被徏议用在数字上Q改用max?/font>
Example: children(maxSize:25)
Error message code: className.propertyName.maxSize.exceeded

min
讑֮属性的最倹{类型必跟属性一致?br /> Example:
age(min:new Date())
price(min:0F)
Error message code: className.propertyName.min.notmet

minLength
讑֮字符串属性或者数l属性的最长度?br /> ?.5版本中被取消Q由minSize代替?/font>
Example: login(minLength:5)
Error message code: className.propertyName.minLength.notmet

minSize
讑֮一个数字或者集合的最大?br /> ?.5版本中不被徏议用在数字属性上Q改用min?/font>
Example: children(minSize:5)
Error message code: className.propertyName.minSize.notmet

notEqual
验证属性的值是否跟指定的值相{?br /> Example: login(notEqual:"Bob")
Error message code: className.propertyName.notEqual

nullable
如果属性不可以为nullQ则设ؓfalse?br /> Note: 如果在表单里未填M东西而提交时Q则作ؓrequest parameterQ属性的gؓ一个空字符Ԍ而不是null?br /> Example: age(nullable:false)
Error message code: className.propertyName.nullable

range
限制属性的值在指定的范围里?br /> Example: age(range:minAge..maxAge)
Error message code:
className.propertyName.range.toosmall
className.propertyName.range.toobig

scale
版本0.4才开始出现的U束属性?br /> Ҏ讑֮的scale数|自动把Q点型数字数点后的位数调整ؓ讑֮的倹{?br /> 适用于以下数值类型:java.lang.Float, Java.lang.Double, and Java.math.BigDecimal (and its subclasses)?br /> Example: salary(scale:2)
Error message code: 不返回错误信?/p>

size
规定一个数|集合或者字W串长度的大?br /> 在版?.5中不被徏议用在数字类型的属性上Q改用range?/font>
Example: children(size:5..15)
Note: 不能使用q个U束属性如果blank设ؓtrue或者nullable设ؓtrue?br /> Error message code:
className.propertyName.size.toosmall
className.propertyName.size.toobig

unique
如果属性必Mؓ唯一Q则设ؓtrue?br /> Example: login(unique:true)
Note: 有可能会发生通过unique验证但是在随后的数据库储存出现错误的情况。预防这U情况发生的Ҏ是用连l事务隔ȝ别或者进行eception的处理?br /> 从版?.5开始,unique的范_ScopeQ可以被指定?Scope"是同一个类里其他属性的名字Q或者这些属性名字的一个list?br /> Example: group(unique:'department')
上面的例子里group名在一个department里是唯一的,但是可能在其他department里有相同名字的groups?br /> Another Example: login(unique:['group','department'])
在这个例子,login在group和department里必L唯一的。可能在不同{group和department里会有相同的login?br /> Error message code: className.propertyName.unique

url
如果属性ؓ一个URL地址Q则设ؓtrue?br /> Example: homePage(url:true)
Error message code: className.propertyName.url.invalid

validator
在闭包里讑֮自定义的验证?br /> Example:
even( validator: {
return (it % 2) == 0
})
Error message code (default): className.propertyName.validator.invalid
会在另外的文章里进行介l?/p>

Eric.Zhou 2008-07-21 22:47 发表评论
]]>
Grails中Service层事务处?/title><link>http://www.aygfsteel.com/rain1102/archive/2008/07/21/216447.html</link><dc:creator>Eric.Zhou</dc:creator><author>Eric.Zhou</author><pubDate>Mon, 21 Jul 2008 13:29:00 GMT</pubDate><guid>http://www.aygfsteel.com/rain1102/archive/2008/07/21/216447.html</guid><wfw:comment>http://www.aygfsteel.com/rain1102/comments/216447.html</wfw:comment><comments>http://www.aygfsteel.com/rain1102/archive/2008/07/21/216447.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/rain1102/comments/commentRss/216447.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/rain1102/services/trackbacks/216447.html</trackback:ping><description><![CDATA[在Grails中Service层默认就是支持事务的,事务传播U别默认是PROPAGATION_REQUIRED.  当然你也可以讄transactional = false.<br /> 如果transactional 讄为true, 则在Service层如何方法内部抛出RuntimeExceptioncd异常, 所有操作将会回?<br /> <p>class UserService {</p> <p>    <span style="color: #008000">boolean transactional = true</span></p> <p>    public boolean register(User user, UserInfo userInfo) throws RuntimeException {<br />         if (user.save()) {<br />             userInfo.user = user<br />             if (userInfo.save()) {<br />                 return true<br />             } else {<br />                 throw new <span style="color: #008000">RuntimeException </span>('ServiceException: UserService.register()...');<br />             }<br />         } else {<br />             throw new <span style="color: #008000">RuntimeException </span>('ServiceException: UserService.register()...');<br />         }<br />     }<br /> }</p> q样不管哪个保存p|, 数据都将会回?<img src ="http://www.aygfsteel.com/rain1102/aggbug/216447.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/rain1102/" target="_blank">Eric.Zhou</a> 2008-07-21 21:29 <a href="http://www.aygfsteel.com/rain1102/archive/2008/07/21/216447.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Grails中的领域cMU束,验证以及错误消息处理http://www.aygfsteel.com/rain1102/archive/2008/07/20/216253.htmlEric.ZhouEric.ZhouSun, 20 Jul 2008 14:20:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/07/20/216253.htmlhttp://www.aygfsteel.com/rain1102/comments/216253.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/07/20/216253.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/216253.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/216253.htmlGrails的验证功能是建立在Spring's Validator API和数据绑定之上的Q但Grails在此Ҏ和U束机制的基上又提供了统一的定义验证约束的Ҏ?br /> 在一个领域类中,U束constraints被定义在constraints属性的代码块中:

class User {

...

    static constraints = {

userName(size:5..15, blank:false, unique:true)

password(size:5..15, blank:false)

email(email:true, blank:false)

age(min:18, nullable:false)

}

}

q样在你每次保存一个对象的时候都回去调用validateҎ来验?

当然你可以在M实例上调用其validateҎ去验证领域类.

def user = new User(params)

if(user.validate()) {

// do something with user

} else {

    user.errors.allErrors.each {

println it

}

}

如果你在注册的时? 比如要输入两ơ密? q时候想把错误消息也攑օ领域cȝerrors属性里? ׃领域cȝ errors属性是Spring的Errors接口实例Q?/span>

Errors接口提供了访问这些验证错误的ҎQƈ且还可以取得原始的倹{?/span>

具体使用的实现类是BeanPropertyBindingResult

Java.lang.Object

org.springframework.validation.AbstractErrors

org.springframework.validation.AbstractBindingResult

org.springframework.validation.AbstractPropertyBindingResult

org.springframework.validation.BeanPropertyBindingResult

每一个消息对应一?span style="color: green">org.springframework.validation.ObjectError对象.所有可以想领域cȝerrors属性里面直接添加ObjectError对象可以了.

 def error = new ObjectError('password', message(code:'pinpin.register.valid.password.notequal'))

 user.errors.addError(error)



Eric.Zhou 2008-07-20 22:20 发表评论
]]>
Grails中用Spring的JdbcTemplate处理SQL语句http://www.aygfsteel.com/rain1102/archive/2008/07/18/215891.htmlEric.ZhouEric.ZhouFri, 18 Jul 2008 12:37:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/07/18/215891.htmlhttp://www.aygfsteel.com/rain1102/comments/215891.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/07/18/215891.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/215891.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/215891.html 但这两张表没有关联字D?也就是说没有外键U束. 但我惛_grail中查询两张表, 获取里面的name, password, age, email以及address{等. 条g是两个id相等.
q时候如何做??? 目前为止我想到的是使用Spring中的JdbcTemplate来处理SQL语句:
class User {
 String name
 String password
}

class UserInfo {
    int age
    String email
    String address
}

在controller中写:

def dataSource
    def list = {
      def template = new JdbcTemplate(dataSource)
      def userList = template.queryForList("select ui.name as name, u.password as password, ui.age as age, ui.email as email, ui.address as address  from user u, user_info ui where u.id = ui.id");
      def map = [userList : userList]

      render(view:"list", model:map)
    }


在gsp中只要用as后面的别名来取对应的值就可以?

<table>
                    <thead>
                        <tr>
                            <g:sortableColumn property="name" title="Name" />

                            <g:sortableColumn property="password" title="Password" />

                                <g:sortableColumn property="email" title="Emial" />

                                <g:sortableColumn property="age" title="Age" />

                                <g:sortableColumn property="address" title="Address" />

                        </tr>
                    </thead>
                    <tbody>
                    <g:each in="${userList}" status="i" var="user">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                            <td>${user.name}</td>
                            <td>${user.password}</td>
                            <td>${user.email}</td>
                            <td>${user.age}</td>
                            <td>${user.address}</td>
                        </tr>
                    </g:each>
                    </tbody>
                </table>

注意:U色的部分要名字一? 当然你也可以不用别? 直接用原来名字也可以!

Eric.Zhou 2008-07-18 20:37 发表评论
]]>
grails调用存储q程[转]http://www.aygfsteel.com/rain1102/archive/2008/07/18/215656.htmlEric.ZhouEric.ZhouFri, 18 Jul 2008 01:30:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/07/18/215656.htmlhttp://www.aygfsteel.com/rain1102/comments/215656.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/07/18/215656.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/215656.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/215656.html 

在特D情况下Q?/span>grails应用需要调用数据库的存储过E,q在grails的官Ҏ档里边好像没有提到过Q在james?/span>blog里介l如何解册个问题?/span>
   
代码转脓如下

Java 代码

  1. class MainController {  
  2.   
  3.   def dataSource // using the datasource we define in the spring's resources.xml  
  4.   
  5.   def index = {  
  6.       Sql sql = new Sql(dataSource)  
  7.       def row = sql.execute("call create_daily_hours(${new Date()+1})")  
  8.   }  
  9. }  

 需要说明的一些是Q?/span>grails本n没有提供讉K存储q程的便h法,?/span>groovy?/span>GSQL提供了,因此grails可以直接拿过来用了,当然也可以用spring?/span>JdbcTemplate?/span>
 
希望?/span>grails用户有点用?/span>

原文地址Q?/span>http://grails.group.javaeye.com/group/blog/86666



My experience with grails is getting richer the longer I use it for web application developing. It's very nice that grails is built on top of spring framework which we can take advantage of. I am not a spring user before but with a help from the nice people at the grails forum I was able to achieve what I want to do.

Calling a stored procedure from a MySQL database or any other database is simple. First we need a datasource which spring could provide for us. I have the following code place in the resources.xml found in the spring folder in your grails folder.


<bean id="dataSource" class=" org.apache.commons.dbcp.BasicDataSource ">
<property name="driverClassName">
    <value>org.hsqldb.jdbcDriver</value>
</property>
<property name="url">
    <value>jdbc:hsqldb:hsql://localhost</value>
</property>
<property name="username">
    <value>sa</value>
</property>
<property name="password">
    <value></value>
</property>
</bean>



I use connection pooling for better performance. In my controller here is how I use the datasource to call a store procedure.


class MainController {

 def dataSource // using the datasource we define in the spring's resources.xml

 def index = {
      Sql sql = new Sql(dataSource)
      def row = sql.execute("call create_daily_hours(${new Date()+1})")
 }
}



That's it! Notice that I am using Groovy SQL instead of Spring JDBCTemplate. It's a lot more friendlier for a beginner.

Grails really makes everything easy here and provides a lot of flexibility thanks to it's nice integration with spring. From here everything is possible.

原文地址Q?/span>http://james-says.blogspot.com/2007/03/grails-little-of-spring-framework.html



Eric.Zhou 2008-07-18 09:30 发表评论
]]>
在grails中用dojo上传文g (转蝲)http://www.aygfsteel.com/rain1102/archive/2008/07/17/215602.htmlEric.ZhouEric.ZhouThu, 17 Jul 2008 14:58:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/07/17/215602.htmlhttp://www.aygfsteel.com/rain1102/comments/215602.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/07/17/215602.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/215602.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/215602.html
<g:javascript library="dojo" />
<g:javascript>
dojo.require(
"dojo.io.IframeIO");
</g:javascript>
<g:form url="[action:'submitToRemoteCall']" id="form2"
enctype
="multipart/form-data">
File: 
<input name="someFile" type="file"></input>
<g:submitToRemote
value
="Submit Upload"
name
="form2"
action
="submitToRemoteUpload"
update
="[success:'message',failure:'error']" />
</g:form>
注意 form中写入url属性, 而且form不要有hidecd的inputQ否则会调用XMLHttpRequestQ而不用IframeIO

在controller中写?br />
def submitToRemoteUpload =
{
def f 
= request.getFile('someFile')
if(f.empty) {
render 
"No file!"
}
 else {
def fileName 
= f.getOriginalFilename()
render(text:
"<html><body><textarea>You called ${actionName} in
${controllerName} with file ${fileName}</textarea></body></html>",
contentType:"text/html", encoding:"UTF-8")
}

}
IframeIO的默认mimetype为text/plainQ所以用render QtextQ?..Q而且套嵌?lt;textarea>?br />
如果要返回render view?可以修改dojo的dojo.io.bind()Qbind参数加上mimetype:"text/html"。form中的<g:submitToRemote>改ؓ
<input onclick="dojo.io.bind({url:'/test/index/submitToRemoteUpload',  
                mimetype:'text/html',
                load:function(type,data,evt){dojo.byId('message')innerHTML = data.body.innerHTML;},
                error:function(type,error) { dojo.html.textContent( dojo.byId('error'),error.message);},
                formNode:dojo.byId('form2')});return false
"
     type
="submit" name="form2" value="Submit Upload">


Eric.Zhou 2008-07-17 22:58 发表评论
]]>
定制Grails的web.xmlhttp://www.aygfsteel.com/rain1102/archive/2008/07/16/215332.htmlEric.ZhouEric.ZhouWed, 16 Jul 2008 14:17:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/07/16/215332.htmlhttp://www.aygfsteel.com/rain1102/comments/215332.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/07/16/215332.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/215332.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/215332.htmlGrails的web.xml是自动生成的。如果需要修改web.xml该怎么办?

先说一下grails的web.xml的生过E?/p>

Grails的web.xml是在Package.groovy的generateWebXml target中生成的。可以在%Grails_Home%/scripts下找到它。其实在q行grails war时也是先走的q一步?/p>

在generateWebXml?/p>

1.先判断有没有config.grails.config.base.webXml属性,如果有,则用指定的config.grails.config.base.webXmlg为最l的web.xml

2.如果没有config.grails.config.base.webXml属性。再判断是否存在%Project_Home%/src/templates/war/web.xmlQ如果存在就使用q个作ؓ最l的web.xml

3.如果上面两个都没有,׃?Grails_Home%/src/war/WEB-INF/web${servletVersion}.template.xml作ؓ最l的web.xml

Ҏ上面的顺序,我们?个方法来指定web.xml

W一Q可以修?%Project_Home%/grails-app/conf/Config.groovy 文gQ在文g中添?br /> grails.config.base.webXml = "file:${basedir}/web.xml"
其中${basedir}代表%Project_Home%Q就是说会将%Project_Home%/web.xml作ؓ最l的web.xml?/p>

W二Q?grails install-templates 命oQ它会创?Project_Home%/src/templates/war/web.xml 文g。这样只要修改这个web.xmlp了?/p>

W三Q修?Grails_Home%/src/war/WEB-INF/web${servletVersion}.template.xml文gQ但是最好不要这样做?/p>

q里使用Grails 1.0.1



Eric.Zhou 2008-07-16 22:17 发表评论
]]>
Grails and uuid.hex generatorhttp://www.aygfsteel.com/rain1102/archive/2008/07/15/214880.htmlEric.ZhouEric.ZhouTue, 15 Jul 2008 02:05:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/07/15/214880.htmlhttp://www.aygfsteel.com/rain1102/comments/214880.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/07/15/214880.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/214880.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/214880.htmlclass Country {
    String id
    String name
    Boolean active = true

    static mapping = {
         id generator:'uuid.hex', params:[separator:'-']
    }
}

params:[separator:'-']Z键中间?-"分隔, 比如生成格式? 2c9d004d-1b247311-011b-2473734f-0001
当然可以Lparams:[separator:'-']直接写成

class Country {
    String id
    String name
    Boolean active = true

    static mapping = {
         id generator:'uuid.hex'
    }
}
q样q成格式ؓ: 2c9d004d1b247311011b2473ebf90003



Eric.Zhou 2008-07-15 10:05 发表评论
]]>
工欲善其?必须利其?NetBeans中设|grails和groovy)http://www.aygfsteel.com/rain1102/archive/2008/07/14/214797.htmlEric.ZhouEric.ZhouMon, 14 Jul 2008 11:10:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/07/14/214797.htmlhttp://www.aygfsteel.com/rain1102/comments/214797.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/07/14/214797.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/214797.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/214797.html5ipinpin刚开?必然要选择开发工? 之前一直是eclipse+myeclipse.
刚开始用netbeans遇到问? 本来以ؓ在netbeans里面和eclipse是一L, 对grails支持是需要下载或者更新插件的.
所以今天上午还担心q事....刚才H然看到讄grails的地? 大喜....
之前在本C弄了grails1.0.2, 然后今天又下了grails1.0.3, 所有我q里又两个版本? 然后通过netbeans的设|很单就可以切换两个版本,q进行开?..
废话扯远?.具体讄如下:
Tools->Options->Groovy
下面有讄Grails和Groovy的地方了, 很简? 选择本地路径可以了, Ok.

讄tab键的size可以到Editor下面的Indentation讄!



Eric.Zhou 2008-07-14 19:10 发表评论
]]>
pȝ~程语言和脚本语ahttp://www.aygfsteel.com/rain1102/archive/2008/06/15/208114.htmlEric.ZhouEric.ZhouSun, 15 Jun 2008 09:41:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/06/15/208114.htmlhttp://www.aygfsteel.com/rain1102/comments/208114.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/06/15/208114.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/208114.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/208114.html pȝ~程语言应该用于如下目的:
1.开发复杂的法或者数据结?br /> 2.实现计算密集型应?br /> 3.操作大型数据?br /> 4.实现良好定义? ~慢变更的需?br /> 5.是大型项目的一部分
而脚本语a应该用于如下目的:
1.q接已有的组?br /> 2.处理l常变化的多U类型的实体
3.h囑Ş化用L?br /> 4.拥有快速变化的功能
5.是小型或者中型项目的一部分

Eric.Zhou 2008-06-15 17:41 发表评论
]]>
XML和JSON响应http://www.aygfsteel.com/rain1102/archive/2008/06/05/206078.htmlEric.ZhouEric.ZhouThu, 05 Jun 2008 08:21:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/06/05/206078.htmlhttp://www.aygfsteel.com/rain1102/comments/206078.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/06/05/206078.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/206078.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/206078.html使用renderҎ输出XML

Grails支持一些不同的Ҏ来生XML和JSON响应。第一个是隐式的通过renderҎ?

renderҎ可以传递一个代码块来执行标记生成器产生XML

def list = {
def results = Book.list()
render(contentType:"text/xml") {
books {
for(b in results) {
book(title:b.title)
}
}
}
}

q段代码的结果将会像q样Q?

<books>
<book title="The Stand" />
<book title="The Shining" />
</books>

注意Q当你用标记生成器Ӟ必须心避免命名冲突。例如,q段代码生一个错误:

def list = {
def books = Book.list()  // naming conflict here
render(contentType:"text/xml") {
books {
for(b in results) {
book(title:b.title)
}
}
}
}

原因是,q里的一个本地变?code>books企图作ؓҎ被调用?

使用renderҎ输出JSON

render Ҏ可以同样被用于输出JSON:

def list = {
def results = Book.list()
render(contentType:"text/json") {
books {
for(b in results) {
book(title:b.title)
}
}
}
}

在这U情况下Q结果就会是大致相同的:

[
{title:"The Stand"},
{title:"The Shining"}
]

同样的命名冲H危险适用于JSON生成器?

自动XML列集(Marshalling)

Q译者注Q在此附上对于列?Marshalling)解释Q对函数参数q行打包处理得过E,因ؓ指针{数据,必须通过一定得转换Q才能被另一lg所理解。可以说列集(Marshalling)是一U数据格式的转换Ҏ。)

Grails同样支持自动列集(Marshalling)领域cMؓXML通过特定的{换器?

首先Q导?code>grails.converters cdC的控制器QControllersQ中Q?

import grails.converters.*

现在Q你可以使用下列高度易读的语法来自动转换领域cLXMLQ?

render Book.list() as XML

输出l果看上M像下列这P

<?xml version="1.0" encoding="ISO-8859-1"?>
<list>
<book id="1">
<author>Stephen King</author>
<title>The Stand</title>
</book>
<book id="2">
<author>Stephen King</author>
<title>The Shining</title>
</book>
</list>

一个用{换器的替代方法是使用Grails的codecsҎ。codecsҎ提供了encodeAsXML和encodeAsJSONҎ:

def xml = Book.list().encodeAsXML()
render xml

 

自动JSON列集(Marshalling)

Grails同样支持自动列集(Marshalling)为JSON通过同样的机制。简单替?code>XML ?code>JSON

render Book.list() as JSON

输出l果看上M像下列这P

[
{"id":1,
"class":"Book",
"author":"Stephen King",
"title":"The Stand"},
{"id":2,
"class":"Book",
"author":"Stephen King",
"releaseDate":new Date(1194127343161),
"title":"The Shining"}
]

再次作ؓ一U替代,你可以?code>encodeAsJSON辑ֈ相同的效?



Eric.Zhou 2008-06-05 16:21 发表评论
]]>
Grails文g上传http://www.aygfsteel.com/rain1102/archive/2008/06/04/205948.htmlEric.ZhouEric.ZhouWed, 04 Jun 2008 15:50:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/06/04/205948.htmlhttp://www.aygfsteel.com/rain1102/comments/205948.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/06/04/205948.html#Feedback1http://www.aygfsteel.com/rain1102/comments/commentRss/205948.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/205948.html 可以Ҏ件的一些属性设|,比如大小Q?br />
<bean class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>1000000</value>
</property>
</bean>
当然gsp面需要在form里面讄enctype="multipart/form-data"
<g:form method="post" action="save" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit"/>
</g:form>

下面是处理上传的文件了Q?br />

import org.springframework.web.multipart.MultipartHttpServletRequest
import org.springframework.web.multipart.commons.CommonsMultipartFile

class UploadController {
    static String uploadDir = "uploadfile"
    def index = {
        render(view:"upload")
    }
    def save = {
        if (request instanceof MultipartHttpServletRequest) {
            MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request
            CommonsMultipartFile orginalFile = (CommonsMultipartFile) multiRequest.getFile("file")
            // 判断是否上传文g
            if (orginalFile != null && !orginalFile.isEmpty()) {
                // 获取pȝ默认文g路径分隔W?br />                 def separator = System.getProperty("file.separator")
                println "file separator is ${separator} "
                // 获取原文件名U?br />                 String originalFilename = orginalFile.getOriginalFilename()
                // 获取上传文g扩展?br />                 def extension = originalFilename.substring(originalFilename.indexOf(".") + 1)
                println "extension is ${extension}"
                def name = ".." + separator + uploadDir + separator + orginalFile.getOriginalFilename()
                println "file name is : ${name}"
                // 使用存放文g的绝对\径创出流
                 /**
                DataOutputStream out = new DataOutputStream(new FileOutputStream(name))
                InputStream is = null
                try {
                    is = orginalFile.getInputStream()
                    byte[] buffer = new byte[1024]
                    while (is.read(buffer) > 0) {
                      out.write(buffer) // 写入盘
                    }
                } catch (IOException exception) {
                    exception.printStackTrace()
                } finally {
                    if (is != null) {
                        is.close()
                    }
                    if (out != null) {
                        out.close()
                    }
                }
                */
                orginalFile.transferTo(new File(name))
                render(view:"success")
            }
          
        } else {
            println "No multipart"
        }
    }
}




Eric.Zhou 2008-06-04 23:50 发表评论
]]>
使用Eclipse开发Grailshttp://www.aygfsteel.com/rain1102/archive/2008/06/04/205744.htmlEric.ZhouEric.ZhouWed, 04 Jun 2008 03:14:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/06/04/205744.htmlhttp://www.aygfsteel.com/rain1102/comments/205744.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/06/04/205744.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/205744.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/205744.htmleclipse-jee-europa-winter-win32.zipQ然后解压到盘上?br /> 2. 安装Groovy插gURL: http://dist.codehaus.org/groovy/distributions/updateDev/Q?span>点击 Help > Software Updates > Find and Install…Q?br /> 3. 把GRAILS_HOME d?/span> Classpath VariablesQ?/span>Windows > Preferences > Java > Build Path > Classpath VariablesQ?/span>
4. Groovy 插g?/span> Class auto generate 的功能,?/span> Contact ?/span> 右键 > Properties > Groovy Project properties > 选择 Disable Groovy Compiler Generating class Files > 点击 OK?br /> 5.配置?Web tools 能够~辑 GSP。打开 Windows > Preference > General > Editors > File AssociationsQ添?*.gspQƈ兌?JSP Editor 卛_配置?Web tools 能够~辑 GSP。打开 Windows > Preference > General > Editors > File AssociationsQ添?*.gspQƈ兌?JSP Editor 卛_?br /> 6. Content TypesQ?/span>Windows > Preference > General > Content Types
现在一切就l了?br /> 此时如果遇到Q?span>groovy.lang.MissingMethodException: No signature of method: groovy.util.ConfigSlurper.parse() is applicable for argument types: (DataSource) values:
%7BDataSource@...}错误?br /> 则确认一下是否已l禁用Groovy 插g?/span> Class auto generate Q以及删除项目目录下的所有class文g?/span>


Eric.Zhou 2008-06-04 11:14 发表评论
]]>
Groovy Eclipse Plugin 安装及问题解?/title><link>http://www.aygfsteel.com/rain1102/archive/2008/04/08/191413.html</link><dc:creator>Eric.Zhou</dc:creator><author>Eric.Zhou</author><pubDate>Tue, 08 Apr 2008 03:28:00 GMT</pubDate><guid>http://www.aygfsteel.com/rain1102/archive/2008/04/08/191413.html</guid><wfw:comment>http://www.aygfsteel.com/rain1102/comments/191413.html</wfw:comment><comments>http://www.aygfsteel.com/rain1102/archive/2008/04/08/191413.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/rain1102/comments/commentRss/191413.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/rain1102/services/trackbacks/191413.html</trackback:ping><description><![CDATA[安装参考链?<a target="_blank">http://<span id="wmqeeuq" class="hilite1">groovy</span>.codehaus.org/<span id="wmqeeuq" class="hilite2">Eclipse</span>+<span id="wmqeeuq" class="hilite3">Plugin</span></a> <br /> 按照步骤安装卛_. <br /> 问题1. <br /> 使用<span id="wmqeeuq" class="hilite2">Eclipse</span>的Software Updatesq行更新安装时报?configure错误,~少一些plug <br /> 解决Ҏ: <br /> 重新安装<span id="wmqeeuq" class="hilite2">Eclipse</span>,如果安装有Myclipse,可能是Myclipse的问?覆盖安装q有问题,最好删除后重新安装. <br /> <br /> 问题2:<span id="wmqeeuq" class="hilite1">Groovy</span> TestNG feature 不能安装 <br /> 解决Ҏ: <br /> 如果使用<span id="wmqeeuq" class="hilite1">Groovy</span> TestNG feature, <br /> 则应先到TestNG update site <br /> (<a target="_blank">http://testng.org/doc/download.html</a>) <br /> 首先安装 TestNG <span id="wmqeeuq" class="hilite2">Eclipse</span> plug-in <br /> 如果不用<span id="wmqeeuq" class="hilite1">Groovy</span> TestNG feature,则取?span class="hilite1">Groovy</span> TestNG feature选择卛_. <br /><img src ="http://www.aygfsteel.com/rain1102/aggbug/191413.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/rain1102/" target="_blank">Eric.Zhou</a> 2008-04-08 11:28 <a href="http://www.aygfsteel.com/rain1102/archive/2008/04/08/191413.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Grails自定义标{?/title><link>http://www.aygfsteel.com/rain1102/archive/2008/04/02/190236.html</link><dc:creator>Eric.Zhou</dc:creator><author>Eric.Zhou</author><pubDate>Tue, 01 Apr 2008 16:28:00 GMT</pubDate><guid>http://www.aygfsteel.com/rain1102/archive/2008/04/02/190236.html</guid><wfw:comment>http://www.aygfsteel.com/rain1102/comments/190236.html</wfw:comment><comments>http://www.aygfsteel.com/rain1102/archive/2008/04/02/190236.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/rain1102/comments/commentRss/190236.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/rain1102/services/trackbacks/190236.html</trackback:ping><description><![CDATA[<p><span style="color: #008000">RaceTrackTagLib.groovyQ放到grails-app\taglib目录下)</span><br /> class RaceTrackTagLib {<br />  def formatDate = { attrs -><br />   def date = attrs.get('date')<br />   <br />   if (!date) {<br />    date = new Date()<br />   }</p> <p>  def format = attrs.get('format')<br />   if (!format) {<br />    format = "yyyy-MM-dd HH:mm:ss z"<br />   }</p> <p>  out << new <a title="Java爱好? href="http://www.aygfsteel.com/rain1102" >Java</a>.text.SimpleDateFormat(format).format(date)<br />  }</p> <p> def formatNumber = { attrs -><br />   def number = attrs.get('number')<br />   <br />   if (!number) {<br />    number = new Double(0)<br />   }</p> <p>  def format = attrs.get('format')<br />   if (!format) {<br />    format = "0"<br />   }</p> <p>  out << new <a title="Java爱好? href="http://www.aygfsteel.com/rain1102" >Java</a>.text.DecimalFormat(format).format((Double)number)<br />  }<br /> }<br /> </p> <br /> <span style="color: #008000">面中?/span><br /> <g:formatDate date="${race.startDateTime}" format="yyyy-MMM-dd HH:mm"/><br /> <br /> <g:formatNumber number="${race.distance}" format="##0.00 mi"/><br /> <br /><img src ="http://www.aygfsteel.com/rain1102/aggbug/190236.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/rain1102/" target="_blank">Eric.Zhou</a> 2008-04-02 00:28 <a href="http://www.aygfsteel.com/rain1102/archive/2008/04/02/190236.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Grails--Quick Starthttp://www.aygfsteel.com/rain1102/archive/2008/04/01/189897.htmlEric.ZhouEric.ZhouMon, 31 Mar 2008 16:02:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/04/01/189897.htmlhttp://www.aygfsteel.com/rain1102/comments/189897.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/04/01/189897.html#Feedback0http://www.aygfsteel.com/rain1102/comments/commentRss/189897.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/189897.html 创徏Grails目
一旦你安装qGrails之后,你就可以使用内置的命令来创徏新的目?
grails create-app
之后会提C您,让您输入目名称.
也可以直接在命o后输入项目的名称.
grails create-app puras_app
命o执行完之?会生成一个以你输入的目名ؓ名的目录,里面则是自动生成的目录结构和一些基代码?l构如下:
%PROJECT_HOME%
    
+ grails-app
       
+ conf                 ---> 本地配置文g,像是数据?br />        + controllers          ---> q个文g多w存有Controllerc?br />        + domain               ---> q个文g多w存有domainc?br />        + i18n                 ---> 国际化信?br />        + services             ---> location of services
       
+ taglib               ---> 标签?br />        + util                 ---> 工具?br />        + views                ---> 视图
           
+ layouts              ---> 布局
   
+ hibernate              ---> 可选择的Hibernate的配|?br />    + lib
   
+ spring                 ---> 可选择的Spring配置
   
+ src
       
+ groovy               ---> 可选择?groovy源代?br />        + java                 ---> 可选择?java源代?br />    + war
       
+ WEB-INF
接下?可以选择配置一个数据源,在执?create-app"?grails创Z几个数据源在你的%PROJECT_HOME%/grails-app/conf目录?它们都是标准的环?DevelopmentDataSource(开发数据源),TestDataSource(试数据?,和ProductionDataSource(产品数据?.所有的例子都是操作在开发环境之?
在执行应用的时候可以选择所属的环境(以后有介l?.
默认?每个数据源都配置的是内嵌的HSQLDB数据?可以很方便的试,但是现实的环境中大概没什么用?,所以此步骤是可选的:
DevelopmentDataSource.groovy
class DevelopmentDataSource {
   
boolean pooling = true
   String dbCreate 
= "create-drop" // one of 'create', 'create-drop','update'
   String url = "jdbc:hsqldb:mem:testDB"
   String driverClassName 
= "org.hsqldb.jdbcDriver"
   String username 
= "sa"
   String password 
= ""
}
配置q个数据?是单的替换上所希望使用数据库的?再将其所用的驱动包拷贝到%PROJECT_HOME%/lib目录?
创徏一个实体类
认你现在所在的目录是你的项目的ȝ?之后输入以下命o
grails create-domain-class
之后命o会提CZ输入要创建的cd,你也可以直接在命令后直接输入cd,?
grails create-domain-class Book
向类里添加两个属?
Book.groovy
class Book {
    String title
    String author
}
你可能想要创Z些测试数?一个简单的Ҏ是?PROJECT_HOME%/grails-app/conf/ApplicationBootStrap.groovyq个Grails应用的启动类?init"闭包里创建ƈ保存试数据.
class ApplicationBootStrap {

    def init 
= { servletContext ->
        
// Create some test data
        new Book(author:"Stephen King",title:"The Shining").save()
        
new Book(author:"James Patterson",title:"Along Came a Spider").save()
    }
    def destroy 
= {
    }
}
创徏Controller
Controllers是Grails应用的中?它们处理WEBh和请求的URLs,请求和h参数映射到控制器cd它里面的一个闭?
执行"grails generate-all"命o,q输入控制器的名U?在我们的例子?我们在生成控制器cȝ时候输?Book",会?PROJECT_HOME%/grails-app/controllers下生成一个名叫BookController.groovy的文?也可以直接在命o后直接加上控制器cȝ名称.
grails generate-all Book
打开q个文g,q把里面的内Ҏ换成下面所C的代码,使用在你的程序运行的时候动态生成的动态脚手架.
class BookController {
     def scaffold 
= Book
}
要注意你输入?Book"是大写的B开?

当然,你同样可以不替换而用默认生成的代码.它可是有学习的h值哦.

要开始你的Grails应用,执行下面的命?br /> grails run-app

q个命o启动一个Jetty应用服务器的一个实例运行在8080端口?Z启动一个运行在不同端口?比如?090,使用grails -Dserver.port=9090 run-app.要访问books的例?打开览?q输?
http://localhost:8080/puras_app/book/list

单的应用到此结?参照?举一q三,做一些简单的应用还是可以的!


Eric.Zhou 2008-04-01 00:02 发表评论
]]>
安装Grails http://www.aygfsteel.com/rain1102/archive/2008/03/31/189891.htmlEric.ZhouEric.ZhouMon, 31 Mar 2008 14:49:00 GMThttp://www.aygfsteel.com/rain1102/archive/2008/03/31/189891.htmlhttp://www.aygfsteel.com/rain1102/comments/189891.htmlhttp://www.aygfsteel.com/rain1102/archive/2008/03/31/189891.html#Feedback3http://www.aygfsteel.com/rain1102/comments/commentRss/189891.htmlhttp://www.aygfsteel.com/rain1102/services/trackbacks/189891.html1、需?/p>
  • 要求安装JDK1.4或以上版?
  • 讄JAVA_HOME环境变量Q指向JDK安装位置

2、安装Grails

  • http://grails.codehaus.org/下蝲最新的Grails版本 
  • 压~包解压到合适的位置
  •  讄GRAILS_HOME环境变量Q指向Grails安装位置
  • ?GRAILS_HOME%\binq加到PATH环境变量?
  • 在命令行执行grailsQ如果显CGrails的版本信息,表示安装成功Q?/li>


Eric.Zhou 2008-03-31 22:49 发表评论
]]>
վ֩ģ壺 ׶| | | | | ԭ| ɽ| | | ˷| Ͽ| | ̽| | | ӳ| ³| | | Ƹ| | ɽ| ˮ| «| Т| | ¡| ½| ״| | ӻ| | | | | | | | Ҧ| | |