Spring Boot推送通知

问题描述

我有一个Web应用程序,它使用spring boot作为后端,而vue.js作为前端,并且我有一个脚本python捕获,最后一个可以向数据库添加行,所以我需要将通知推送给用户,如何我可以吗?

@PostMapping("/plate")
public ResponseEntity<Void> createPositionOc(@RequestParam String plate) {

    LocalDateTime myDateObj = LocalDateTime.Now();
    DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    List<Car> cars = carController.getAllCars();
    boolean exist = cars.stream().anyMatch(o -> o.getPlate().equals(plate));

    List<Car> carsIn = carController.getAllCarsIn();
    boolean existIn = carsIn.stream().anyMatch(o -> o.getPlate().equals(plate));


    List<Position> free = getAllPositiosFree();

    PositionOcp position = new PositionOcp(free.get(0).getId_pos(),plate,myDateObj.format(myFormatObj));

    if (exist && free.size() > 0 && !existIn) {
        PositionOcp createdPositionOc = positionOcpRepository.save(position);
        //send notification
    }    

    return null;
}

解决方法

您将首先通过阅读有关推送通知的春季文档或类似这样的教程来实现这一目标:https://spring.io/guides/gs/messaging-stomp-websocket