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

cn.featherfly.persistence.jdbc.Test Maven / Gradle / Ivy

There is a newer version: 1.4.2
Show newest version

package cn.featherfly.persistence.jdbc;

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

import cn.featherfly.common.lang.LangUtils;

/**
 * 

* Test * 类的说明放这里 *

* * @author 钟冀 */ public class Test { public void update(String tableName, Map params, Map conditions) { StringBuilder sql = new StringBuilder(); sql.append("update ").append(tableName); if (LangUtils.isNotEmpty(params)) { sql.append(" set "); int index = 0; for (String key : params.keySet()) { if (index > 0) { sql.append(", "); } sql.append(key).append(" = :").append(key); index++; } } Map newCondition = new HashMap<>(); if (LangUtils.isNotEmpty(conditions)) { sql.append(" where "); int index = 0; for (String key : conditions.keySet()) { if (index > 0) { sql.append(" and "); } String conditionNamedParam = ":_condition_" + key; sql.append(key).append(" = ").append(conditionNamedParam); Object value = conditions.get(key); newCondition.put(conditionNamedParam, value); index++; } } params.putAll(newCondition); System.out.println(sql); System.out.println(params); } public static void main(String[] args) { Map parameters = new HashMap<>(); parameters.put("STATE", 1); parameters.put("TERMINATE_TIME", new Date()); parameters.put("LAST_MODIFY_TIME", new Date()); parameters.put("TERMINATER", 123); Map condition = new HashMap<>(); condition.put("ID", 123); condition.put("name", "yufei"); new Test().update("ad_advertising", parameters, condition); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy