Grails Quick Start
2727 ワード
grailsのインストール
インストール方法が多い公式サイトのインストールhttps://grails.org/documentation.html 本機はmac os選択用homebrewで取り付ける
プロジェクトの作成
grailsコマンドを使用してプロジェクトを作成します.
プロジェクトディレクトリ:
レルムクラスの作成
クラスを編集してプロパティを追加
constraints関数では、いくつかの制約を追加できます.
コントローラの作成
シンプルコントロール
「ハローワールド」が見えます.
もっと高度な:scaffold grailsが定義されている場合、CUDRを自動的に作成する論理は不思議ではありませんか?
うんてん
アクセスhttp://localhost:8080何か見たか?
アクセスhttp://localhost:8080/test Hello world
データベースの接続
インストール方法が多い
brew install grails
プロジェクトの作成
grailsコマンドを使用してプロジェクトを作成します.
grails create-app my-project
プロジェクトディレクトリ:
%PROJECT_HOME%
+ grails-app
+ conf ---> location of configuration artifacts
+ hibernate ---> optional hibernate config
+ spring ---> optional spring config
+ controllers ---> location of controller artifacts
+ domain ---> location of domain classes
+ i18n ---> location of message bundles for i18n
+ services ---> location of services
+ taglib ---> location of tag libraries
+ util ---> location of special utility classes
+ views ---> location of views
+ layouts ---> location of layouts
+ lib
+ scripts ---> scripts
+ src
+ groovy ---> optional; location for Groovy source files
(of types other than those in grails-app/*)
+ java ---> optional; location for Java source files
+ test ---> generated test classes
+ web-app
+ WEB-INF
レルムクラスの作成
cd my-project
grails create-domain-class org.example.Book
クラスを編集してプロパティを追加
package org.example
class Book {
String title
String author
static constraints = {
title(blank: false)
author(blank: false)
}
}
constraints関数では、いくつかの制約を追加できます.
コントローラの作成
grails create-controller org.example.Book // Note the capital B
シンプルコントロール
def index={
// url
render "Hello World"
}
「ハローワールド」が見えます.
もっと高度な:scaffold grailsが定義されている場合、CUDRを自動的に作成する論理は不思議ではありませんか?
package org.example
class BookController {
def scaffold = Book // Note the capital "B"
}
うんてん
grails run-app
アクセスhttp://localhost:8080何か見たか?
アクセスhttp://localhost:8080/test Hello world
データベースの接続
dataSource:
pooled: true
jmxExport: true
driverClassName: org.postgresql.Driver
username: changeme
password: changeme
environments:
development:
dataSource:
dbCreate: create-drop
url: jdbc:postgresql://10.32.150.91:5432/psyco