spring-attic / tut-react-and-spring-data-rest

React.js and Spring Data REST :: A tutorial based on the 5-part blog series by Greg Turnquist
https://spring.io/guides/tutorials/react-and-spring-data-rest
882 stars 1.58k forks source link

How does the mapping work? #82

Closed simonwangtx closed 5 years ago

simonwangtx commented 6 years ago

In HomeController, there is only one function mapping the root directory. So how could we get the JSON output when typing the URL like "localhost:8080/api/employees"? I guess this is probably in the rest.js part. And could you explain the mapping mechanism in detail? Really hard for me to understand it for now.

gregturn commented 6 years ago

Actually, /api is what is served by Spring Data REST. By default, Spring Data REST served from /, but since we want to serve a web template from there, we have spring.data.rest.base-path=/api configured in application.properties to tell Spring Data REST to shift the base URI.

From there, Spring Data REST is able to serve up any Spring Data repositories using a mapping algorithm along with a naming convention.