Spring Boot添加HTML和JavaScript [英] Spring Boot add HTML and JavaScript
问题描述
我正在尝试使用一些HTML5和JavaScript运行Spring boot app,但是我遇到了问题.
我有这样的项目结构:
我的Spring MVC控制器正在调用文件offer.html,并且工作正常.
我的offer.html文件如下:
<!DOCTYPE html>< html lang ="zh-CN" ng-app ="coByTu">< head>< title>页面</title>< script type ="text/javascript" src ="../js/lib/angular.js"/>< script type ="text/javascript" src ="../js/src/offer.js"/></head><身体></body></html>
当我输入应用程序URL时
我不知道为什么我的应用程序看不到该脚本文件,有人可以知道我做错了什么吗?
基本上,所有需要静态提供的内容(例如javascript文件)都应放在静态文件夹下.
HTML文件:
<!DOCTYPE html>< html lang ="en">< head>< title>页面</title>< script type ="文本/javascript"th:src ="@ {/js/lib/angular.js}"/>< script type ="文本/javascript"th:src ="@ {/js/src/offer.js}""/></head><身体>
使用th:src将确保链接具有上下文意识
添加了th:src以使引用上下文可见
I'm trying to run Spring boot app with some HTML5 and JavaScript and I have a problem.
I have project structure like this:
My Spring MVC Controller is calling file offer.html and that works ok.
My offer.html file look like this:
<!DOCTYPE html>
<html lang="en" ng-app="coByTu">
<head>
<title>Page</title>
<script type="text/javascript" src="../js/lib/angular.js" />
<script type="text/javascript" src="../js/src/offer.js" />
</head>
<body>
</body>
</html>
And when I'm typing my app URL http://localhost:8080/offerView
response from server is:
I have no idea why my app doesn't see this script files, could any one have any idea what i did wrong?
Basically all content that needs to be served staticly (such as javascript files) should be placed under the static folder. https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot
I've thrown together a quick working example to show how it is done: https://github.com/ericbv/staticContentWithSpringBoot
File structure:
HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Page</title>
<script type="text/javascript" th:src="@{/js/lib/angular.js}" />
<script type="text/javascript" th:src="@{/js/src/offer.js}" />
</head>
<body>
Using th:src will make sure that the links are context aware
Edit: added the th:src to make the references context aware
这篇关于Spring Boot添加HTML和JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!