新建一个src/main/resources/static/js/main.js文件
window.onload = function(){ console.log("www.bonc.cn"); } |
在message_show_style.html总添加js
<!DOCTYPE HTML> <html xmlns:th="http://www.thymeleaf.org"> <head> <title>SpringBoot模版渲染</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> </head> <body> <p th:text="'官方网站:' + ${url}"/> <p th:utext="'官方网站:' + ${url}"/> <hr/> <h2 th:text="#{welcome.url}"/> <h2 th:text="#{welcome.msg('bonc')}"/> <h2 th:utext="#{welcome.msg(${url})}"/> <hr/> <p th:utext="'官方网站:' + ${url} + '、数学计算:' + (1 + 2)"/>
<script type="text/javascript" src="/js/main.js"></script> </body> </html> |
打开调试模式,观察Console,显示www.bonc.cn
现在改造一下src
<script type="text/javascript" th:src="@{/js/main.js}"></script> |
打开调试模式,观察Console,还是显示www.bonc.cn 打开sources,发现main.js已经改名了,查看源代码main.js文件名变了