spring css没有为spring boot项目加载

时间:2018-02-11 03:17:34

标签: java css spring

问题:正如您从图像中看到的那样,浏览器无法加载css文件。 我也在STS控制台中得到了这个例外:

[2m2018-02-10 19:00:57.770 [0; 39m [33m WARN [0; 39m [35m16292 [0; 39m [2m --- [0; 39m [2m [nio-8080-exec-3] ] [0; 39m [36m.wsmsDefaultHandlerExceptionResolver [0; 39m [2m:[0; 39m由Handler执行导致的已解决异常:org.springframework.web.bind.UnsatisfiedServletRequestParameterException:实际请求参数未满足参数条件“取消”:

the code was working fine until I completed the included Controller

任何人都知道为什么会这样?  浏览器出错(firefox)

][1]

!DOCTYPE html>

    <html xmlns:th="http://www.thymeleaf.org">
    <head lang="en" th:fragment="head">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <!-- jQuery library -->
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>

    <!-- Latest compiled JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7 /js/bootstrap.min.js"></script>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
    <link th:href="@{/css/style2.css}" rel="stylesheet" media="screen" />
    <link th:href="@{/css/login.css}" rel="stylesheet" media="screen"/>
    <link rel="stylesheet" type="text/css"  media="screen" th:href="@{/css/login.css}"/>
</head>
<body>

</body>
</html>
  

控制器

package com.intelbs.controllers;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.intelbs.dao.Customer;
import com.intelbs.dao.Employee;
import com.intelbs.dao.Expense;
import com.intelbs.dao.Note;
import com.intelbs.services.ExpenseService;

@Controller
public class ExpenseController {

    @Autowired
    private ExpenseService expService;

    @RequestMapping(value = "/monthlyExpenses", method = RequestMethod.GET)
    public String listMonthlyExpenses(Model model, String month, String year) {
        model.addAttribute("monthlyExpenses", expService.monthExpense(month, year));
        return "monthlyexpensesform";

    }

    @RequestMapping(value="new_expense", method = RequestMethod.GET)
    public String diplayAddExpenseForm( Model model) {
        System.out.println("inside  display");
        model.addAttribute("expense", new Expense());
        return "addexpenseform";

    }

    @RequestMapping(params= "save", method=  RequestMethod.POST)

    public String processAddExpenseForm(@Valid Expense expense, BindingResult br,
                                        Model model, RedirectAttributes ra) {
        System.out.println("inside processform");
        if(br.hasErrors()) {
            System.out.println("inside has er");    
            return"addexpenseform";

        }

        model.addAttribute("expense", expense);

        expService.saveExpense(expense);

        ra.addFlashAttribute("expense", expense);

        return "redirect:/customers";
    }

    @RequestMapping(params = "cancel",method= {RequestMethod.GET, RequestMethod.POST})
    public String cancelAddExpenseForm() {

        return "redirect:/customers";
    }
}

  [Browser error]: https://i.stack.imgur.com/xO4l5.png

1 个答案:

答案 0 :(得分:0)

我认为您在param中错误地使用value而不是@RequestMapping

实际上,param用于缩小与网址匹配的请求

请参阅doc

  

一系列“myParam = myValue”样式表达式,仅提供请求   如果发现每个这样的参数都具有给定值,则映射。

像这样折射您的代码。

@RequestMapping(value="/new_expense", method = RequestMethod.GET)
    public String diplayAddExpenseForm( Model model) {
        System.out.println("inside  display");
        model.addAttribute("expense", new Expense());
        return "addexpenseform";

    }

    @RequestMapping(value= "/save", method=  RequestMethod.POST)
    public String processAddExpenseForm(@Valid Expense expense, BindingResult br,
                                        Model model, RedirectAttributes ra) {
        System.out.println("inside processform");
        if(br.hasErrors()) {
            System.out.println("inside has er");    
            return"addexpenseform";

        }

        model.addAttribute("expense", expense);

        expService.saveExpense(expense);

        ra.addFlashAttribute("expense", expense);

        return "redirect:/customers";
    }

    @RequestMapping(value= "/cancel",method= {RequestMethod.GET, RequestMethod.POST})
    public String cancelAddExpenseForm() {

        return "redirect:/customers";
    }