Spring Boot JPA Repository使用Proj

2017-09-11  本文已影响0人  Lin_XJ

描述

@Repository
public interface RoleRepository extends CrudRepository<Role, Long> {
    Set<RoleDTO> findByUsers_Email(String email);
}

public interface RoleDTO {
    String getUuid();
    String getName();
    String getSecondRoleName();
    String getRoleDesc();
    Date getCreateDate();
    List<Module> getModules();
}

以上操作返回的RoleDTO,如果包含多个Module,也就是有一对多关系,结果会返回多个RoleDTO。

解决

public interface RoleDTO {
    @Value("#{target.uuid}")
    String getUuid();
    String getName();
    String getSecondRoleName();
    String getRoleDesc();
    Date getCreateDate();
    List<Module> getModules();
}

找一个字段确定唯一性,使用@Value标记。

上一篇 下一篇

猜你喜欢

热点阅读