javaspringhibernatetomcatspring-data-rest

Spring Boot adds 'es' to the links


I'm newcomer with Spring Boot and now after some lessons I'm trying to create RESTful+Hibernat+MySQL App. I've created:

Entity

@Entity
@Table(name = "customers")
@NamedQueries({
    @NamedQuery(name = "Customers.findAll", query = "SELECT c FROM Customers c")})
public class Customers implements Serializable {...};

Controller

@RestController
@RequestMapping("/customers")
public class CustomersController {

    @RequestMapping(method = GET)
    public List<Object> list() {
        return null;
    }

    @RequestMapping(value = "/{id}", method = GET)
    public Object get(@PathVariable String id) {
        return null;
    }

    @RequestMapping(value = "/{id}", method = PUT)
    public ResponseEntity<?> put(@PathVariable String id, @RequestBody Object input) {
        return null;
    }

    @RequestMapping(value = "/{id}", method = POST)
    public ResponseEntity<?> post(@PathVariable String id, @RequestBody Object input) {
        return null;
    }

    @RequestMapping(value = "/{id}", method = DELETE)
    public ResponseEntity<Object> delete(@PathVariable String id) {
        return null;
    }

} 

Repository

public interface CustomersRepository extends JpaRepository<Customers, Long> {
    public Optional<Customers> findOneByEmail(String email);
}

Finally ma App runs, and when I open the link in my browserand open the link localhost:8089 I see the following:

{
    "customerses" : {
      "href" : "http://localhost:8089/customerses{?page,size,sort}",
      "templated" : true
    }
  }
}

My question is why I have customerses on the end of controller name and who's adding this extension?

Thank you in advance.


Solution

  • It's done on purpose by Spring Data Rest - it assumes that entity name is singular, so it automatically makes it plural for the endpoint.
    You just need to rename your table and entity to singular - Customer. Here is a good explanation why it should be singular - SO answer.