嗨,我有一個問題,我學到了如何傳遞值與PathVariable,我有一個輸入文本和一個按鈕,當你按下按鈕時,它會帶你到其他頁面和顯示值,但它不工作時,我按下它帶我到這個網址的BUTTOM:@RequestMapping與@PathVariable URI是不同的
http://localhost:8080/appThyme/shoForm1.html?firstname=MyName&submit=
和我得到這個錯誤HTTP 404 - /appThyme/showForm1.html
,但如果我把這個網址:http://localhost:8080/appThyme/respuesta/Myname
它WOR KS它讓我在我的網頁我的名字,我怎麼能作出這樣的工作,只有在按BUTTOM,爲什麼當我按下它添加問號和等於符號,我的URI
@Controller
public class HomeController {
@RequestMapping(value = "/form1", method = RequestMethod.GET)
public String showFormulario2(Model model) {
logger.info("***PAG formulario***");
return "form1.html";
}
@RequestMapping(value = "/showForm1/{id}", method = RequestMethod.GET)
public String showForm(Model model, @PathVariable("id") String id)
{
String theId= id;
model.addAttribute("TheID", theId);
return "showForm1.html";
}
我form1.html頁BUTTOM
<form id="guestForm" th:action="@{/showForm1.html}" method="get">
<div>
<input type="text" name="firstname" id="firstname"></input>
</div>
<div>
<button type="submit" name="submit">Submit</button>
</div>
</form>
我showForm1.html頁
enter code here
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>
Hello world!
</h1>
<P> The value is ${nombre} </P>
</body>
</html>
你爲什麼要把'th:action =「@ {/ showForm1.html}」'?應該如何處理? – 2014-09-03 15:43:08
我說,因爲我正在使用thymeleaf視圖解析器和「th」標記和註釋是必要的,但我有同樣的問題,如果我使用普通的視圖解析器與一個正常的「行動=」標籤 – stackUser2000 2014-09-03 15:46:47
好吧,忘記行動。你爲什麼使用**路徑**? – 2014-09-03 15:51:58