控制器:
我返回这里,结果还可以。
@RequestMapping(method = RequestMethod.GET , value = "/pagination")
@ApiOperation(value = "Get By Pagination Operation", response = ProjectDto.class)
public ResponseEntity<TPage<ProjectDto>> getAllByPagination(Pageable pageable) {
TPage<ProjectDto> data =projectService.getAllPageable(pageable);
return ResponseEntity.ok(data);
}
存储库:
public interface ProjectRepository extends JpaRepository<Project, Long> {
Project getByProjectCode(String projectCode);
List<Project> getByProjectCodeContains(String projectCode);
Project getByProjectCodeAndIdNot(String projectCode, Long id);
Page<Project> findAll (Pageable pageable);
List<Project> findAll (Sort sort);
}
ProjectDTO:
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@ToString
@ApiModel(value = "Project Data Transfer Object")
public class ProjectDto {
@ApiModelProperty(value = "Project ID ")
private Long id;
@NotNull
@NotEmpty
@ApiModelProperty(required = true, value = "Name Of Project.")
private String projectName;
@NotNull
@NotEmpty
@ApiModelProperty(required = true, value = "Code Of Project.")
private String projectCode;
}
我的TPage: 我使用自己的TPage,以便所有信息都不可见。
public class TPage<T> {
private int number;
private int size;
private Sort sort;
private int totalPages;
private Long totalElements;
private List<T> content;
public void setStat(Page page, List<T> list) {
this.number = page.getNumber();
this.size = page.getSize();
this.sort = page.getSort();
this.totalPages = page.getTotalPages();
this.totalElements = page.getTotalElements();
this.content = list;
}
}
ProjectServiceImpl:
@Override
public TPage<ProjectDto> getAllPageable(Pageable pageable) {
Page<Project> data = projectRepository.findAll(pageable);
TPage<ProjectDto> response = new TPage<ProjectDto>();
response.setStat(data, Arrays.asList(modelMapper.map(data.getContent(), ProjectDto[].class)));
return response;
}
pom.xml依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.199</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
当我向与控制器映射的URL发出HTTP GET请求时,出现以下错误日志。
2019-10-15 18:16:44.237 DEBUG 2296 --- [nio-8000-exec-4] o.s.web.servlet.DispatcherServlet : GET "/api/project/pagination?page=1&size=3", parameters={masked}
2019-10-15 18:16:44.237 DEBUG 2296 --- [nio-8000-exec-4] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.http.ResponseEntity<com.basarsoft.issuemanagement.util.TPage<com.basarsoft.issuemanagement.dto.ProjectDto>> com.basarsoft.issuemanagement.controller.ProjectController.getAllByPagination(org.springframework.data.domain.Pageable)
2019-10-15 18:16:44.238 DEBUG 2296 --- [nio-8000-exec-4] o.h.e.t.internal.TransactionImpl : On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2019-10-15 18:16:44.238 DEBUG 2296 --- [nio-8000-exec-4] o.h.e.t.internal.TransactionImpl : begin
2019-10-15 18:16:44.238 DEBUG 2296 --- [nio-8000-exec-4] o.h.q.c.internal.CriteriaQueryImpl : Rendered criteria query -> select generatedAlias0 from Project as generatedAlias0
2019-10-15 18:16:44.239 DEBUG 2296 --- [nio-8000-exec-4] org.hibernate.SQL : select project0_.id as id1_2_, project0_.created_at as created_2_2_, project0_.created_by as created_3_2_, project0_.status as status4_2_, project0_.updated_by as updated_5_2_, project0_.updated_at as updated_6_2_, project0_.manager_user_id as manager_9_2_, project0_.project_code as project_7_2_, project0_.project_name as project_8_2_ from project project0_ limit ? offset ?
Hibernate: select project0_.id as id1_2_, project0_.created_at as created_2_2_, project0_.created_by as created_3_2_, project0_.status as status4_2_, project0_.updated_by as updated_5_2_, project0_.updated_at as updated_6_2_, project0_.manager_user_id as manager_9_2_, project0_.project_code as project_7_2_, project0_.project_name as project_8_2_ from project project0_ limit ? offset ?
2019-10-15 18:16:44.239 DEBUG 2296 --- [nio-8000-exec-4] org.hibernate.loader.Loader : Result set row: 0
2019-10-15 18:16:44.240 DEBUG 2296 --- [nio-8000-exec-4] org.hibernate.loader.Loader : Result row: EntityKey[com.basarsoft.issuemanagement.model.Project#4]
2019-10-15 18:16:44.240 DEBUG 2296 --- [nio-8000-exec-4] org.hibernate.loader.Loader : Result set row: 1
2019-10-15 18:16:44.240 DEBUG 2296 --- [nio-8000-exec-4] org.hibernate.loader.Loader : Result row: EntityKey[com.basarsoft.issuemanagement.model.Project#5]
2019-10-15 18:16:44.240 DEBUG 2296 --- [nio-8000-exec-4] org.hibernate.loader.Loader : Result set row: 2
2019-10-15 18:16:44.240 DEBUG 2296 --- [nio-8000-exec-4] org.hibernate.loader.Loader : Result row: EntityKey[com.basarsoft.issuemanagement.model.Project#6]
2019-10-15 18:16:44.240 DEBUG 2296 --- [nio-8000-exec-4] o.h.engine.internal.TwoPhaseLoad : Resolving associations for [com.basarsoft.issuemanagement.model.Project#4]
2019-10-15 18:16:44.240 DEBUG 2296 --- [nio-8000-exec-4] o.h.engine.internal.TwoPhaseLoad : Done materializing entity [com.basarsoft.issuemanagement.model.Project#4]
2019-10-15 18:16:44.240 DEBUG 2296 --- [nio-8000-exec-4] o.h.engine.internal.TwoPhaseLoad : Resolving associations for [com.basarsoft.issuemanagement.model.Project#5]
2019-10-15 18:16:44.240 DEBUG 2296 --- [nio-8000-exec-4] o.h.engine.internal.TwoPhaseLoad : Done materializing entity [com.basarsoft.issuemanagement.model.Project#5]
2019-10-15 18:16:44.240 DEBUG 2296 --- [nio-8000-exec-4] o.h.engine.internal.TwoPhaseLoad : Resolving associations for [com.basarsoft.issuemanagement.model.Project#6]
2019-10-15 18:16:44.240 DEBUG 2296 --- [nio-8000-exec-4] o.h.engine.internal.TwoPhaseLoad : Done materializing entity [com.basarsoft.issuemanagement.model.Project#6]
2019-10-15 18:16:44.240 DEBUG 2296 --- [nio-8000-exec-4] o.h.q.c.internal.CriteriaQueryImpl : Rendered criteria query -> select count(generatedAlias0) from Project as generatedAlias0
2019-10-15 18:16:44.240 DEBUG 2296 --- [nio-8000-exec-4] org.hibernate.SQL : select count(project0_.id) as col_0_0_ from project project0_
Hibernate: select count(project0_.id) as col_0_0_ from project project0_
2019-10-15 18:16:44.241 DEBUG 2296 --- [nio-8000-exec-4] org.hibernate.loader.Loader : Result set row: 0
2019-10-15 18:16:44.241 DEBUG 2296 --- [nio-8000-exec-4] org.hibernate.loader.Loader : Result row:
2019-10-15 18:16:44.241 DEBUG 2296 --- [nio-8000-exec-4] o.h.e.t.internal.TransactionImpl : committing
2019-10-15 18:16:44.243 DEBUG 2296 --- [nio-8000-exec-4] .m.m.a.ExceptionHandlerExceptionResolver : Using @ExceptionHandler public final org.springframework.http.ResponseEntity<java.lang.Object> org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler.handleException(java.lang.Exception,org.springframework.web.context.request.WebRequest) throws java.lang.Exception
2019-10-15 18:16:44.244 DEBUG 2296 --- [nio-8000-exec-4] o.s.w.s.m.m.a.HttpEntityMethodProcessor : No match for [*/*], supported: []
2019-10-15 18:16:44.244 DEBUG 2296 --- [nio-8000-exec-4] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class com.basarsoft.issuemanagement.util.TPage]
2019-10-15 18:16:44.244 DEBUG 2296 --- [nio-8000-exec-4] o.s.web.servlet.DispatcherServlet : Completed 500 INTERNAL_SERVER_ERROR
我想知道我是否忘记了项目中的任何配置。