基于 Spring MVC 中数据库的值的计算

Calculations based on values from the database in Spring MVC

我在 Spring MVC 中获得了简单的 CRUD 应用程序,其中包含以下字段:userName (String)、height(float)、weight(float)、liverCoef(float)。我需要对 'liverCoef' 进行一些数学运算(例如:2 * (liverCoef / 9) +7)并在 JSP table 中的 'username' 旁边显示结果。我只能在 jsp 代码中进行这些数学运算,但我知道这是一种不好的做法。我怎样才能按照好的做法去做?

您可以在您拥有这些属性(用户名、身高、体重和 liverCoef)的 class 中创建其他 属性 以获得该计算,例如:

public class Person {
 private String username;
 private float height, weight, liverCoef, someCalculation;

 //getters and setters
 public float getSomeCalculation() {
   return 2 * (liverCoef / 9) +7);
 }
}