无法跳转,400错误
老师看下代码哪里有错吗,点击提交报400错误,控制台输打印了一行
Field error in object 'persons' on field 'height': rejected value [160,55]; codes [typeMismatch.persons.height,typeMismatch.height,typeMismatch.double,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [persons.height,height]; arguments []; default message [height]]; default message [Failed to convert property value of type 'java.lang.String[]' to required type 'double' for property 'height'; nested exception is java.lang.NumberFormatException: For input string: "160,55"]]
package com.imooc.handler;
import com.imooc.entity.Persons;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/**
* TODO {file desc}
*
* @version 1.0
*/
@Controller
public class BMIHandler {
@RequestMapping("/cacultBMI")
public ModelAndView cacultBMI(Persons person) {
ModelAndView modelAndView = new ModelAndView();
double bmi = person.getWeight() / ((person.getHeight() / 100) * (person.getHeight() / 100));
System.out.println(bmi);
if (bmi < 19) {
modelAndView.addObject("msg", "多吃点,太瘦了!注意加强营养~");
modelAndView.setViewName("bmi1");
} else if (bmi >= 19 && bmi < 25) {
modelAndView.addObject("msg", "该减肥了!注意加强锻炼~");
modelAndView.setViewName("bmi1");
} else if (bmi >= 25) {
modelAndView.addObject("msg", "体重正常,注意保持~");
modelAndView.setViewName("bmi1");
}
return modelAndView;
}
}0
收起
正在回答 回答被采纳积分+1
2回答
相似问题
登录后可查看更多问答,登录/注册
SSM主流框架入门与综合项目实战2018版
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程

恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星