简体   繁体   English

Spring boot 应用程序我无法从 oracle 数据库中获取数据,它在 postman 中返回 []

[英]Spring boot application I can not get data from oracle database it returns [] in postman

Spring boot application I can not get data from oracle database it returns [] . Spring 启动应用程序我无法从 oracle 数据库中获取数据,它返回[] In postman , it returns other requests eg home method in controller class returns correctly.postman ,它返回其他请求,例如控制器类中的 home 方法正确返回。 also, the table created by model class the problem is getting data from the table.此外,模型类创建的表问题是从表中获取数据。

Here is the postman result:这是邮递员的结果:

这是邮递员结果

I get this in console:我在控制台中得到这个:

我在控制台得到这个 Model class模型类

@Entity // This tells Hibernate to make a table out of this class
public class Userr {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;

private String name;

private String email;

public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}


}

//Controller Class //控制器类

    @RestController
public class MainController {
        @Autowired // This means to get the bean called userRepository
        // Which is auto-generated by Spring, we will use it to handle the data
        private UserRepository userRepository;

        @PostMapping(path="/add") // Map ONLY POST Requests
        public @ResponseBody String addNewUser (@RequestParam String name
                , @RequestParam String email) {
            // @ResponseBody means the returned String is the response, not a view name

        // @RequestParam means it is a parameter from the GET or POST request

        Userr n = new Userr();
        n.setName(name);
        n.setEmail(email);
        userRepository.save(n);
        return "Saved";
    }

    @GetMapping(path="/all")
    public @ResponseBody Iterable<Userr> getAllUsers() {
        // This returns a JSON or XML with the users
        //
        return userRepository.findAll();
    }
@GetMapping(path="/al")
public List<Userr> printPersonInfo() {
    List<Userr> list = new ArrayList<>();
    userRepository.findAll().forEach(list::add);
    return list;
}





@RequestMapping("/user")
public String home(){
    return "PPPPPP";

    }
}

//Repository Class //存储库类

    public interface UserRepository extends CrudRepository<Userr, Integer> {

}

Add @Repository annotation to your UserRepository.将 @Repository 注释添加到您的 UserRepository。 It will help with your issue.它将帮助您解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 无法从浏览器访问启动应用程序,也无法访问 Postman - Spring Boot application can't be reached from browser nor Postman KTable 在 Spring Boot 应用程序中不返回任何数据,但可以查询 - KTable returns no data in Spring Boot application, however it can be queried spring boot无法从配置的外部oracle数据库中获取数据 - spring boot not fetching data from external oracle database configured 如何使用 Spring Boot 和 Postman 将 Excel 文件上传到 MySQL 数据库? - 状态:401 未经授权 - How can I upload an excel file with Spring Boot and Postman to a MySQL Database? - Status: 401 Unauthorized 如何解决通过 Z03D476861AFD3854510 测试 spring 引导 rest api 时遇到的错误? - How can I solve the error I get while testing the spring boot rest api via postman? Postman 没有从 Spring 应用程序中获取数据 - Postman is not fetching data from spring application 从 MySQL 数据库中获取数据,使用 Spring 引导按日期过滤 - Get data from MySQL database filtered by date with Spring boot Spring Boot无法从application.yml获取配置 - spring boot can not get configuration from application.yml Spring Boot无法从MySQL数据库获取和显示数据 - Spring Boot can't fetch and display Data from MySQL Database 具有Oracle数据库重置连接的容器化Spring Boot应用程序 - Containerized spring boot application with oracle database resetting connection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM