目标:处理新旧数据迁移
问题:
1.数据库,新表中dynamic_field_json字段存储的是前端js encodeURI()编码后的字符串;
2.数据库,旧表需组装json格式字符串,然后java端需要参考前端js encodeURI()编码后重新存储;
方案:
public static void main(String[] args) {
Map<Object, Object> map = new HashMap<>();
map.put("label", "制作内容");
map.put("type", "TEXT");
map.put("val", "测试");
try {
logger.info("编码前:{}", SerializeUtils.convertMap2JsonString(map));
logger.info("编码后:{}", URLEncoder.encode(SerializeUtils.convertMap2JsonString(map), "Utf-8")
.replaceAll("\\+", "%20")
.replaceAll("\\%21", "!")
.replaceAll("\\%27", "'")
.replaceAll("\\%28", "(")
.replaceAll("\\%29", ")")
.replaceAll("\\%7E", "~")
.replaceAll("\\%2C", ",")
.replaceAll("\\%2F", "/")
.replaceAll("\\%3F", "?")
.replaceAll("\\%3A", ":")
.replaceAll("\\%40", "@")
.replaceAll("\\%26", "&")
.replaceAll("\\%3D", "=")
.replaceAll("\\%2B", "+")
.replaceAll("\\%24", "\\$")
.replaceAll("\\%23", "#"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}