我正在编写一个用于计算学生成绩的 springboot 应用程序。您应该从命令行读取学生的姓名,并调用一个 API,该 API 将以 JSON 格式返回学生 ID。然后我将获取学生 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);
}
答案 0 :(得分:0)
对于一个骷髅来说,它看起来很明智。用于从 Web 转换为域的控制器以及域/应用程序服务中的业务逻辑 (CalculateGrade)。看起来很像六边形架构(“端口和适配器”)。