Это моя сущность клиента
@Entity
public class Customer
{
@Id
private String account_no;
private String customer_name,father_name,gender, phone, email, aadhaar; // phone no is varchar because I'll do validation in angular.
private double salary;
// one customer can have one loan. Relation is unidirectional
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="account_no")
private Loan loan;
public Customer() {}
@Override
public String toString() {
return "CustomerInfo [account_no=" + account_no + ", customer_name=" + customer_name + ", phone=" + phone
+ ", email=" + email + ", aadhaar=" + aadhaar + ", salary="
+ salary + ", loan=" + loan + "]";
}
}
Теперь это моя сущность займа
@Entity
public class Loan
{
@Id
@Column(name="account_no")
private String account_no; // making this as foreign key will not allow any holder to take loan again.
private String type;
private String issue_date;
private String last_payment;
private double loan_amount;
private double emi_amount;
private int emi_balance;
public Loan() {
}
@Override
public String toString() {
return "LoanInfo [account_no=" + account_no + ", type=" + type + ", loan_amount=" + loan_amount
+ ", emi_amount=" + emi_amount + ", emi_balance=" + emi_balance + ", issue_date=" + issue_date + "]";
}
}
Теперь код слоя Dao
Функция findCustomer () возвращает ноль. В dao findLoan () и addCustomer () работают нормально. Даже когда я проверил базу данных, она сохраняет данные в базе данных.
База данных, которую я использую - mysql, и hibernate используется для реализации приложения. Пружина mvc используется.
@Repository("bankDao")
@Transactional
public class BankDao {
@PersistenceContext
EntityManager em;
// It add customer details and loan details like emi while sanctioning any loan.
public void addCustomer(Customer customer) throws RevokeLoanException
{
try {
em.persist(customer);
}
catch(Exception e) {
throw new RevokeLoanException();
}
}
// for customer details
public Customer findCustomer(String accNo) throws LoanNotFoundException{
System.out.println(em.find(Customer.class, accNo));
Customer customer=em.find(Customer.class, accNo);
if(customer==null)
throw new LoanNotFoundException();
return customer;
}
// useful while paying emi
public Loan findLoan(String acc_no) throws LoanNotFoundException{
// TODO Auto-generated method stub
Loan loan=em.find(Loan.class, acc_no);
if(loan==null)
throw new LoanNotFoundException();
return loan;
}
Проблема, возникающая в контроллере. Контроллер не работает указанным c способом для id = 2020-04-30T23: 22: 00.210
вызов API = http://localhost: 8082 / LoanBackEnd / loan / loanStatus / 2020-04-30T23: 22: 00.210
@GetMapping("/loanStatus/{id}")
public ResponseEntity<Map<String, String>> loanStatus(@PathVariable String id) throws LoanNotFoundException{
System.out.println(id+" which got");
Map<String,String> response=bankService.loanStatus(id);
return new ResponseEntity<Map<String,String>>(response,HttpStatus.OK);
}
Эта печатная строка возвращает меня 2020-04-30T23: 22: 00 вместо 2020-04-30T23: 22: 00.210