Post on 15-Apr-2017
Unless o therw ise i nd i cated, these s l i des a re © 2013 -2015 P i vo ta l So f tware, Inc . and l i censed under a Crea t i ve Com mons A t t r ibu tio n-NonCommercia l l i cense : h t tp : // crea tivecommons.o rg/ l icenses/by -nc/3 .0 /
By Tom Henricksen
// This is Helvetica: 18 pt or higher please
public class TransferServikjceImpl implements TransferService {
public TransferServiceImpl(AccountRepository ar) {
this.accountRepository = ar;
}
…
}
Domain Validation
class User {
static
login
password
age
// This is Helvetica: 18 pt or higher please
public class TransferServikjceImpl implements TransferService {
public TransferServiceImpl(AccountRepository ar) {
this.accountRepository = ar;
}
…
}
Command Object
@grails.validation.Validateable
class LoginCommand {
String username
String password
static constraints = {
username(blank: false, minSize: 6)
password(blank: false, minSize: 6)
}
}
// This is Helvetica: 18 pt or higher please
public class TransferServikjceImpl implements TransferService {
public TransferServiceImpl(AccountRepository ar) {
this.accountRepository = ar;
}
…
}
Be Careful with GStrings
// Single quotes
def s1 = ‘This is a string’
// Double quotes
def s2 = “This is also a string!”
// A Gstring at a software conference…
def g1 = “Hi, your name is ${user.name}”
String toString() { return “$description” }
// This is Helvetica: 18 pt or higher please
public class TransferServikjceImpl implements TransferService {
public TransferServiceImpl(AccountRepository ar) {
this.accountRepository = ar;
}
…
}
Mapping
static mapping = {
table ‘descriptions’ {
columns {
description column ‘description’
}
}
static mapping = {
table ‘descriptions’
}
// This is Helvetica: 18 pt or higher please
public class TransferServikjceImpl implements TransferService {
public TransferServiceImpl(AccountRepository ar) {
this.accountRepository = ar;
}
…
}
Dynamic Finders
class Book {
String title
Date releaseDate
Author author
}
def book = Book.findByTitle("The Stand")
book = Book.findByTitleLike ("Harry Pot%")
// This is Helvetica: 18 pt or higher please
public class TransferServikjceImpl implements TransferService {
public TransferServiceImpl(AccountRepository ar) {
this.accountRepository = ar;
}
…
}
Default Values
String description
static constraints = {
description nullable: false, maxSize: 500
}