Java 为什么我的Spring Boot Web应用程序中出现404错误?

Java 为什么我的Spring Boot Web应用程序中出现404错误?,java,spring,spring-mvc,Java,Spring,Spring Mvc,我是Spring的新手,我正在创建一个简单的MVC web应用程序来显示乐队信息。我有一个这样的控制器: @Controller @RequestMapping("/band") public class BandController { @Autowired BandRepository bandRepository; @RequestMapping("") public String index(Model model) { List&l

我是Spring的新手,我正在创建一个简单的MVC web应用程序来显示乐队信息。我有一个这样的控制器:

@Controller
@RequestMapping("/band")
public class BandController {

    @Autowired
    BandRepository bandRepository;

    @RequestMapping("")
    public String index(Model model) {

        List<Band> bands = bandRepository.findAll();
        model.addAttribute("bands", bands);
        return "band/bands";

    }

    @RequestMapping("/{id}")
    public String viewBand(@PathVariable String id, Model model) {

        Band band = bandRepository.get(id);
        model.addAttribute("band", band);
        return "band/viewBand";

    }

}
@控制器
@请求映射(“/band”)
公共类带宽控制器{
@自动连线
波段库波段库;
@请求映射(“”)
公共字符串索引(模型){
List bands=bandRepository.findAll();
model.addAttribute(“条带”,条带);
返回“波段/波段”;
}
@请求映射(“/{id}”)
公共字符串视口(@PathVariable字符串id,模型){
Band=bandRepository.get(id);
model.addAttribute(“带”,带);
返回“波段/可视波段”;
}
}
显示带区列表可以正常工作,但通过id时会出现一个白标签错误页面,显示“出现意外错误(type=notfound,status=404)。”

我的应用程序使用SpringBoot与JDBCTemplate和Thymeleaf。我有一个templates文件夹,里面有一个band文件夹,其中包含bands.html和viewBand.html

到目前为止,我只使用了注释


编辑:我使用的URL:

这不起作用,因为在您的请求映射中,您正在将其映射到
http://localhost:8080/band/{id}
。尝试将
@RequestMapping(“/{id}”)
更改为
@RequestMapping(“/viewBand/{id}”)


方法名称不会影响Spring使用的URL模式。

在传递id时,是否可以发布完整的URL。。