我正在向用户显示一个表单,其中包含一些详细信息,然后用户单击批准并拒绝。在后端,我想将其放在一个属性中-userAction,可以“批准”或“拒绝”。
如何为用户单击的按钮添加输入?然后,此输入是对象requestDto的一部分。
<form th:action="@{/mission/store/{uuid}(uuid=${uuid})}" th:object="${requestDto}" method="post" class="mission_form">
<div class="wizard-header">
<h3 class="wizard-title">
Approve Mission
</h3>
<h5>Should you chose to accept this mission, press approve.</h5>
</div>
<div class="wizard-footer">
<!--<div class="pull-right">-->
<input type='button' class="btn btn-success" name='approve' value='Approve' />
<!--</div>-->
<div class="pull-left">
<input type='button' th:field="*{}" class='btn btn-danger' name='previous' value='Decline' />
</div>
<div class="clearfix"></div>
</div>
</form>
答案 0 :(得分:0)
首先定义一个适当的DataTransferObject:
import pandas as pd
import datetime
import os
import Tkinter
from Tkinter import Tk
from tkFileDialog import askdirectory
from Tkinter import filedialog
from os import listdir
from os.path import isfile, join
import glob
# Get input and output paths
Tk().withdraw()
sourcefolder = askdirectory()
outputfolder = askdirectory()
selectmonth = raw_input("Please enter month ('January', 'February'...:")
# Get content
all_files = glob.glob(os.path.join(sourcefolder, "*.xls*"))
contentdataframes = []
contentdataframes2 = []
for f in all_files:
df = pd.read_excel(f)
df['Name'] = os.path.basename(f).split('.')[0].split('_')[0]
mask = df.columns.str.contains('Base')
c2 = df.columns[~mask].tolist()
df = df[c2]
contentdataframes.append(df)
concatenatedfinal = pd.concat(contentdataframes)
concatenatedfinal .to_excel(outputfolder + "/" + selectmonth + "_Upload.xlsx",index=False)
然后将该类的对象添加到模型中
public class MyRequestDto {
private String userAction;
// don't forget getters and setters
}
定义这样的形式(我使用了按钮元素)。重点是不要使用th:field属性:
// if you are return a M&V-object:
ModelAndView mv = new ModelAndView("viewName")
ModelAndView.addObject("requestDto", new MyRequestDto());
// if you define a Model-Object as input-parameter:
Model.addAttribute("requestDto", new MyRequestDto());
通过将DataTransferObject添加到您的控制器输入参数(用于处理发布请求的控制器)中来接收该数据传输对象:
... @Valid RequestDto requestDto,BindingResult bindingResult,....
现在,您可以访问requestDto的userAction-Attribute。如果您单击第一个按钮,则该值为批准;如果您单击第二个按钮,则为拒绝。首先,您可以通过检查bindingResults.hasErrors()来检查是否存在绑定错误。