Chào mọi người!
Hiện tại mình đang làm bài kết nối database trong mysql dùng spring boot, nhưng hiện tại mình đang gặp vấn đề nhỏ là nếu show theo từng cột trong database lên localhost theo dạng String thì show ra được, còn nếu show cả bảng dữ liệu theo class khai báo như dưới thì lại bị lỗi không đọc được. Ai biết mình sai chỗ nào chỉ giùm mình với ạ!
Đây là code của mình
UserGetting.java
package com.javainspires.simpleconnectapp.domain;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class UserGetting {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
private String email;
private int password;
private int phone;
public int getId() {
return id;
}
public void setId(int 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;
}
public int getPassword() {
return password;
}
public void setPassword(int password) {
this.password = password;
}
public int getPhone() {
return phone;
}
public void setPhone(int phone) {
this.phone = phone;
}
public UserGetting(int id, String name, String email, int password, int phone) {
super();
this.id = id;
this.name = name;
this.email = email;
this.password = password;
this.phone = phone;
}
public UserGetting() {
super();
}
@Override
public String toString() {
return "UserGetting [id=" + id + ", name=" + name + ", email=" + email + ", password=" + password + ", phone="
+ phone + "]";
}
UserController.java
package com.javainspires.simpleconnectapp.controller;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.javainspires.simpleconnectapp.domain.UserGetting;
import com.javainspires.simpleconnectapp.repo.UserRepo;
import com.javainspires.simpleconnectapp.repository.UserRepository;
@RestController
@RequestMapping(path = "/customer")
public class UserController {
@Autowired
UserRepository userRepository;
UserRepo userRepo;
/*@GetMapping
public String toTest() {
return "Welcome to Java Inspires...";
}*/
@GetMapping(path = "/getusername")
public List<String> getAllUserNames() {
return userRepository.getAllUserNames();
}
@GetMapping(path = "/getuser")
@ResponseBody
public List<UserGetting> getAllUser() {
return userRepo.findAll();
}
}