ID からではなく、lastName からこのクラスのユーザーを取得する方法。
私の例では、REST Web サービスを使用しています。
Grails の私のクラス USER.groovy:
class User {
String firstName
String lastName
String zipcode }
クラス UrlMappings.groovy
class UrlMappings {
static mappings = {
/user/$id" (controller: "user") {
action = [GET: "show"]
}
}
}
def show in UserController.groovy
def show = {
User user = User.get(params.id)
if (user) {
render user as JSON
} else {
SendNotFoundResponse()
}
}