当前位置:网站首页>JG data reset (WD)
JG data reset (WD)
2022-07-28 01:31:00 【qq_ forty million seven hundred and eleven thousand and ninety-】
Code
/** * Test class */
public void toSql() {
String table = "gzw07";
String id1 = "43";
String id2 = "44";
String format = String.format("select * from %s where id = '%s'", table, id1);
// aggregate
Map<String, Object> map = jdbcTemplate.queryForMap(format);
String sql = String.format("select * from %s where id = '%s' ", table, id2);
// Data class ->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);
}
/** * hold map2 The value assigned to 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) {
// It's not necessary to use it (JG-id Same )
if (!"id".equals(str)) {
String var = (String) map2.get(str);
map1.put(str, var);
}
}
System.out.println(map1);
// String gzw07 = maptosql(map1, "gzw07");
}
/** * map1 convert to sql * * @param map1 * @param table Table name * @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 The data belongs to that table * @param id data ID * @param json JSON -》to DB * @return */
public String zs1(String table, String id, String json) {
//1. basic sql, Take him as the template to assign values map
String format = String.format("select * from %s where id = '%s'", table, id);
Map<String, Object> map = jdbcTemplate.queryForMap(format);
// Is the data that needs to be reset . Can only simulate
Map map2 = (Map) JSON.parse(json);
//2. take map2 Assign a value to map(id With the exception of ,ID Nothing to ask for )
getmap(map, map2);
//3. take sql Return to... After splicing
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);
}
边栏推荐
- Cesium add dynamic pop-up
- 8000 word explanation of OBSA principle and application practice
- Day 013 一维数组练习
- How to solve the pain points of 12000 small and medium-sized customers' component procurement? Say goodbye to overtime!
- Anfulai embedded weekly report no. 275: 2022.07.18--2022.07.24
- Matlab drawing - points and vectors: method and source code of vector addition and subtraction
- 华米科技“黄山2号”发布:AI性能提升7倍,功耗降低50%!
- Codeforces暑期训练周报(7.21~7.27)
- Spreadsheet export excel table
- Cesium add inundation analysis measurement area
猜你喜欢

Unity shader introduction Essentials - basic texture

Flutter 通话界面UI

Lecture 16 of project practice: using the open close principle to realize the commodity price rule engine

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

ICML2022 | 在线决策Transformer

Icml2022 | online decision transformer

迅为i.MX6ULL开发板Qt系统移植-交叉编译Qt代码

二维数组相关知识

Lua快速上手

氧气温湿度模组
随机推荐
Lua get started quickly
测试人员需要了解的软件流程
Advanced MySQL -- stored procedures and custom functions
Anfulai embedded weekly report no. 275: 2022.07.18--2022.07.24
BAT大厂测试架构师如何解读测试平台的各种争议
Learn how Baidu PaddlePaddle easydl realizes automatic animal recognition in aquarium
JUC concurrent programming learning
开发 Flutter 录音功能的插件
糟糕程序员的20个坏习惯
mysql-JPA对数据库中JSON类型数据的支持
Thoroughly understand kubernetes scheduling framework and plug-ins
BigDecimal常用API
EWM receiving ECC delivery note verification logic problem
Day 013 一维数组练习
华为回应美国封锁供应链:他们仍需为5G专利付费
Fluent call interface UI
Codeforces summer training weekly (7.14~7.20)
Huawei responded to the US blockade of the supply chain: they still have to pay for 5g patents
晶方科技:光刻机厂商ASML为公司参与并购的Anteryon公司的最主要客户之一
软件测试面试题:性能测试指标有哪些?