大佬教程收集整理的这篇文章主要介绍了调用Spring Data Rest Repository方法不会返回链接,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
HATEOAS功能仅对于带有注释的Spring数据jpa存储库可用@RepositoryRestresource
。这将自动公开其余端点并@R_502_6189@。
在控制器中使用存储库时,只需获取对象,杰克逊映射器便将其映射到Json。
如果您想在使用Spring MVC控制器时@R_502_6189@,请看@L_502_0@
我有存储库“ ClientRepository”:
public interface ClientRepository extends PagingAndSorTingRepository<Client,Long> {
}
当我请求http:// localhost:8080 / clients /
1时,服务器响应
{
"algorithmId" : 1,"lastNameTxt" : "***","firstNameTxt" : "**","middlenameTxt" : "**","_links" : {
"self" : {
"href" : "http://localhost:8080/clients/1121495168"
},"client" : {
"href" : "http://localhost:8080/clients/1121495168"
}
}
}
响应具有预期的链接。
当我在另一个控制器中调用存储库继承的方法findOne时
@RestController
public class SearchRestController {
@Autowired
public SearchRestController(ClientRepository clientRepository) {
this.CLIENtRepository = clientRepository;
}
@requestMapping(value = "/search",method = requestMethod.GET)
Client readAgreement(@requestParam(value = "query") String query,@requestParam(value = "category") String category) {
return clientRepository.findOne(Long.parseLong(query));
}
}
它回应
{
"algorithmId" : 1,"middlenameTxt" : "**"
}
为什么在第二种情况下响应不包含链接?如何使Spring添加他们的响应?
以上是大佬教程为你收集整理的调用Spring Data Rest Repository方法不会返回链接全部内容,希望文章能够帮你解决调用Spring Data Rest Repository方法不会返回链接所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。