我的百里香叶形式没有拿起输入longUrl。当我在调试中运行该应用程序时,它会在下面用“”打出帖子请求。我如何使它获取表单输入并将其发送到正文中?

java - 胸腺模板不发布正文-LMLPHP

java - 胸腺模板不发布正文-LMLPHP

胸腺叶形式:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form method="POST" th:action="@{create_short_url_thymeleaf}">
    <h1>Hit Enter to Shorten Your Long Url</h1>
        <input type="text" th:name="longUrl"/>
</form>
</body>
</html>


即使当我尝试手动填充值时,它仍然没有将其添加到控制器中

<input type="text" name="longUrl" value="somelongurl"/>


控制器代码:

@Controller
@RequestMapping("/api/v1")
public class UrlShorteningController {

    @GetMapping("/create_short_url")
    public String newShortUrl(Model model) {
        model.addAttribute("longUrl",
            "");
        return "some-form";
    }

    @PostMapping("/create_short_url_thymeleaf")
    ResponseEntity<String> newShortUrlFromThymeleaf(@ModelAttribute String longUrl) {
        // Running the application on debug, I make it here, but the longUrl is empty.
       ....
    }

最佳答案

尝试更换
th:action="@{create_short_url_thymeleaf}

th:action="@{/create_short_url_thymeleaf}

08-17 15:04