我試着使用Maven執行Spring MVC的項目,但同時得到行家包裝編譯錯誤 -@Pathvariable沒有找到編譯錯誤
錯誤
[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";
}
}
項目結構
[[email protected] 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