MCPcopy Create free account
hub / github.com/Bit0r/java-util / getEntityMessage

Method getEntityMessage

src/main/java/util/CommonUtils.java:270–287  ·  view source on GitHub ↗

获取错误提示 实体中的@NotBlank @NotNull @param fieldErrorList @param map map.put("字段名","提示语"); 提示是否替换 map.put("bigType","大类不能为空ZC"); 不替换默认使用注解中的message值 @return

(List<FieldError> fieldErrorList, Map<String, Object> map)

Source from the content-addressed store, hash-verified

268 * @return
269 */
270 public static String getEntityMessage(List<FieldError> fieldErrorList, Map<String, Object> map) {
271 if (map.isEmpty()) {
272 return getEntityMessage(fieldErrorList);
273 }
274 Map<String, Object> messageMap = new HashMap<>();
275 fieldErrorList.forEach(data -> {
276 if (data.getCodes() != null && data.getCodes().length > 0) {
277 String field = data.getField();
278 String message = data.getDefaultMessage();
279 if (map.containsKey(field)) {
280 message = (String) map.get(field);
281 }
282 messageMap.put(field, message);
283 }
284 });
285 JSONObject json = new JSONObject(messageMap);
286 return json.toString();
287 }
288
289 /**
290 * 获取错误提示

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected