我是Spring Boot的新手,现在经过一些课程后,我试图创建RESTful + Hibernat + MySQL应用程序。我创造了:
实体
@Entity
@Table(name = "customers")
@NamedQueries({
@NamedQuery(name = "Customers.findAll", query = "SELECT c FROM Customers c")})
public class Customers implements Serializable {...};
控制器
@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;
}
}
存储库
public interface CustomersRepository extends JpaRepository<Customers, Long> {
public Optional<Customers> findOneByEmail(String email);
}
最后ma app运行,当我在浏览器中打开链接时打开链接localhost:8089我看到以下内容:
{
"customerses" : {
"href" : "http://localhost:8089/customerses{?page,size,sort}",
"templated" : true
}
}
}
我的问题是为什么我在控制器名称的末尾有 es 以及谁添加了此扩展程序?
提前谢谢。
答案 0 :(得分:2)
它是由Spring Data Rest专门完成的 - 它假设实体名称是单数的,因此它会自动使其成为端点的复数。
您只需将表格和实体重命名为单数 - 客户。
这是一个很好的解释,为什么它应该是单数 - SO answer。