简体   繁体   中英

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 [] . In postman , it returns other requests eg home method in controller class returns correctly. 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. It will help with your issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM