如何通过java中restapi中的@getmapping传递enum参数来列出所有内容?

oknrviil  于 2021-07-12  发布在  Java
关注(0)|答案(0)|浏览(221)

我需要在SpringBoot中搜索所有使用这个名称“type”的对象,怎么做?
我的代码:

//Find by type
@GetMapping("/type")
public ResponseEntity<List<Address>> listAddressByType(@RequestParam("type") descriptiontype type){
    return ResponseEntity.ok(repository.findByTypeContains(type));
}

我的枚举:

public enum descriptiontype {

    HOME,
    APARTMENT,
    COMPANY,
    GOVERNMENT;

}

我的存储库:

public interface Repository extends JpaRepository<Address, Long> {

    List<Address> findByCepContains(String cep);
    List<Address> findByTypeContains(descriptiontype type);
}

我的型号:

@Enumerated(value = EnumType.STRING)
@Column(nullable = false)
private descriptiontype type;

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题