Created
October 18, 2012 11:52
-
-
Save joeRinehart/3911330 to your computer and use it in GitHub Desktop.
Grails for the Wicked Smaht 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def ajaxShow() { | |
| render Person.get( params.personId ) as JSON | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def company = new Company( "Acme" ) | |
| def person = new Person( firstname : "Bob", lastname : "Bobbyson", age : 80 ) | |
| company.addToPeople( person ) | |
| company.save() | |
| person.findByFirstName( "Bob" ) // finds all "Bob"s | |
| person.findAll( "from Person where Company = :company", [ company: company ] ) | |
| company.delete() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PersonController { | |
| def show() { | |
| def person = Person.get( params.personId ) | |
| return [ person: person ] | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person { | |
| String firstname | |
| String lastname | |
| Integer age | |
| void setFirstname( String firstname ) { | |
| println "Setting firstname to ${firstname}" | |
| this.firstname = firstname | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person { | |
| String firstname | |
| String lastname | |
| Integer age | |
| static constraints = [ | |
| name size: 1...50 | |
| age nullable: true | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| You just loaded ${person.firstname} ${person.lastname}. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def literal = 'John' | |
| def gString = "The name is ${literal}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment