我对java和spring非常陌生。我有一个表格,收集要处理的数据。我的初始页面上的表单。我希望表单数据出现在第二个名为records.jsp的页面中。
这是我的init.jsp页面
<!-- Beginning of action 'compare' form -->
<form:form action="compare" method="POST" modelAttribute="dcf">
<table class="table table-responsive">
<tr>
<td>DB Source:</td>
<td>
<form:select id="sourceDbSelection" path="srcDb">
<form:option value="NONE" label="-Select-"/>
<form:options value="" items="${srcDbLst}" />
</form:select>
</td>
</tr>
<tr>
<td>DB Target:</td>
<td>
<form:select id="targetDbSelection" path="tgtDb" >
<form:option value="NONE" label="-Select-"/>
<form:options value="" items="${tgtDbLst}" />
</form:select>
</td>
</tr>
<tr>
<td>
<form:checkboxes title="Business Unit Filter:" path="businessUnit" items="${businessUnitLst}" />
</td>
</tr>
<tr>
<td colspan="2" align="center"><input onclick="validate()" id="submit" class="btn btn-primary" type="submit" name="execute" value="RUN" /></td>
我的表格模型
公共类datacompareform{
private String srcDb;
private String tgtDb;
private List<String> businessUnit;
public String getSrcDb() {
return srcDb;
}
public void setSrcDb(String srcDb) {
this.srcDb = srcDb;
}
public String getTgtDb() {
return tgtDb;
}
public void setTgtDb(String tgtDb) {
this.tgtDb = tgtDb;
}
public List<String> getBusinessUnit() {
return businessUnit;
}
public void setBusinessUnit(List<String> businessUnit) {
this.businessUnit = businessUnit;
}
}
我的控制器
@Controller
public class datacomparecontroller{protected logger log=logmanager.getlogger(this.getclass());
@Autowired
JsonSourceTargetDBService jsonDbSrcConverter;
@Autowired
DataCompareController dataCompareService;
// JSON File data & configs & the
@RequestMapping("/init")
public ModelAndView showForm(Model model) {
log.debug("starting to prepare src db data...alternative");
DBInstanceJson dbInst = jsonDbSrcConverter.load();
model.addAttribute("srcDbLst", dbInst.getSrcDB());
model.addAttribute("tgtDbLst", dbInst.getTgtDB());
model.addAttribute("businessUnitLst", dbInst.getBusinessUnitLst());
DataCompareForm dcf = new DataCompareForm();
model.addAttribute("dcf", dcf);
return new ModelAndView("init", "command", new DataCompareForm());
}
@RequestMapping(value="/compare", method = RequestMethod.POST)
public ModelAndView compare(@ModelAttribute("dcf")DataCompareForm dcf, Model model)
{
log.debug("Selection: src {}, target {}, # of business unit {}", dcf.getSrcDb(), dcf.getTgtDb(), dcf.getBusinessUnit().size());
model.addAttribute("source",dcf.getSrcDb());
model.addAttribute("target",dcf.getTgtDb());
//modelAndView.addObject("records", service.getRecord());
//model.addAttribute("age",dc.getAge());
//model.addAttribute("id",dcf.getId());
//System.out.println("First Name:"+stu.getFirstname()+"\n"+"Last Name:"+stu.getLastname()+"\n"+"Age:"+stu.getAge()+"\n"+"ID:"+stu.getId());
System.out.println(dcf.getSrcDb() +" " + dcf.getTgtDb());
//return new ModelAndView("records", "command", dcf);
return new ModelAndView("redirect:/records");
}
@RequestMapping("/records")
public ModelAndView viewRecords() {
List<DataCompareForm> list = new ArrayList<DataCompareForm>();
//Manually added to test
list.add(new HistoricalFileInformation(new Date(), "source" , "target", new String(), new String(), new String()));
return new ModelAndView("records","list",list);
}
}
要在其中显示form input records.jsp的窗体
<!-- RECORD TABLE START -->
<h2>Historical Data</h2>
<table class="table">
<tr>
<th>Date</th>
<th>Source</th>
<th>Target</th>
<th>File Name</th>
<th>File Size</th>
</tr>
<c:forEach var="dcf" items="${list}">
<tr>
<td>${dcf.date}</td>
<td>${dcf.srcDb}</td>
<td>${dcf.tgtDb}</td>
<td>${dcf.download}</td>
<td>${dcf.fileSize}</td>
</tr>
</c:forEach>
</table>
records.jsp表的模型
public class HistoricalFileInformation {
private Date genDate;
private String src;
private String tgt;
private String fileName;
private String fileSize;
private String urlLink;
public HistoricalFileInformation() {}
public HistoricalFileInformation(Date genDate, String src, String tgt, String fileName, String fileSize, String urlLink) {
this.genDate = genDate;
this.src = src;
this.tgt = tgt;
this.fileName= fileName;
this.fileSize = fileSize;
this.urlLink = urlLink;
}
public String getUrlLink() {
return urlLink;
}
public void setUrlLink(String urlLink) {
this.urlLink = urlLink;
}
public Date getGenDate() {
return genDate;
}
public void setGenDate(Date genDate) {
this.genDate = genDate;
}
public String getSrc() {
return src;
}
public void setSrc(String src) {
this.src = src;
}
public String getTgt() {
return tgt;
}
public void setTgt(String tgt) {
this.tgt = tgt;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getFileSize() {
return fileSize;
}
public void setFileSize(String fileSize) {
this.fileSize = fileSize;
}
}
暂无答案!
目前还没有任何答案,快来回答吧!