问题:从图像中可以看到,浏览器无法加载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]由处理程序执行引起的已解决异常: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

最佳答案

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

实际上,param用于缩小与URL匹配的请求的范围

请参见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";
    }

10-08 10:51