Spring boot 绑定按钮的方法-thymeleaf
我正在尝试使用thymeleaf将Robot类方法分配给按钮。在我的控制器中,我使用以下方法创建了控制器Spring boot 绑定按钮的方法-thymeleaf,spring-boot,thymeleaf,Spring Boot,Thymeleaf,我正在尝试使用thymeleaf将Robot类方法分配给按钮。在我的控制器中,我使用以下方法创建了控制器 @GetMapping("/start") public String test(Model theModel) { return "moveTheMouse"; } boolean bool = true; @RequestMapping("/move") public String moveTheMouseMeth
@GetMapping("/start")
public String test(Model theModel) {
return "moveTheMouse";
}
boolean bool = true;
@RequestMapping("/move")
public String moveTheMouseMethod() throws Exception {
Robot hal = new Robot();
while(bool){
hal.delay(1000 * 5);
int x = MouseInfo.getPointerInfo().getLocation().x + 2;
int y = MouseInfo.getPointerInfo().getLocation().y+ 2;
hal.mouseMove(x,y);
}
return "moveTheMouse";
}
我试图将它分配给html文件中的按钮,但是它不起作用
<a
th:action ="@{/move}"
class="btn btn-success btn-block">
MOVE THE MOUSE
</a>
移动鼠标
您可以向应用程序中添加表单并设置操作。因此,代码可以如下所示:
或者您可以使用
th:href
代替链接的th:action
。您可以执行以下任一操作:
(一)
(ii)
<a th:href ="@{move}" class="btn btn-success btn-block">
MOVE THE MOUSE
</a>
<form action="#" th:action="@{/move}" method="GET">
<input type="submit" value="Submit" />
</form>