Getメソッドで表示してHTMLテンプレートで名を取得したい。コントローラを実行しましたが、htmlテンプレートで指定した名前が表示されません。このコントローラーは、テンプレートからこのパラメーターを取得する必要があります。私は私のブラウザに例外がありますThere was an unexpected error (type=Bad Request, status=400). Required String parameter 'first_name' is not present
どこで間違えたのか教えてもらえますか?
これは私のサービスです:
public class ReadFamily {
@Autowired
ChildRespository childRespository;
private RestTemplate restTemplate;
public ReadFamily(){
restTemplate = new RestTemplate();
}
public ChildForm findChild(String firstName){
return restTemplate.getForObject("http://localhost:8080/findP/"+firstName,ChildForm.class);
}
public String firstNameFormat(ChildForm childForm) {
return childForm.getFirstName();
}
public String secondNameFormat(ChildForm childForm) {
return childForm.getSecondName();
}
public String sexFormat(ChildForm childForm) {
return childForm.getSex();
}
public String peselFormat(ChildForm childForm) {
return childForm.getPesel();
}
}
コントローラ:
@Autowired
ReadFamily readFamily;
@GetMapping("findP")
public String findPerson(Model model){
model.addAttribute("childForm",new ChildForm());
return"Find";
}
@RequestMapping (value = "findPersonResult", method = RequestMethod.POST)
public String findPerson(Model model,
@RequestParam ("first_name") String firstName) {
System.out.println(firstName);
ChildForm childInfo = readFamily.findChild(firstName);
model.addAttribute("firstName",readFamily.firstNameFormat(childInfo));
model.addAttribute("secondName",readFamily.secondNameFormat(childInfo));
model.addAttribute("pesel",readFamily.peselFormat(childInfo));
model.addAttribute("sex",readFamily.sexFormat(childInfo));
return "Find";
}
およびテンプレート:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Find person</title>
</head>
<body>
<form th:object="${childForm}" action="/findPersonResult" method="post">
<input type="text" th:field="*{firstName}" placeholder="firstName"> <br/>
<input type="submit" value="Find">
</form>
<h2>Persons</h2>
<form action="/findP" method="get">
<div id="show" >
<h1 th:text="${firstName} "></h1>
<h1 th:text="${secondName} "></h1>
<h1 th:text="${pesel} "></h1>
<h1 th:text="${sex} "></h1>
</div>
</form>
</body>
</html>
変化する
@RequestParam ("first_name") String firstName
に
@RequestParam ("firstName") String firstName
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加