simple crud in grails

Solutions on MaxInterview for simple crud in grails by the best coders in the world

showing results for - "simple crud in grails"
Jana
15 May 2019
1   //Grails Laguage
2
3    //index : list all data of object from domain Object
4    def index() {
5        def domainName = DomainName.list()
6        render domainName as JSON
7    }
8    
9    //show : get data of object from domain Object base on id
10    def show() {
11        def domainName = DomainName.get(params.id as Long)
12        render domainName as JSON
13    }
14
15    //create
16    def save(){
17        def objectJSON = request.JSON
18        def domainName = new DomainName()
19        domainName.properties = objectJSON
20        domainName.save(flush: true)
21        render domainName as JSON
22    }
23
24    //update base on Id
25    def update() {
26        def objectJSON = request.JSON
27        def domainName = DomainName.get(params.id as Long)
28        domainName.properties = objectJSON
29        domainName.save(flush: true)
30        render domainName as JSON
31    }
32
33    //delete
34    def  delete(){
35        def domainName = DomainName.get(params.id as Long)
36        domainName.delete(flush: true)
37        render domainName as JSON
38    }