Its better to declare your domain in class which could be related to database.
user domain class
class User {
Long id
String name
static mapping = {
table 'user' //here user is database table name
version false
id column: 'id', generator: 'increment'
name column: 'name'
}
static constraints = {
id(nullable: true)
name(nullable: false)
}
}
you can use scaffolding in controller to generate CRUD as well like
class UserController {
static scaffold = User
def index() {
def userList = User.list()
[userList: userList]
}
}
Without declaring your domain class you will get error to execute query from database in controller.