我提出一个共同的项目聆听异常和使用@ControllerAdvice与@ExceptionHandler
@ControllerAdvice(annotations = RestController.class)
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler({Exception.class})
@ResponseStatus(value = HttpStatus.NOT_FOUND)
@ResponseBody
public ResponseEntity<ErrorResponse> notFound(Exception ex) {
return new ResponseEntity<>(
new ErrorResponse(ex.getMessage(), 404, "My Custom Message"), HttpStatus.NOT_FOUND);
}
}
Run Code Online (Sandbox Code Playgroud)
没有任何@SpringBootApplication主要的方法来作为依赖添加到我的另一个项目中。我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>spring-commons-rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-commons-rest</name>
<description>for Listening Exceptions</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> …Run Code Online (Sandbox Code Playgroud) 我有一个List<report>在Java的,我想将其更改为List<graph>
万一
class report {
String date;
String type;
String count;
}
class graph{
String date;
String numberA;
String numberB;
String numberC;
}
Run Code Online (Sandbox Code Playgroud)
例如我有:
date type count change it into > date numberA numberB numberC
03/21 A 8017 03/21 8017 5019 0
03/21 B 5019 03/22 5001 0 8870
03/22 A 5001 03/23 0 8305 0
03/22 C 8870 03/24 1552 2351 8221
03/23 B 8305
03/24 A 1552
03/24 B 2351
03/24 C 8221 …Run Code Online (Sandbox Code Playgroud)