Spring Boot应用程序我无法从Oracle数据库中获取数据,它在邮递员中返回[]

时间:2019-12-25 12:27:35

标签: spring oracle hibernate spring-boot

Spring Boot应用程序我无法从oracle数据库获取数据,它返回[]。在postman中,它返回其他请求,例如,控制器类中的home方法正确返回。另外,由模型类创建的表的问题是从表中获取数据。

这是邮递员的结果:

here is the postman reuslt

我在控制台中得到这个:

i get this in console 模型课程

@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;
}


}

//控制器类

    @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";

    }
}

//存储库类

    public interface UserRepository extends CrudRepository<Userr, Integer> {

}

1 个答案:

答案 0 :(得分:0)

将@Repository批注添加到UserRepository。它将帮助您解决问题。