1yml配置
spring:
thymeleaf:
suffix: .html
prefix: classpath:/templates/
cache: false
encoding: UTF-8
content-type: text/html
mode: HTML5
注意 要在 src\main\resources路径下新建templates文件夹
2 Controller向页面传值
package com.game.controller.mobile;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class TestController {
protected final Logger logger = Logger.getLogger(this.getClass());
@RequestMapping(value = "/test", method = {RequestMethod. POST ,RequestMethod. GET })
public String test(HttpServletRequest request) {
request.setAttribute("info", "enterGameMoblie调用异常");
return "err.html";// src\main\resources/templates/err.html
}
}
3 html接收
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<head>
<title>err</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script th:inline="javascript">
window.onload=function()
{
}
</script>
<body>
<div id="myDiv"><span th:text="${info}"></span></div>
</html>
访问测试