Browse Source

implement "Test type 4: Fortunes"

Lari Hotari 11 years ago
parent
commit
d140b224a2

+ 9 - 0
grails/hello/grails-app/controllers/hello/HelloController.groovy

@@ -45,6 +45,15 @@ class HelloController {
         render worlds as JSON
     }
     
+    // Test type 4: Fortunes
+    @Transactional(readOnly=true)
+    def fortunes() {
+        def fortunes = Fortune.getAll()
+        fortunes << new Fortune(message: 'Additional fortune added at request time.')
+        fortunes.sort(true){Fortune it -> it.message}
+        [fortunes: fortunes]
+    }
+    
     // Test type 6: Plaintext
     def plaintext() {
         render text:'Hello, world', contentType:'text/plain'

+ 14 - 0
grails/hello/grails-app/domain/hello/Fortune.groovy

@@ -0,0 +1,14 @@
+package hello
+
+class Fortune {
+    Integer id
+    String message
+
+    static constraints = {
+    }
+
+    static mapping = {
+      table name: 'Fortune'
+      version false
+    }
+}

+ 10 - 0
grails/hello/grails-app/views/hello/fortunes.gsp

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head><title>Fortunes</title></head>
+<body>
+<table>
+<tr><th>id</th><th>message</th></tr>
+<g:each var="fortune" in="${fortunes}"><tr><td>${fortune.id}</td><td>${fortune.message}</td></tr></g:each>
+</table>
+</body>
+</html>