更新数据(update,delete)

HqlHelper配置

方法 等价HQL片段
update(String fromClazzFieldName, Object value) update ...
set fromClazz.fromClazzFieldName = value
where...
updateHqlSegment(String fromClazzFieldName, String hqlSegment) update ...
set fromClazz.fromClazzFieldName = hqlSegment
where...

例子

    @Autowired
    private HqlHelperService helperService;

    @Test
    public void testHql() {
        // 一个基本的更新例子
        // 将id=1160799039167057920 的城市名称更新为`新名称`
        // 并且,将sortSeq字段加1
        HqlHelper helper = HqlHelper.queryFrom(City.class);
        helper.update("name", "新名称")
              .updateHqlSegment("sortSeq", "sortSeq + 1")
              .eq("id", "1160799039167057920");
        int updateRow = helperService.update(helper);
        System.err.println("updateRow =" + updateRow);

        // 一个基本的删除例子
        //将name以「测试」开头的城市都删除掉
        helper.resetQueryFrom(City.class)
              .like("name", "测试", MatchType.START);
        int deleteRow = helperService.delete(helper);
        System.err.println("deleteRow =" + deleteRow);
    }
//执行结果:
updateRow =1
deleteRow =0
Copyright © Dodo Framework 2019 all right reservedModify At: 2019-12-25 11:46:55