Spring Boot-无法在网页中添加JS [英] Spring Boot - unable to add JS in a webpage

查看:107
本文介绍了Spring Boot-无法在网页中添加JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的网页,想在其中添加JS.

I have a simple webpage and want to add JS to it.

呈现页面的控制器为-

@Controller
@RequestMapping("/testui")
public class GreetingController {

@RequestMapping("/greeting")
public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
    model.addAttribute("name", name);
    return "pages/greeting";
}

}

我的资源文件夹的结构是-

The struture of my resources folder are -

src/main/resources
|
 -- static
 --templates
   |
    --css
    --js
    --pages

胸腺页面是-

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>

</head>

<body>
Welcome to the future
</body>
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
</html>

PS-我也尝试过-

<script type="text/javascript" th:src="@{js/jquery-1.10.2.min.js/}"></script>

但同样的问题

推荐答案

问题出在cssjs文件夹所在的地方,它们应该在static文件夹中.

The problems is the place where your css and js folders are, those should be inside of static folder.

src/main/resources
|
 -- static
   |
    --css
    --js
 --templates
   |
    --pages

在您的*.html页面中,您可以使用:

And in your *.html page you can use:

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- include css -->
    <link rel="stylesheet" type="text/css" th:href="@{/css/style.css}"/>
</head>

<body>
Welcome to the future
</body>
    <!-- include javascript -->
    <script type="text/javascript" th:src="@{/js/jquery-1.10.2.min.js}"></script>
</html>

这篇关于Spring Boot-无法在网页中添加JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆