首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Spring Boot CSS在尝试所有内容后显示为空白/未加载

Spring Boot CSS在尝试所有内容后显示为空白/未加载
EN

Stack Overflow用户
提问于 2016-12-09 17:25:43
回答 2查看 7.2K关注 0票数 1

我是Spring Boot的新手,目前我正在阅读这本书。Spring Boot正在运行。

我创建并编译了我的第一个web简单web应用程序,很好,预计css文件在控制台中显示为空白。我已经查阅了下面的帖子:

Spring Boot - CSS not loading

Spring Boot CSS Stripped

我使用的是百里叶,我的css文件被放在静态文件夹中,就像文章和书中所说的那样,但是什么也没有显示出来。我目前的外部链接,似乎也是正确的方式。

 <link rel="stylesheet" th:href="@{/main.css}" />

尽管css似乎显示在console的资源中,但css文件仍为空。下面是我的文件和代码。

文件结构:

模板:

body {
    background-color: #cccccc;
    font-family: arial,helvetica,sans-serif;
}
.bookHeadline {
    font-size: 12pt;
    font-weight: bold;

}
.bookDescription {
    font-size: 10pt;
}
label {
    font-weight: bold;
}
         <html xmlns:th="http://www.springframework.org/schema/data/jaxb">
    <head>
    <title>Reading List</title>
    <link rel="stylesheet" th:href="@{/main.css}" />
    </head>
    <body>
    <h2>Your Reading List</h2>
    <div th:unless="${#lists.isEmpty(books)}">
    <dl th:each="book : ${books}">
        <dt class="bookHeadline">
            <span th:text="${book.title}">Title</span> by
            <span th:text="${book.author}">Author</span>
            (ISBN: <span th:text="${book.isbn}">ISBN</span>)
        </dt>
        <dd class="bookDescription">
    <span th:if="${book.description}"
      th:text="${book.description}">Description</span>
            <span th:if="${book.description eq null}">
    No description available</span>
        </dd>
    </dl>
    </div>
    <div th:if="${#lists.isEmpty(books)}">
    <p>You have no books in your book list</p>
    </div>
    <hr/>
   <h3>Add a book</h3>
    <form method="POST">
    <label for="title">Title:</label>
    <input type="text" name="title" size="50"></input><br/>
    <label for="author">Author:</label>
    <input type="text" name="author" size="50"></input><br/>
    <label for="isbn">ISBN:</label>
    <input type="text" name="isbn" size="15"></input><br/>
    <label for="description">Description:</label><br/>
    <textarea name="description" cols="80" rows="5">
    </textarea><br/>
    <input type="submit"></input>
    </form>
    </body>
    </html>

控制器:

package codenotes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.List;

@Controller
@RequestMapping("/")
public class BookController {


private BookRepository bookRepository;

@Autowired
public BookController(BookRepository bookRepository) {
    this.bookRepository = bookRepository;
}

@RequestMapping(value = "/{reader}", method = RequestMethod.GET)
public String readerBooks(
        @PathVariable("reader") String reader,
        Model model) {

    List<Book> readingList =
            bookRepository.findByReader(reader);
    if (readingList != null) {

        model.addAttribute("books", readingList);
    }
    return "readingList";
}

@RequestMapping(value = "/{reader}", method = RequestMethod.POST)
public String addToReadingList(
        @PathVariable("reader") String reader, Book book) {
    book.setReader(reader);
    bookRepository.save(book);
    return "redirect:/{reader}";
}
}

存储库:

package codenotes;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
public interface BookRepository extends JpaRepository<Book, Long> {
List<Book> findByReader(String reader);
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41057042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档