spring-projects / spring-data-examples

Spring Data Example Projects
Apache License 2.0
5.2k stars 3.4k forks source link

@Query support any parser, for example. #643

Closed fengsoshuai closed 2 years ago

fengsoshuai commented 2 years ago
    @Query("insert into stock_logistics_no (logistics_id, logistics_type, logistics_no, stockout_id, send_province, send_city, send_district, send_address, status, created)" +
            " value (:logisticsId, :logisticsType, :logisticsNo, :stockOutId, :sendProvince," +
            ":sendCity, :sendDistrict, :sendAddress, :status, :created) ON DUPLICATE KEY UPDATE stockout_id=VALUES(stockout_id),status=VALUES(status)")
    Mono<Void> insertIntoOnDuplicateKey(Integer logisticsId, Integer logisticsType, String logisticsNo, Integer stockOutId,
                                        String sendProvince, String sendCity, String sendDistrict, String sendAddress, Integer status, LocalDateTime created);

    default Mono<Void> insertIntoOnDuplicateKey(StockLogisticsNo stockLogisticsNo) {
        return insertIntoOnDuplicateKey(
                stockLogisticsNo.getLogisticsId(), stockLogisticsNo.getLogisticsType(), stockLogisticsNo.getLogisticsNo(),
                stockLogisticsNo.getStockOutId(), stockLogisticsNo.getSendProvince(),
                stockLogisticsNo.getSendCity(), stockLogisticsNo.getSendDistrict(), stockLogisticsNo.getSendAddress(),
                stockLogisticsNo.getStatus(), LocalDateTime.now());
    }

I need use an Object to repalce this default method.

fengsoshuai commented 2 years ago

for examlple:

@Query("insert into stock_logistics_no (logistics_id, logistics_type, logistics_no, stockout_id, send_province, send_city, send_district, send_address, status, created)" +
            " value (:stockLogisticsNo.logisticsId, :stockLogisticsNo.logisticsType, :stockLogisticsNo.logisticsNo, :stockLogisticsNo.stockOutId, :stockLogisticsNo.sendProvince," +
            ":stockLogisticsNo.sendCity, :stockLogisticsNo.sendDistrict, :stockLogisticsNo.sendAddress, :stockLogisticsNo.status, :stockLogisticsNo.created) ON DUPLICATE KEY UPDATE stockout_id=VALUES(stockout_id),status=VALUES(status)")
    Mono<Void> insertIntoOnDuplicateKeyExample(StockLogisticsNo stockLogisticsNo);
fengsoshuai commented 2 years ago

the package is org.springframework.data.r2dbc.repository.Query

mp911de commented 2 years ago

Thanks for submitting an issue. This repository hosts only Spring Data examples and is not a general Q&A forum. Please take a look at the SpEL syntax that allows you to include dynamic parameter markers such as #{stockLogisticsNo.logisticsId}.

fengsoshuai commented 2 years ago

Thanks!