[英]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.