How to create Dynamic query in spring data

13 Views Asked by At

I am looking to create a dynamic sql according to data parameters using spring data As follows

My old SQL:

   @Query(value = "select" * " +
            "from t_corporation where " +
            "asset_code=:assetCode " +
            "and report_code=:reportCode", nativeQuery = true)
    IManagementAssetEntity getByAssetCode(String assetCode, reportCode);
When data assetCode is null then sql
    ==> select * from t_corporation where report_code=:reportCode
When data reportCode is null then sql  
     ==>  select * from t_corporation where asset_code=:assetCode
Else ==>  select * from t_corporation where asset_code=:assetCode and eport_code=:reportCode

I tried custom string data but it didn't work

0

There are 0 best solutions below