当前位置:网站首页>JG-数据重置(wd)
JG-数据重置(wd)
2022-07-27 23:02:00 【qq_40711092】
代码
/** * 测试类 */
public void toSql() {
String table = "gzw07";
String id1 = "43";
String id2 = "44";
String format = String.format("select * from %s where id = '%s'", table, id1);
//集合
Map<String, Object> map = jdbcTemplate.queryForMap(format);
String sql = String.format("select * from %s where id = '%s' ", table, id2);
//数据类->jSON
User bean = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(User.class));
String string = JSON.toJSONString(bean);
Map map2 = (Map) JSON.parse(string);
Set<String> strings = map.keySet();
Set<String> set = map2.keySet();
getmap(map, map2);
}
/** * 把map2值赋值给map1 * * @param map1 * @param map2 */
public void getmap(Map map1, Map map2) {
System.out.println(map1);
Set<String> strings = map1.keySet();
for (String str : strings) {
//可用可不用(JG-id一样的)
if (!"id".equals(str)) {
String var = (String) map2.get(str);
map1.put(str, var);
}
}
System.out.println(map1);
// String gzw07 = maptosql(map1, "gzw07");
}
/** * map1转换成sql * * @param map1 * @param table 表名 * @return */
public String maptosql(Map map1, String table) {
String sql = "update " + table + " set ";
Set<String> set = map1.keySet();
for (String str : set) {
if (!"id".equals(str)) {
sql = sql + str + " = '" + map1.get(str) + "' , ";
}
}
sql = sql.substring(0, sql.lastIndexOf(","));
sql = sql + " where id = " + "'" + map1.get("id") + "'";
System.out.println(sql);
return sql;
/* int update = jdbcTemplate.update(sql); System.out.println(update);*/
}
/** * @param table 数据属于那个表 * @param id 数据ID * @param json JSON -》to DB * @return */
public String zs1(String table, String id, String json) {
//1.基本sql,以他为模板去赋值 map
String format = String.format("select * from %s where id = '%s'", table, id);
Map<String, Object> map = jdbcTemplate.queryForMap(format);
//是需要重置的数据。只能模拟
Map map2 = (Map) JSON.parse(json);
//2.将map2赋值给map(id除外,ID一样无所求)
getmap(map, map2);
//3.将sql拼接后返回
String maptosql = maptosql(map, table);
int update = jdbcTemplate.update(maptosql);
return String.valueOf(update);
}
controller
@RequestMapping(path = "/sql", method = {
RequestMethod.GET})
public Result sql(String id) {
//fileService.toSql();
String js = "{\"cjsj\":\"2022-07-17 18:40:08\",\"id\":44,\"lxfs\":\"44\",\"tzqy\":\"44\",\"userName\":\"tom44\",\"yxds\":\"44\"}";
String gzw07 = fileService.zs1("gzw07", id, js);
return Result.init(200, "", gzw07);
}
边栏推荐
- 线性代数 【23】 概念的深入01 - Points坐标点和Vectors向量
- dataworks 传输数据到mysql 中文乱码是什么原因
- JS global function method module exports exports
- Swoole内存-table详解
- 比亚迪半导体完成8亿元A+轮融资:30家知名投资机构入局,估值已达102亿元!
- Spool timer
- 学习笔记12:Eratosthenes筛选法求素数(100以内) 和 魔方阵
- Flutter--密码登录注册界面
- Recommended system model (III): fine scheduling model [LR, gbdt, wide & deep, DCN, DIN, Dien, MMOE, ple]
- Behind the war of seizing power in arm China: "two years of independence, it is still difficult to" independent "?
猜你喜欢

Swoole定时器

Node red interacts with tdengine

二维数组相关知识

代码随想录笔记_哈希_1002查找共用字符

3年经验想拿20K,居然面了半个月都没拿到?

Matlab drawing - points and vectors: method and source code of vector addition and subtraction

Fabric2.4.4 version building process (complete process)
![[STM32] watchdog module](/img/63/346d07c7febbaff69707f47ecb337c.png)
[STM32] watchdog module

Use of postman

C language programming | single dog topic explanation
随机推荐
2022/07/27 learning notes (Day17) code blocks and internal classes
swoole-WebSocket服务
Spool timer
测试人员需要了解的软件流程
spreadsheet 导出 excel表格
Matlab drawing - points and vectors: method and source code of vector addition and subtraction
Monitor mouse sideslip (adapt to mobile terminal)
站在数字零售转型的十字路口,我们需要用新的角度来看待它
激光器芯片厂商陕西源杰半导体获广发证券、中信证券等8家投资机构入股
110. In depth introduction to sap ui5 fileuploader control - why do you need a hidden iframe
Node red interacts with tdengine
Meguiar sued liandian for secret theft and sentenced: liandian was fined NT $100million and three employees were sentenced!
学习笔记12:Eratosthenes筛选法求素数(100以内) 和 魔方阵
Uni app advanced style framework / production environment
逻辑回归原理
20 bad habits of bad programmers
URDF 集成 Gazebo
Flutter--密码登录注册界面
uni-app进阶之样式框架/生产环境
DEMO:测试接口短时间内接收重复数据创建单据