gpt4 book ai didi

java - 如何将值传递给模型类

转载 作者:太空宇宙 更新时间:2023-11-04 13:34:01 25 4
gpt4 key购买 nike

在jsp页面中我使用输入字段

<input type="text"  name="basic" id="basic"  >

在 Controller 中

@RequestMapping(value="/palySlip/add",method=RequestMethod.POST)
public String addData(@ModelAttribute("empPaySlip") EmployeePlaySlip e){

return "redirect:/employeepayin";
}

并将值设置到模型类中

 public class EmployeePlaySlip {
private double basic;
public double getBasic() {
return basic;
}
public void setBasic(double basic) {
this.basic = basic;
}
}

但是在发送数据时我遇到了错误

HTTP Status 400 - type Status report message description The request sent by the client was syntactically incorrect.

最佳答案

首先,您需要将一个对象设置为模型属性。

@RequestMapping(value="/employeepaying",method=RequestMethod.POST)
public ModelAndView showData(){
ModelAndView mav = new ModelAndView("employeepayingPage");
mav.addObject(empPaySlip, new EmployeePlaySlip ());
return mav;
}

将 Spring 标签库添加到您的 JSP 中:

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

创建提交表单:

<form:form method="post"  modelAttribute="empPaySlip" action="/palySlip/add">
<form:input path="basic" />
<input type="submit" value="Submit" />
</form:form>

然后获取您的模型属性。

@RequestMapping(value="/palySlip/add", method=RequestMethod.POST)
public String addData(@ModelAttribute("empPaySlip") EmployeePlaySlip e){
// Do whatever you want with your object
return "redirect:/employeepaying";
}

关于java - 如何将值传递给模型类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31874116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com