Groovy и Grails. Быстро и обо всём

  • Published on
    16-Jun-2015

  • View
    103

  • Download
    2

Embed Size (px)

DESCRIPTION

Groovy Grails.

Transcript

<ul><li> 1. Groovy Grails </li></ul> <p> 2. Groovy, http://groovy.codehaus.org/ JVM Java :-) 3. println Hello World import java.io.*;public class HelloWorld {public static voidmain(String[] args) {System.out.println("HelloWorld");}} 4. import java.io.*;import java.util.*;public class HelloWorld {public static List kvadrat(List x) {List y = new ArrayList(x.size());for (Integer n : x) {y.add( (int)Math.round(Math.pow(n, 2)) );}return y;}public static void main(String[] args) {List x = new ArrayList();x.add(1); x.add(2); x.add(3); x.add(4); x.add(5);List y = kvadrat(x);for (Integer n : y) {System.out.println(n);}}} 5. public static List kvadrat(List x) {List y = new ArrayList(x.size());for (Integer n : x) {y.add((int) Math.round(Math.pow(n, 2)));}return y;}List x = new ArrayList();x.add(1); x.add(2); x.add(3); x.add(4); x.add(5);List y = kvadrat(x);for (Integer n : y) {System.out.println(n);} 6. // x , powerpublic static List kvadrat(List x) {List y = new ArrayList(x.size());for (Integer n : x) {y.add(n.power(2));}return y;}List x = [1, 2, 3, 4, 5];List y = kvadrat(x);for (Integer n : y) {System.out.println(n);} 7. // collect. Groovy public static List kvadrat(List x) {List y = x.collect({ n -&gt; n.power(2) });return y;}List x = [1, 2, 3, 4, 5];List y = kvadrat(x);for (Integer n : y) {System.out.println(n);} 8. // . Java // , Groovy - public static List kvadrat(List x) {return x.collect({ n -&gt; n.power(2) });}List y = kvadrat([1, 2, 3, 4, 5]);for (Integer n : y) {System.out.println(n);} 9. // : , , return.// .eachdef kvadrat(x) { x.collect { n -&gt; n.power(2) } }def y = kvadrat([1, 2, 3, 4, 5])y.each { n -&gt;System.out.println(n)} 10. // y :)def kvadrat(x) { x.collect { n -&gt; n.power(2) } }kvadrat([1, 2, 3, 4, 5]).each { n -&gt;System.out.println(n)} 11. // n , itdef kvadrat(x) { x.collect { it.power(2) } }kvadrat([1, 2, 3, 4, 5]).each { println it } 12. // kvadrat - :)[1, 2, 3, 4, 5].collect { it.power(2) }.each { println it } 13. [1, 2, 3, 4, 5].collect {it.power(2) }.each {println it}import java.io.*;import java.util.*;public class HelloWorld {public static List kvadrat(List x) {List y = new ArrayList(x.size());for (Integer n : x) {y.add( (int)Math.round(Math.pow(n, 2)) );}return y;}public static void main(String[] args) {List x = new ArrayList();x.add(1); x.add(2); x.add(3); x.add(4); x.add(5);List y = kvadrat(x);for (Integer n : y) {System.out.println(n);}}} 14. final a = [1, 2, 3, 4, 5], b = [2, 3, 4, 5, 6]List.metaClass.kvadrat = { delegate.collect { it.power(2) } }println "${a.kvadrat()} ${b.kvadrat()}"import javax.servlet.http.HttpServletRequestHttpServletRequest.metaClass.getRealIp = {delegate.getHeader('X-Real-Ip') ?: delegate.remoteAddr } 15. class Eat { def eat() { println "I ate" } }class Drink { def drink() { println "I drinked" } }class Animal {}; class Mammal extends Animal {}@Mixin(Eat) class Human extends Mammal {}final me = new Human()me.eat()Human.mixin(Drink)me.drink() 16. class Human {def eat() {}def drink() {}}final x = [ eat: { println "I ate." }, drink: { println "I drinked." } ] as Humanx.eat()println "${x.class}: ${x instanceof Human}"I ate.class Human1_groovyProxy: true 17. I/Oprintln new File('/etc/passwd').textprintln new URL('http://baron.su/').textimport groovy.json.*def builder = new JsonBuilder()builder.human ( name: 'Vasya', height: 180 )new File('/tmp/out.json').withWriter { w -&gt;w.println builder.toString()}{"human":{"name":"Vasya","height":180}} 18. POGOclass Human {def name, sex, height, weightString toString() { "$name ($sex): $height cm $weight kg" }}println new Human(name: 'Vasya', sex: 'every day', height: 180, weight: 80)Vasya (every day): 180 cm 80 kg 19. GORMclass Person {String nameint agestatic constraints = {name blank: false}}new Person(name: Ruslan, age: 31).save(flush:true)final ruslan = Person.findOrCreateByNameAndAge(Ruslan, 31).save() 20. GORM Hibernate Pessimistic &amp; Optimistic locking Hibernate Convention over Configuration 21. Grails Convention over Configuration web 22. Grails. package dummyclass Password {String usernameString passwordString urlstatic constraints = {}} 23. Grails. package dummyclass PasswordController {static scaffold = Passworddef index() { }} 24. Grails. Bootstrapimport dummy.Passwordclass BootStrap {def init = { servletContext -&gt;new Password(username: 'admin', password: 'password', url:'http://berserktcg.ru/').save(flush: true)}def destroy = {}} 25. Scaffolding 26. ? :) </p>

Recommended

View more >