我正在尝试提问,这是多种选择。我成功获得问题,但其选项为空。
<c:forEach begin="0" end="${optionsCount}" varStatus="loop">
<form:input path="options[${loop.index}].mcq"/>
</c:forEach>
public class OnlineTestQuestionBean {
private String optionsCount;
private Long questionId;
private String question;
private Set<QuestionOptionBean> options;
//setter getter
}
public class QuestionOptionBean {
private Long optionId;
private String mcq;
//setter getter
}
以下为控制器代码:-
@Controller
public class OnlineTestController {
@RequestMapping(value = "/savequestion", method = RequestMethod.GET)
public String addQuestion(Model model) {
model.addAttribute("OnlineTestQuestionBean", onlineTestQuestionBean);
return "addquestion";
}
@RequestMapping(value = "/savequestion", method = RequestMethod.POST)
public String saveQuestion(@ModelAttribute("OnlineTestQuestionBean")OnlineTestQuestionBean onlineTestQuestionBean, Model model) {
return null;
}
}
以下是Spring表单代码:-
<c:forEach begin="0" end="${optionsCount}" varStatus="loop">
<form:input path="options[${loop.index}].mcq"/>
</c:forEach>
当我提交该时间时,我得到“无法从大小为0的集合中获取索引为0的元素,使用属性路径进行访问”此异常,
假设我使用以下代码获取了空的设置值。
<input type="text" path="options.mcq"/>
答案 0 :(得分:0)
尝试使用以下形式:
df = df.mul(df.pop('Pnl'), axis=0).sum()
print (df)
W -2
X 122
Y 0
Z 2
dtype: int64