美文网首页
Spring Boot JPA Repository使用Proj

Spring Boot JPA Repository使用Proj

作者: Lin_XJ | 来源:发表于2017-09-11 13:46 被阅读0次

描述

@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标记。

相关文章

网友评论

      本文标题:Spring Boot JPA Repository使用Proj

      本文链接:https://www.haomeiwen.com/subject/hzxfsxtx.html