$ grails create-app helloworld
$ cd helloworld
$ grails create-domain-class hello
$ vi ./grails-app/domain/helloworld/Hello.groovy
package helloworld
class Hello { String message
static constraints = { } }
$ grails create-controller hello
$ vi ./grails-app/controllers/helloworld/HelloController.groovy
package helloworld
class HelloController { static scaffold = Hello }
$ grails run-app
grails { exploded = true plugins { compile project(':core-domain-plugin') compile project(':sub-domain-plugin') }}
includeFlat 'core-domain-plugin'includeFlat 'sub-domain-plugin'
class IsbnUserType implements UserType { @Override int[] sqlTypes() { return [StringType.INSTANCE.sqlType()] } @Override Class returnedClass() { return Isbn.class }
}
package com.example.domain
class Isbn { private String isbnCode}
class Book { String title Isbn isbn BigDecimal standardUnitPrice static mapping = { isbn type: IsbnUserType } String toString() { title } }
dependencies { compile "org.springframework.boot:spring-boot-starter-logging" compile "org.springframework.boot:spring-boot-autoconfigure" compile "org.grails:grails-core" compile "org.springframework.boot:spring-boot-starter-actuator" compile "org.springframework.boot:spring-boot-starter-tomcat" compile "org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1"
: }
package com.example.domain
class Isbn { private String isbnCode}
package com.example.domainimport grails.validation.Validateableclass Book implements Validateable { Long id String title Isbn isbn BigDecimal standardUnitPrice Long version static constraints = { } }
package com.example.infrastructureimport com.example.domain.Bookimport org.apache.ibatis.annotations.Mapperimport org.apache.ibatis.annotations.Param@Mapperinterface BookMapper { void register(@Param("book") Book book) List<Book> list()}
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.example.infrastructure.BookMapper"> <resultMap id="product" type="com.example.domain.Book"> <id property="id" column="id"/> <result property=“isbn.isbnCode" column="isbn_code"/> <result property="title" column=“title"/> <result property="standardUnitPrice" column=“standard_unit_price”/> <result property="version" column="version"/> </resultMap> :</mapper>
package com.exampleclass BookRepositoryService { List<Book> list() { Book.findAll() } :}
package com.example.domaininterface BookRepository { List<Book> list() Book get(Long id)
}
package com.example.infrastructureimport com.example.domain.Bookimport com.example.domain.BookRepositoryimport org.springframework.stereotype.Repository@Repositoryclass BookDatasource implements BookRepository { @Override List<Book> list() { Book.findAll() } :}