java 无法访问同一个包中的类

gzszwxb4  于 2023-05-15  发布在  Java
关注(0)|答案(1)|浏览(154)

我正在遵循Sping Boot 教程,其中包含2个简单的类。这是控制器类:

package org.example.springbootquickstart.topic;

import java.util.Arrays;
import java.util.List;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TopicController {

   @RequestMapping( "/topics" )
   public List<Topic> getAllTopics() {
      return Arrays.asList(
            new Topic("123123123", "Spring Framework", "Spring Framework Description"),
            new Topic("java", "Core Java", "Core Java Description"),
            new Topic("javascript", "JavaScript", "JavaScript Description"));
   }
}

这是Topic类:

package org.example.springbootquickstart.topic;

public class Topic {

   private String id;
   private String name;
   private String description;

   public Topic() {

   }

   public Topic( String id, String name, String description ) {
      super();
      this.id = id;
      this.name = name;
      this.description = description;
   }

// getters and setters ...

}

主类在org.example.springbootquickstart包中。现在,这段代码运行没有任何问题,我可以看到打开路由时的JSON响应:

问题是IntelliJ显示以下错误消息,我不知道为什么会这样:Cannot access org.example.springbootquickstart.topic.Topic

isr3a4wc

isr3a4wc1#

尝试“从磁盘重新加载文件”/“重新加载项目”/“使缓存无效”。有时Intellij会毫无理由地显示这样的错误

相关问题