我是 Spring Boot 的新手。我一整天都陷入了创建新数据(POST)的问题。该错误表明我没有成功连接到数据库(ORA-00942)。
由于一些隐私问题,我无法通过我的设备复制粘贴我的作品。因此,我将尽力描述我的逻辑并输入我的部分代码。任何想法都会有很大帮助!太感谢了!
- 我这里有五个包,基本上按(1.)SpringBootApplication包,(2.)Repository包(3.)Service包(4.)Controller包(5.)Entity包分类
- 基本上,我不会在 (1.)SpringBootApplication 包中进行编辑,它最初保留为默认值。
- 在我的 (5.)Entity 包中,我编写了一个与我的数据库匹配的实体类。假设这个实体的类名叫做 TitleOfMyDb。在这里,我已经正确地编写了对应的@id,并且我也正确地编写了setter和getter。
- 在 (3.)Service 包中,有一个接口和一个类。类基本上是接口的实现。现在,这是服务类的精简实现。
@Autowired private ExRepository exRepository; @Overrride public TitleOfMyDb createExampleMethod(String a, String b){ TitleOfMyDb titleOfMyDb = new TitleOfMyDb(); titleOfMyDb .setA(a); titleOfMyDb .setB(b); return exRepository.save(titleOfMyDb) //save method is originated from Repository instinctively.
- 在我的 (4.)Controller 包中,我有一个 ExController 类:
@Autowired private ExService exService; @GetMapping("/test") public TitleOfMyDb createSomething (@RequestParam(value="aa") String a, @RequestParam(value="bb") String b){ TitleOfMyDb object = exService.createExampleMethod(a, b) return object; }
- 在我的 (2.)Repository 包中,我没有在那里添加更多代码,它也保留了原始代码。因为它已经具有允许我使用存储库保存()我的实体的本能方法。
之后,当我尝试运行我的 spring boot 时,它显示 ORA-00942 错误。另外,当我通过浏览器输入http://localhost:8080/test时,我只能看到错误。错误消息非常复杂,抱歉我真的无法通过我的设备复制粘贴它。基本上,它没有正确连接到我的数据库。非常感谢对我的逻辑和思维过程的任何帮助或指导。谢谢!!!