java用 postman输入 数字 会加上单引号 和逗号,方便查询
/**
* 输入12575726
* 891006
* 12575726
* 891006
* 返回
* '12575726',
* '891006',
* '12575726',
* '891006'
* 方便查询数据
* @param data
* @return
*/
@RequestMapping(value = "listIn", consumes = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> listIn(@RequestBody String data) {
// 按换行符拆分字符串
String[] dataArray = data.split("\\r?\\n");
StringBuilder builder = new StringBuilder();
for (String value : dataArray) {
builder.append("'").append(value.trim()).append("',\n");
}
String result = builder.toString();
result = result.substring(0, result.length() - 2); // 移除最后一个逗号和换行符
System.out.println(result);
return ResponseEntity.status(HttpStatus.OK)
.header("Content-Type", "text/plain")
.body(result);
}
用法