首页 > 解决方案 > 使用 JPA 查询时未显示响应正文

问题描述

我正在尝试使用 jpa 查询方法显示特定的实体数据,以通过它们的“Nome”参数和升序和降序的顺序找到它们。

我正在使用以下查询方法:

public List<Cliente> findByNomeOrderByNomeAsc(String nome);
public List<Cliente> findByNomeOrderByNomeDesc(String nome);

我的控制器代码是:

@ApiImplicitParam(name = "Authorization", value = "Bearer Token", required = true,
        allowEmptyValue = false, paramType = "header", example = "Bearer access_token")
@ApiOperation("Listar todos os clientes por nome em ordem crescente")
@GetMapping("/nome/asc/{nome}")
public List<Cliente> listarPorNomeOrdemCrescente(@PathVariable String nome) {
    return clienteRepository.findByNomeOrderByNomeAsc(nome);
}


@ApiImplicitParam(name = "Authorization", value = "Bearer Token", required = true,
        allowEmptyValue = false, paramType = "header", example = "Bearer access_token")
@ApiOperation("Listar todos os clientes por nome em ordem decrescente")
@GetMapping("/nome/desc/{nome}")
public List<Cliente> listarPorNomeOrdemDecrescente(@PathVariable String nome) {
    return clienteRepository.findByNomeOrderByNomeDesc(nome);
}

出于某种原因,我得到一个空向量作为响应,这意味着列表是空的。

截屏

客户实体:

@Entity
@ApiModel(value = "Cliente", description = "Representa um cliente")
@Table(name = "cliente")
public class Cliente {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull
    private String nome;

    @NotNull
    private String email;

    @NotNull
    private String senha;

    @NotNull
    private String documento;

    @NotNull
    private Date dataCadastro;

    //getters and setters
    }

如果有人能帮我解决这个问题,我将不胜感激。谢谢你。

标签: springapispring-mvcjpaswagger

解决方案


推荐阅读