gpt4 book ai didi

spring - Bean 名称的 BindingResult 和普通目标对象都不能用作请求属性

转载 作者:IT老高 更新时间:2023-10-28 13:43:46 28 4
gpt4 key购买 nike


各位专家,我有这个抛出上述错误的 Controller 代码。直到昨天它工作正常,我不知道同事对这段代码做了什么,今天我看到了错误:

Bean 名称 'sideForm' 的 BindingResult 和普通目标对象都不能用作请求属性

您能否建议我在哪里查找此类错误。我在 POST 或 GET 方法声明中是否有任何错误或返回错误?

非常感谢您的帮助:)

package com.att.analytics.ui;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.si.myworld.business.AdminChart;
import com.si.myworld.business.Chart;
import com.si.myworld.dao.AdminChartSummaryData;
import com.si.myworld.dao.BulletinData;
import com.si.myworld.dao.ChartData;

@RequestMapping("/index.html")
@Controller
public class IndexController {

private static final Logger log = Logger.getLogger(IndexController.class);

/**
* Called to load the page initially (GET request)
*
* @param model
* @return
*/
@RequestMapping(method = RequestMethod.GET)
public String getCharts(ModelMap model) {

Chart chart = new Chart();
chart.setTimeline("Monthly");
chart.setStartDt("mm/dd/yyyy");
chart.setEndDt("mm/dd/yyyy");

AdminChartSummaryData acsd = new AdminChartSummaryData();
List<AdminChart> list = acsd.getLandingChartDataList();

if (list.size() == 4) {
Chart chart1 = new Chart(list.get(0));
Chart chart2 = new Chart(list.get(1));
Chart chart3 = new Chart(list.get(2));
Chart chart4 = new Chart(list.get(3));
model.put("chart1", chart1);
model.put("chart2", chart2);
model.put("chart3", chart3);
model.put("chart4", chart4);

log.info("chart 1>>>>" + chart1);


ChartData cd = new ChartData();

String chartOneDatasource = cd.fetchChartDatasourceName(chart1
.getChartSubgroup());
String chartTwoDatasource = cd.fetchChartDatasourceName(chart2
.getChartSubgroup());
String chartThreeDatasource = cd.fetchChartDatasourceName(chart3
.getChartSubgroup());
String chartFourDatasource = cd.fetchChartDatasourceName(chart4
.getChartSubgroup());

String breadcrumbOne = chart1.getChartGroup() + ">>"
+ chart1.getChartSubgroup();
String breadcrumbTwo = chart2.getChartGroup() + ">>"
+ chart2.getChartSubgroup();
String breadcrumbThree = chart3.getChartGroup() + ">>"
+ chart3.getChartSubgroup();
String breadcrumbFour = chart4.getChartGroup() + ">>"
+ chart4.getChartSubgroup();


BulletinData bd = new BulletinData();
String bulletin = bd.getBulletinData();

model.put("sideForm", chart);



model.put("chartOneDatasource", chartOneDatasource);
model.put("chartTwoDatasource", chartTwoDatasource);
model.put("chartThreeDatasource", chartThreeDatasource);
model.put("chartFourDatasource", chartFourDatasource);

model.put("breadcrumbOne", breadcrumbOne);
model.put("breadcrumbTwo", breadcrumbTwo);
model.put("breadcrumbThree", breadcrumbThree);
model.put("breadcrumbFour", breadcrumbFour);

model.put("bulletin", bulletin);
}

return "land";
}


@RequestMapping(method = RequestMethod.POST)
public String loadCharts(HttpServletRequest request, ModelMap model, @ModelAttribute("sideForm") Chart chart) {

String from_date = request.getParameter("startDt");
String to_date = request.getParameter("endDt");

chart.setStartDt(from_date);
chart.setEndDt(to_date);

ChartData cd = new ChartData();

BulletinData bd = new BulletinData();
String bulletin = bd.getBulletinData();



AdminChartSummaryData acsd = new AdminChartSummaryData();
List<AdminChart> list = acsd.getLandingChartDataList();
if (list.size() == 4) {
Chart chart1 = new Chart(list.get(0));
Chart chart2 = new Chart(list.get(1));
Chart chart3 = new Chart(list.get(2));
Chart chart4 = new Chart(list.get(3));
model.put("chart1", chart1);
model.put("chart2", chart2);
model.put("chart3", chart3);
model.put("chart4", chart4);


String chartOneDatasource = cd.fetchChartDatasourceName(chart1
.getChartSubgroup());
String chartTwoDatasource = cd.fetchChartDatasourceName(chart2
.getChartSubgroup());
String chartThreeDatasource = cd.fetchChartDatasourceName(chart3
.getChartSubgroup());
String chartFourDatasource = cd.fetchChartDatasourceName(chart4
.getChartSubgroup());

model.put("chartOneDatasource", chartOneDatasource);
model.put("chartTwoDatasource", chartTwoDatasource);
model.put("chartThreeDatasource", chartThreeDatasource);
model.put("chartFourDatasource", chartFourDatasource);

String breadcrumbOne = chart1.getChartGroup() + ">>"
+ chart1.getChartSubgroup();
String breadcrumbTwo = chart2.getChartGroup() + ">>"
+ chart2.getChartSubgroup();
String breadcrumbThree = chart3.getChartGroup() + ">>"
+ chart3.getChartSubgroup();
String breadcrumbFour = chart4.getChartGroup() + ">>"
+ chart4.getChartSubgroup();


model.put("breadcrumbOne", breadcrumbOne);
model.put("breadcrumbTwo", breadcrumbTwo);
model.put("breadcrumbThree", breadcrumbThree);
model.put("breadcrumbFour", breadcrumbFour);
}
return "land";
}


@ModelAttribute("timeline")
public Collection<String> populateTimeline() {
return Arrays.asList("Daily", "Weekly", "Monthly", "Quarterly",
"Annually", "12_Month_Rolling");
}
}

此页面从如下所示的表单中获取值:

<form:form commandName="sideForm">
<div style="font-weight:bold; color:#000">Timeline</div>


<div style="margin:0 0 5px 0;"><form:select path="timeline" items="${timeline}" id="tm"/></div>

<div class="tofrom">From:</div>

<form:input path="startDt" id="from_date" size="7" maxlength="10" />

<div class="tofrom">To:</div>

<form:input path="endDt" id="to_date" size="7" maxlength="12" />

<input type="submit" value="Update Chart" />

</form:form>

最佳答案

确保您的 Spring 表单提及 modelAttribute="<Model Name" .

示例:

@Controller
@RequestMapping("/greeting.html")
public class GreetingController {

@ModelAttribute("greeting")
public Greeting getGreetingObject() {
return new Greeting();
}

/**
* GET
*
*
*/
@RequestMapping(method = RequestMethod.GET)
public String handleRequest() {
return "greeting";
}

/**
* POST
*
*
*/
@RequestMapping(method = RequestMethod.POST)
public ModelAndView processSubmit(@ModelAttribute("greeting") Greeting greeting, BindingResult result){
ModelAndView mv = new ModelAndView();
mv.addObject("greeting", greeting);
return mv;
}
}

在您的 JSP 中:

<form:form  modelAttribute="greeting" method="POST" action="greeting.html">

关于spring - Bean 名称的 BindingResult 和普通目标对象都不能用作请求属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1069958/

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