Java 有没有办法减少页面返回上的参数数量?
我正在使用Spring在应用程序中实现分页,endpoit的返回是Java 有没有办法减少页面返回上的参数数量?,java,rest,spring-mvc,pagination,Java,Rest,Spring Mvc,Pagination,我正在使用Spring在应用程序中实现分页,endpoit的返回是Page。此对象返回许多参数。有没有办法消除其中一些 存储库扩展了JpaRepository 服务 @Autowired ClientRepositoy clientRepositoy; public List<Client> findAllList() { return clientRepositoy.findAll(); } 我想删除整个可分页对象,例如: "pageable": { "
Page
。此对象返回许多参数。有没有办法消除其中一些
存储库扩展了JpaRepository
服务
@Autowired
ClientRepositoy clientRepositoy;
public List<Client> findAllList() {
return clientRepositoy.findAll();
}
我想删除整个可分页对象,例如:
"pageable": {
"sort": {
"sorted": false,
"unsorted": true,
"empty": true
},
"offset": 0,
"pageNumber": 0,
"pageSize": 10,
"paged": true,
"unpaged": false
},
因此,我们在响应中使用了一个不能修改的类 我们可以用混合器 如果创建了ObjectMapperbean,则可以指定mixin,它将在序列化期间使用 它看起来像下面的代码 mixin设置getter的可见性。它将在序列化期间使用:
public interface PageImplMixin {
@JsonIgnore
Pageable getPageable();
}
自己的对象映射器bean,配置为在序列化pageimpl类时使用我们的mixin:
@Configuration
public class JacksonConfig {
@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper().setMixIns(Map.of(PageImpl.class, PageImplMixin.class));
}
}
理解该概念的一些链接:
public interface PageImplMixin {
@JsonIgnore
Pageable getPageable();
}
@Configuration
public class JacksonConfig {
@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper().setMixIns(Map.of(PageImpl.class, PageImplMixin.class));
}
}