How to use spring.data.rest.enable-enum-translation in Spring Data REST

一笑奈何 提交于 2019-12-04 13:42:43

To use this feature you have to add a 'rest-messages' Resource Bundle to your project 'resources' folder. Then describe your enums in these files like this:

com.example.myproject.myapp.Roles.ROLE_ADMIN=Amministratore
com.example.myproject.myapp.Roles.ROLE_USER=Utente

If you have a nested enums you have to join them and the parent class with '$' sign:

com.example.myproject.myapp.User$Roles.ROLE_ADMIN=Amministratore
com.example.myproject.myapp.User$Roles.ROLE_USER=Utente

In the same manner you can describe your links:

_links.user.title=Utente
_links.users.title=Lista utenti

Then you get something like this:

"_links": {
    "user": {
        "href": "http://localhost:8080/api/users/1",
        "title": "Utente"
    }
}

"users": {
    "href": "http://localhost:8080/api/users{?page,size,sort}",
    "templated": true,
    "title": "Lista utenti"
}

There is also a little bit info in the SDR reference regarding to this issue.

See Restbucks example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!