我刚开始学习Spring Boot。我安装了STS并使用Web + JPA + MySQL + DevTools + Security创建了一个应用程序。当我创建我的控制器并用@RequestMapping注意它时,STS说RequestMapping无法解析为类型。
import org.springframework.stereotype.Controller;
@Controller
public class TestController {
@RequestMapping("/test")
public String test() {
return "test";
}
}
修改
我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd“&GT; 4.0.0
<groupId>com.heart</groupId>
<artifactId>echocardiogram</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>echocardiogram</name>
<description>Echocardiogram Management System</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
我该如何解决这个问题?
答案 0 :(得分:0)
**您应该像Request / POST / PUT / DELETE这样添加RequestMethodType。**这里我们使用get方法来返回内容
@Controller
public class TestController {
@RequestMapping(value="/test",method=RequestMethod.GET)
public String test() {
return "test";
}
}
答案 1 :(得分:-1)
检查POM并进行maven更新。 确保你已导入
import org.springframework.web.bind.annotation.RequestMapping;