crud example Grails
Example: simple crud in grails
def index() {
def domainName = DomainName.list()
render domainName as JSON
}
def show() {
def domainName = DomainName.get(params.id as Long)
render domainName as JSON
}
def save(){
def objectJSON = request.JSON
def domainName = new DomainName()
domainName.properties = objectJSON
domainName.save(flush: true)
render domainName as JSON
}
def update() {
def objectJSON = request.JSON
def domainName = DomainName.get(params.id as Long)
domainName.properties = objectJSON
domainName.save(flush: true)
render domainName as JSON
}
def delete(){
def domainName = DomainName.get(params.id as Long)
domainName.delete(flush: true)
render domainName as JSON
}