微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Groovy轻松入门——Grails实战基础篇(4)

 

ok.gsp:

9,修改demo/grails-app/conf/ApplicationBootStrap.groovy,将一个User实例保存到数据库(grails自带hsqldb和jetty)中,内容如下:

class ApplicationBootStrap {

     def init = { servletContext ->
         new User(name: "demo",password: "123456").save()
     }
     def destroy = {
     }
} 

 

10,在“命令行”中,输入“grails run-app”,运行我们的Web应用,输出如下:

D:/Temp/grails_apps/demo>grails run-app

Welcome to Grails 0.4.2 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: D:/D/MY_DEV/grails

Base Directory: D:/Temp/grails_apps/demo
Environment set to development
Running script D:/D/MY_DEV/grails/scripts/RunApp.groovy
Compiling sources
   [delete] Deleting directory D:/Temp/grails_apps/demo/web-app/WEB-INF/grails-a
pp
    [mkdir] Created dir: D:/Temp/grails_apps/demo/web-app/WEB-INF/grails-app/vie
ws
    [mkdir] Created dir: D:/Temp/grails_apps/demo/web-app/WEB-INF/grails-app/i18
n
     [copy] copying 8 files to D:/Temp/grails_apps/demo/web-app/WEB-INF/grails-a
pp/views
[native2ascii] Converting 1 file from D:/Temp/grails_apps/demo/grails-app/i18n t
o D:/Temp/grails_apps/demo/web-app/WEB-INF/grails-app/i18n
Attempting to load [13] core plugins
Grails plug-in [i18n] with version [0.4.2] loaded successfully
Grails plug-in [quartz] with version [0.4.2] loaded successfully
Grails plug-in [core] with version [0.4.2] loaded successfully
Grails plug-in [domainClass] with version [0.4.2] loaded successfully
Grails plug-in [controllers] with version [0.4.2] loaded successfully
Attempting to load [0] user defined plugins
Grails plug-in [dataSource] with version [0.4.2] loaded successfully
Grails plug-in [codecs] with version [0.4.2] loaded successfully
Grails plug-in [hibernate] with version [0.4.2] loaded successfully
Grails plug-in [services] with version [0.4.2] loaded successfully
Grails plug-in [scaffolding] with version [0.4.2] loaded successfully
[RuntimeConfiguration] Configuring for environment: Development
Building new Hibernate SessionFactory
Neither 'urlMap' nor 'mappings' set on SimpleUrlHandlerMapping
64 beans defined in application context [org.codehaus.groovy.grails.commons.spri
ng.GrailsWebApplicationContext;hashCode=6971605]
Using MessageSource [org.springframework.context.support.ReloadableResourceBundl
eMessageSource: basenames=[WEB-INF/grails-app/i18n/messages]]
Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticas
ter': using default [org.springframework.context.event.SimpleApplicationEventMul
ticaster@181d405]
     [copy] copying 8 files to D:/Temp/grails_apps/demo/web-app/WEB-INF/grails-a
pp/views
[GrailsContextLoader] Grails application loaded.
Initializing filter 'grailsWebRequest'
Filter 'grailsWebRequest' configured successfully
Initializing filter 'reloadFilter'
Filter 'reloadFilter' configured successfully
Initializing servlet 'grails'
FrameworkServlet 'grails': initialization started
Using context class [org.codehaus.groovy.grails.commons.spring.GrailsWebApplicat
ionContext] for servlet 'grails'
Using MultipartResolver [org.springframework.web.multipart.commons.CommonsMultip
artResolver@1945696]
Using LocaleResolver [org.springframework.web.servlet.i18n.CookieLocaleResolver@
1c0bec5]
Unable to locate ThemeResolver with name 'themeResolver': using default [org.spr
ingframework.web.servlet.theme.FixedThemeResolver@1984161]
No HandlerAdapters found in servlet 'grails': using default
Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': usi
ng default [org.springframework.web.servlet.view.DefaultRequestToViewNameTransla
tor@688d6f]
FrameworkServlet 'grails': initialization completed in 187 ms
Servlet 'grails' configured successfully

 

11,打开浏览器,输入:http://localhost:8080/demo/login/login ,在Name处输入demo,Password处输入123456,点击‘Login’,跳转到成功页面

 

Welcome demo
demo : 123456

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐