Develop Chart Statistics APIs in a Spring Boot Project

Write Statistical SQLs

Before write the code, you can write statistical SQLs first. Because the core of statistical APIs are SQLs. As the saying goes, “first, solve the problem, then, write the code”.

Define Parameter and Response VOs

VO (value object) is typically used for data transfer between business layers and only contains data.

Parameter VOs

@Data
public class SomeStatParam {
private Date beginTime;
private Date endTime;
private Integer type;
private Integer userId;
...
}

Response VOs

@Data
public class someStatResult {
...
}

Write the APIs

@RestController
@RequestMapping(value = "/moduleName")
public class SomeStatController {
@GetMapping(value = "/getSomeStat")
public ResponseEntity<SomeStatResult> getSomeStat(SomeStatParam someStatParam) {
SomeStatResult data = someStatService.getSomeStat(someStatParam);
return ResponseEntity.ok(data);
}
}