我正在写一个springboot应用程序,它应该计算学生的成绩。您应该从命令行读取学生的姓名,并调用一个将以JSON格式返回学生ID的API。然后,我将获取学生ID并调用另一个API,该API将返回JSON中的学生分数总数。然后,我应该相应地计算分数。计算如下: F=<60,D=<65,C=< 75,B=<85,A=<100。下面是我关于如何编写项目的假设视图,我认为我知道如何编写能够运行的代码,但我被项目或类设计的最佳框架所困。下面是我认为它应该如何写。
@Controller
// Rest call to the Student API
public class StudentController {
private static final Logger log = LoggerFactory.getLogger(ClientController.class);
private RestOperations rest;
private Config config; //to read the URL
..... @Controller
// Rest call to the grades API
public class GradsController
{
private static final Logger log = LoggerFactory.getLogger(ClientController.class);
private RestOperations rest;
private Config config; //to read the URL
.....Configuration
@ConfigurationProperties(prefix="api.call")
public class Config {
private String URL;
..... public class Student {
@JsonProperty("Data")
private Elements[] elements;
....... public class Grads {
@JsonProperty("Subjects")
private String[] subjects;
.......@Service
public class CalculateGrade {
private String marks;
private HashMap <String, Integer> gradeMap;
CalculateGrade( String marks)
{
this.marks = marks;
this.carName = carName;
fillMap();
}
private void fillMap()
{
gradeMap= new HashMap<>();
gradeMap.put("A",100);
gradeMap.put("B", 85 );
..........
}
public String getGrade()
{
// do calculations;
} @SpringBootApplication
@ConfigurationPropertiesScan ("Config")
public class MyApplication {
private static final Logger log = LoggerFactory.getLogger(MyApplication.class);
@Autowired StudentController StudentController;
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}发布于 2021-01-08 20:13:21
对于一个骨架来说,它看起来很明智。域/应用程序服务(CalculateGrade)中的业务逻辑。看起来很像六边形架构(“端口和适配器”)。
https://stackoverflow.com/questions/65627320
复制相似问题