1.前端form表单提交,后端通过前端name属性直接获取
<form class="mt-5" method="post" th:action="@{/login}">
<input type="text" th:class="|form-control ${usernameMsg!=null?'is-invalid':''}|"
th:value="${param.username}"
id="username" name="username">
<div class="invalid-feedback" th:text="${usernameMsg}"> </div>
<label for="password" class="col-sm-2 col-form-label text-right">密码:</label>
<input type="password" th:class="|form-control ${passwordMsg!=null?'is-invalid':''}|"
th:value="${param.password}"
id="password" name="password">
<div class="invalid-feedback" th:text="${passwordMsg}"></div>
</form>
@RequestMapping(path = "/login", method = RequestMethod.POST)
public String login(String username, String password)
2.前端get请求,url示例:/index/orderMode=1,后端获取orderMode
<li class="nav-item">
<a th:class="|nav-link ${orderMode==0?active:''}|" th:href="@{/index(orderMode=0)}">最新</a>
</li>
@RequestMapping(path="/index",method = RequestMethod.GET)
public String getIndexPage(@RequestParam(name = "orderMode",defaultValue = "0") int orderMode){
3.前端get请求,url示例/detail/id,后端获取id
<a th:href="@{|/detail/${id}|}"
@RequestMapping(path="/detail/{id}",method = RequestMethod.GET)
public String getDiscussPost(@PathVariable("id") int id){