gpt4 book ai didi

java - @Pathvariable 找不到编译错误

转载 作者:行者123 更新时间:2023-11-29 07:46:10 27 4
gpt4 key购买 nike

<分区>

我尝试使用 Maven 执行 Spring MVC 项目,但在 maven 打包时出现编译错误 -

错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project CounterWebApp: Compilation failure
[ERROR] /home/prem1980/apache-maven/all_maven_projects/java_webapp_project/CounterWebApp/src/main/java/com/mkyong/controller/BaseController.java:[23,36] cannot find symbol
[ERROR] symbol : class PathVariable
[ERROR] location: class com.mkyong.controller.BaseController

java文件

package com.mkyong.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

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

@RequestMapping(value="/welcome", method = RequestMethod.GET)
public String welcome(ModelMap model) {

model.addAttribute("message", "Maven Web Project + Spring 3 MVC - welcome()");

//Spring uses InternalResourceViewResolver and return back index.jsp
return "index";

}

@RequestMapping(value="/welcome/{name}", method = RequestMethod.GET)
public String welcomeName(@PathVariable String name, ModelMap model) {

model.addAttribute("message", "Maven Web Project + Spring 3 MVC - " + name);
return "index";

}

}

项目结构

[pr@web449 CounterWebApp]$ tree .
.
├── pom.xml
├── src
│   └── main
│   ├── java
│   │   └── com
│   │   └── mkyong
│   │   └── controller
│   │   └── BaseController.java
│   ├── resources
│   └── webapp
│   └── WEB-INF
│   ├── index.jsp
│   ├── mvc-dispatcher-servlet.xml
│   └── web.xml
└── target
├── classes
├── generated-sources
│   └── annotations
└── maven-status
└── maven-compiler-plugin
└── compile
└── default-compile
└── createdFiles.lst

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com