All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.lingkang.mm.orm.UpadateWrapper Maven / Gradle / Ivy

Go to download

mybatis能力扩展框架,兼顾mybatis的mapper.xml编写操作数据库。

There is a newer version: 1.0.7
Show newest version
package top.lingkang.mm.orm;

import java.util.HashMap;
import java.util.Map;

/**
 * 更新包装对象,例1 :
 * 
 * {@code
 *     UpadateWrapper update = mapperManage.createUpdate("update t_user set password=#{p} where id=#{id}");
 *     update.addParam("p", System.currentTimeMillis()).addParam("id", 1);
 *     int execute = update.execute();
 *     log.info("受影响行数: {}", execute);
 * }
 * 
* 例2: *
 * {@code
 *     UpadateWrapper update = mapperManage.createUpdate("insert into t_user(id,username) values (2,#{un})");
 *     update.addParam("un", "lk");
 *     int execute = update.execute();
 *     log.info("受影响行数: {}", execute);
 * }
 * 
* * @author lingkang * @create by 2024/3/6 */ public class UpadateWrapper { private String sql; private MapperManageImpl manage; public UpadateWrapper(String sql, MapperManageImpl manage) { this.sql = sql; this.manage = manage; } private Map params = new HashMap<>(); /** * 添加参数,sql中的参数只能用 #{paramName}
* 代码例子: *
     * {@code
     *     UpadateWrapper update = mapperManage.createUpdate("update t_user set password=#{p} where id=#{id}");
     *     update.addParam("p", System.currentTimeMillis()).addParam("id", 1);
     *     int execute = update.execute();
     *     log.info("受影响行数: {}", execute);
     * }
     * 
* * @param name 参数名 * @param value 参数值 * @return 查询包装对象 */ public UpadateWrapper addParam(String name, Object value) { params.put(name, value); return this; } /** * 添加 map 参数 * * @param params map参数 * @return 查询包装对象 */ public UpadateWrapper addParam(Map params) { params.putAll(params); return this; } /** * 获取参数 * * @return map 参数 */ public Map getParams() { return params; } /** * 执行更新操作 * * @return 受影响行数 */ public int execute() { params.put("execSql_", sql); return manage.langMapper.update(params); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy