我无法使我的表格正常工作,我在不同的论坛上尝试了很多东西,但找不到解决方法
我的控制器:
@RequestMapping(value = "/board", method = RequestMethod.GET)
public String getCityValues(Model model) {
model.addAttribute("CityInfos", new CityInfos());
return "board";
}
@PostMapping("/board")
public String CitySubmit(@ModelAttribute CityInfos cityInfos) {
return "board";
}
我的课:
public class CityInfos {
private String cityName;
private String countryCode;
public CityInfos() {}
public CityInfos(String cityName, String countryCode) {
this.cityName = cityName;
this.countryCode = countryCode;
}
public String getCityName() {
return cityName;
}
public String getCountryCode() {
return countryCode;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
}
和board.html
<form th:action="@{/board}" th:object="${CityInfos}" method="post">
<p>Name of the City : <input type="text" th:text="*{cityName}" /></p>
<p>Country code : <input type="text" th:text="*{countryCode}" /></p>
<input type="submit" value="Submit" />
</form>
我只想将输入文本的值存储在我的java类中
答案 0 :(得分:0)
尝试一下:
@RequestMapping(value = "/board", method = RequestMethod.GET)
public ModelAndView getCityValues(ModelAndView mv) {
mv.setViewName("board");
mv.addObject("CityInfos", new CityInfos());
return mv;
}