定义

getDeleteExpression: 动态生成delete语句

  • tableEntity: 表类型的实体。
  • filters: 筛选找出对应要更新数据。

举例

Java Code:

@Test
public void testDelete() throws Exception {
        // 删除掉id 为1的产品。
        FilterDescriptor idFilter =
                new FilterDescriptor(FilterCondition.AND,
                        Product.class, Product::getProductID,
                        FilterOperator.EQUAL, 1);
        ParamExpression paramExpression =
                mybatisQueryProvider.getDeleteExpression(Product.class, idFilter);
        Map<String, Object> updateParam = new HashMap<>();
        updateParam.put("deleteExpression", paramExpression.getExpression());
        updateParam.putAll(paramExpression.getParamMap());
        int result = northwindDao.delete(updateParam);
        assertEquals(1, result);
}

mapper

@Mapper
public interface NorthwindDao {
    int delete(Map<String, Object> params);
}

xml:

<delete id="delete" parameterType="java.util.Map">
    ${deleteExpression}
</delete>

output:

==>  Preparing: DELETE FROM product WHERE (product_id = ?) 
==> Parameters: 1(String)
<==    Updates: 1

results matching ""

    No results matching ""