嘿,伙计们,我的代码有问题。由于某些原因,当我尝试将值更改为false时,它不会反映在我的sql数据库中。我调试过,它确实是通过java设置的,但是它没有传输过来。我正在处理一个通知服务类,它将其中的值设置为true没有问题,但是我的postmapping方法不起作用。我将在下面为add flight和我的通知服务发布一段代码。
@PostMapping("addflight")
String addflight(@ModelAttribute Flights flights, @SessionAttribute(required = false) String loggedInuser) {
Accounts a = accountsRepository.findByEmail(loggedInuser).get();
flightsRepository.saveAndFlush(flights);
List<Flights> flightsList = flightsRepository.findByAccountsOrderByDateofflightAsc(a);
if(flightsList.size() != 0) {
Flights lastFlight = flightsList.get(flightsList.size() - 1);
LocalDate today = LocalDate.now();
long days = 0;
days = ChronoUnit.DAYS.between(lastFlight.getDateofflight(), today);
if(days >= 46){
a.setNotified(false);
}
}
return "redirect:logbook";
}
############################# 通知片段#########################################
@Scheduled(fixedDelay = 4000000)
@Transactional
public void findFlights(){
List<Accounts> list = accountsRepository.allpilots();
List <Flights> accflight;
long days = 0;
long daysLeft = 0;
for(Accounts a: list) {
accflight = flightsRepository.findByAccountsOrderByDateofflightAsc(a);
if (accflight.size() == 0) {
System.out.println("No flights logged..");
continue;
}
Flights lastFlight = accflight.get(accflight.size() - 1);
days = ChronoUnit.DAYS.between(lastFlight.getDateofflight(), today);
if (!a.getNotified()) {
if (days > 60) {
System.out.println("You are uncurrent! It has been " + days + " days since your last flight");
try {
emailManager.sendMail(a.getEmail(), "You are uncurrent!", "Currency reminder");
a.setNotified(true);
} catch (Exception e) {
System.out.println(e);
System.out.println("Email failed to send!");
}
continue;
}
1条答案
按热度按时间368yc8dk1#
据我所知:你没有更新你的帐户后,设置通知为假。在使用以下内容设置更改后,需要保留更改
accountRepository.save(a);