我是 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 应用程序运行,当我在浏览器中打开链接并打开链接 localhost:8089 时,我看到以下内容:
{
"customerses" : {
"href" : "http://localhost:8089/customerses{?page,size,sort}",
"templated" : true
}
}
}
我的问题是为什么我的控制器名称末尾有客户es以及谁添加了此扩展程序?
提前谢谢您。
这是 Spring Data Rest 故意完成的 - 它假设实体名称是单数,因此它会自动将端点变为复数。
您只需将表和实体重命名为单数 - Customer。
这是为什么它应该是单数的一个很好的解释 - SO 答案。