Follow these steps to use play2-crud. You can also use it partially just for DAO or CRUD controllers. If you think any part needs further explanation, please report a new issue.
- Model class has to implement
play.utils.dao.BasicModel
with the type parameter indicating the type of the@Id
field.
@Entity
public class Sample extends Model implements BasicModel<Long> {
@Id
private Long key;
@Basic
@Required
private String name;
public Long getKey() {
return key;
}
public void setKey(Long key) {
this.key = key;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
- Here the
Sample
model class implementsBasicModel<Long>
wherekey
field indicated with@Id
isLong
.
- Change the
application.global
configuration key in theconf/application.conf
file, aand useplay.utils.crud.GlobalCRUDSettings
:
...
application.global=play.utils.crud.GlobalCRUDSettings
...
- If the above key is commented, you can just uncomment the configuration line, and change it.
- You can also use a class which is extending
play.utils.crud.GlobalCRUDSettings
.
# CRUD Controllers
-> /app play.crud.Routes
# REST API
-> /api play.rest.Routes
... and voila!