0
可以自定义为Spring Data REST生成的findAll和findById生成的默认查询吗?例如,选择列的一个子集,因为我发现设置@JsonIgnore不会更改查询生成中的SELECT列本身。自定义由Spring Data REST生成的默认查询
搜索查询可以通过@Query定制,但不知道如何与像所有用户或用户的其他环节上做到/ {ID}
可以自定义为Spring Data REST生成的findAll和findById生成的默认查询吗?例如,选择列的一个子集,因为我发现设置@JsonIgnore不会更改查询生成中的SELECT列本身。自定义由Spring Data REST生成的默认查询
搜索查询可以通过@Query定制,但不知道如何与像所有用户或用户的其他环节上做到/ {ID}
正如你所说的搜索查询可以通过@Query进行定制,这样你就可以只是覆盖在你的接口声明
public interface UserRepository extends JpaRepository<User, Long> {
@Query("select u from User u where u.firstname like %?1")
List<User> findAll();
@Query("select u from User u where u.id == %?1")
User findById(String id);
}
与查询注释默认方法,如果你想选择列的子集,我会建议公共列,将被映射到相同的表内展示创建新的实体。
class UserPublic
... public fields;
和开放的API基于新的实体仓库
public interface UserPublicRepository extends JpaRepository<UserPublic, Long> {}
我认为UserPublicRepository会UserPublic为JpaRepository泛型类型? – fortm 2014-11-02 11:08:50
是的,我会编辑:) – mavarazy 2014-11-02 11:22:56
如何控制为投影生成的查询?相关:http://stackoverflow.com/questions/26524529/how-to-control-sql-query-generated-during-spring-data-rest-projections – fortm 2014-11-16 18:49:02