@PostMapping(“/test”)
@ResponseBody </span><span style="color: rgba(0, 0, 255, 1)">public</span><span style="color: rgba(0, 0, 0, 1)"> String test() { InputStream test </span>= getClass().getResourceAsStream("/static/json/test.json"<span style="color: rgba(0, 0, 0, 1)">); Map</span><String, Object> map1 = <span style="color: rgba(0, 0, 255, 1)">new</span> HashMap<String, Object><span style="color: rgba(0, 0, 0, 1)">(); map1.put(</span>"name", "a"<span style="color: rgba(0, 0, 0, 1)">); map1.put(</span>"age", 10<span style="color: rgba(0, 0, 0, 1)">); JSONObject json1 </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JSONObject(map1); Map</span><String, Object> map2 = <span style="color: rgba(0, 0, 255, 1)">new</span> HashMap<String, Object><span style="color: rgba(0, 0, 0, 1)">(); map2.put(</span>"name", 1<span style="color: rgba(0, 0, 0, 1)">); map2.put(</span>"age", "12"<span style="color: rgba(0, 0, 0, 1)">); JSONObject json2 </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JSONObject(map2); Map</span><String, Object> map3 = <span style="color: rgba(0, 0, 255, 1)">new</span> HashMap<String, Object><span style="color: rgba(0, 0, 0, 1)">(); map3.put(</span>"name", "a"<span style="color: rgba(0, 0, 0, 1)">); map3.put(</span>"sex", "0"<span style="color: rgba(0, 0, 0, 1)">); JSONObject json3 </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JSONObject(map3); Map</span><String, Object> map4 = <span style="color: rgba(0, 0, 255, 1)">new</span> HashMap<String, Object><span style="color: rgba(0, 0, 0, 1)">(); map4.put(</span>"name", "a"<span style="color: rgba(0, 0, 0, 1)">); map4.put(</span>"age", 11<span style="color: rgba(0, 0, 0, 1)">); map4.put(</span>"sex", 0<span style="color: rgba(0, 0, 0, 1)">); JSONObject json4 </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JSONObject(map4); Map</span><String, Object> map5 = <span style="color: rgba(0, 0, 255, 1)">new</span> HashMap<String, Object><span style="color: rgba(0, 0, 0, 1)">(); map5.put(</span>"name", "ad"<span style="color: rgba(0, 0, 0, 1)">); map5.put(</span>"age", "12"<span style="color: rgba(0, 0, 0, 1)">); map4.put(</span>"sex", 0<span style="color: rgba(0, 0, 0, 1)">); JSONObject json5 </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JSONObject(map5); JSONObject Schema </span>= <span style="color: rgba(0, 0, 255, 1)">new</span> JSONObject(<span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> JSONTokener(test)); Schema schema </span>=<span style="color: rgba(0, 0, 0, 1)"> SchemaLoader.load(Schema); System.out.println(</span>"—————————data1———————————"<span style="color: rgba(0, 0, 0, 1)">); </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> { schema.validate(json1); System.out.println(</span>"校验成功!"<span style="color: rgba(0, 0, 0, 1)">); } </span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (ValidationException e) { System.out.println(e.getAllMessages()); } System.out.println(</span>"—————————data2———————————"<span style="color: rgba(0, 0, 0, 1)">); </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> { schema.validate(json2); System.out.println(</span>"校验成功!"<span style="color: rgba(0, 0, 0, 1)">); } </span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (ValidationException e) { System.out.println(e.getAllMessages()); } System.out.println(</span>"—————————data3———————————"<span style="color: rgba(0, 0, 0, 1)">); </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> { schema.validate(json3); System.out.println(</span>"校验成功!"<span style="color: rgba(0, 0, 0, 1)">); } </span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (ValidationException e) { System.out.println(e.getAllMessages()); } System.out.println(</span>"—————————data4———————————"<span style="color: rgba(0, 0, 0, 1)">); </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> { schema.validate(json4); System.out.println(</span>"校验成功!"<span style="color: rgba(0, 0, 0, 1)">); } </span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (ValidationException e) { System.out.println(e.getAllMessages()); } System.out.println(</span>"—————————data5———————————"<span style="color: rgba(0, 0, 0, 1)">); </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)"> { schema.validate(json5); System.out.println(</span>"校验成功!"<span style="color: rgba(0, 0, 0, 1)">); } </span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (ValidationException e) { System.out.println(e.getAllMessages()); } </span><span style="color: rgba(0, 0, 255, 1)">return</span> "hello"<span style="color: rgba(0, 0, 0, 1)">;
}
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.bianchenghao6.com/h6javajc/11287.html