Ze contrôleur package
vinna.controllers; import
vinna.response.Response; import
vinna.response.StringResponse; public
class
HelloController
{
public
Response
index()
{
return
new
StringResponse("Go
to
/hello/{your
name}
for
a
free
hug
!");
}
public
Response
sayHello(String
name,
String
ohai)
{
return
new
StringResponse(String.format("%s
%s
!",
(ohai
==
null
?
"Ohai"
:
ohai),
name));
} } Thursday, 23 May, 13
Ze même contrôleur package
vinna.controllers; import
vinna.response.Response; import
vinna.response.StringResponse; public
class
HelloController
{
public
Response
index()
{
return
new
StringResponse("Go
to
/hello/{your
name}
for
a
free
hug
!");
}
public
Response
sayHello(String
name,
String
ohai)
{
return
new
StringResponse(String.format("%s
%s
!",
(ohai
==
null
?
"Ohai"
:
ohai),
name));
} } Thursday, 23 May, 13
Exemples (déclaratif) GET
/css/bootstrap.min.css
pass GET
/**/*.js
pass GET
/
TodoController.list() GET
/new
TodoController.create() POST
/new
TodoController.create({req.param.title},
{req.param.debug}) req.param.debug:
true|false GET
/api/{id}
ApiTodoController.show({id})
id:
\d+ POST
/api
ApiTodoController.create(JacksonArgument) GET
/create
TodoController.create(TodoParameter) GET
/resource
Controller.get({req.header.ETag}) Thursday, 23 May, 13
De base Validation
validation
=
new
Validation(); validation.required(title,
"title").required(description,
"description"); if
(validation.hasErrors())
{
return
new
CreateView(title,
description,
validation); } Thursday, 23 May, 13
Avec JSR-303 public
class
Todo
{
private
Long
id;
@NotNull
@Size(min
=
2,
max
=
128)
private
String
title;
@NotNull
@Size(max
=
512)
private
String
description; : : Validation
validation
=
new
Validation().validate(todo); if
(!validation.hasErrors())
{
:
: } Thursday, 23 May, 13