我的视图中具有生成数独网格的表单:
<div class="col-4 offset-4">
<form id="sudokuBoard" method="post" class="form-group text-center">
<div class="container">
<table class="row-eq-height table-striped table-bordered text-center">
<tr th:each="row: ${board}">
<td th:each="value: ${row}">
<div th:switch="${value}" class="col-xs-4">
<input name="cellValue" th:case="0" class="content form-control input"
style="text-align:center" type="text" pattern="[0-9]*"
maxlength="1" value="0">
<input name="cellValue" th:case="*" class="content form-control input"
style="text-align:center;background-color:lightgreen" type="text"
th:value="${value}" readonly>
</div>
</td>
</tr>
</table>
<div class="gap-10"></div>
<button type="submit" class="btn btn-outline-primary btn-sm">Check Solution</button>
<button class="btn btn-outline-primary btn-sm" onClick="window.location.reload();">New Game</button>
<button type = "submit" class="btn btn-outline-primary btn-sm" id="solveBoard"> Solve Puzzle</button>
</div>
</form>
board
值是通过此Controller方法传递的,该方法移出了可解决的难题。
@GetMapping("/sudoku")
String createSolvableBoard (Model model){
sudokuGenerator.generateBoard(9, 20);
sudokuGenerator.fillValues();
model.addAttribute("board", sudokuGenerator.getMat());
return "sudoku";
}
我想添加另一个选项来自动解决难题。这意味着必须刷新表格,并用已解决的木板填充。我的想法是通过单击按钮来调用另一个Controller方法并通过已解决的板发送,但我似乎无法将这两种方法都映射到/sudoku
Spring不允许。
有什么方法可以做吗?还是我应该看看其他选择?