导出,根据自定义顺序和字段导出,想出个方法就是前端传要导出的哪些字段和顺序,到后端查出全部之后按照那个顺序去过滤以及排序,找了半天才有简便的方法 *//** * 指定排除属性过滤器和包含属性过滤器 * 指定排除属性过滤器:转换成JSON字符串时,排除哪些属性 * 指定包含属性过滤器:转换成JSON字符串时,包含哪些属性 *//* String[] excludeProperties = {"country", "city"}; String[] includeProperties = {"id", "username", "mobile"}; PropertyPreFilters filters = new PropertyPreFilters(); PropertyPreFilters.MySimplePropertyPreFilter excludefilter = filters.addFilter(); excludefilter.addExcludes(excludeProperties); PropertyPreFilters.MySimplePropertyPreFilter includefilter = filters.addFilter(); includefilter.addIncludes(includeProperties); *//** * 情况一:默认忽略值为null的属性 *//* jsonUser = JSONObject.toJSONString(user, SerializerFeature.PrettyFormat); System.out.println("情况一:\n" + jsonUser); *//** * 情况二:包含值为null的属性 *//* jsonUser = JSONObject.toJSONString(user, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue); System.out.println("情况二:\n" + jsonUser); *//** * 情况三:默认忽略值为null的属性,但是排除country和city这两个属性 *//* jsonUser = JSONObject.toJSONString(user, excludefilter, SerializerFeature.PrettyFormat); System.out.println("情况三:\n" + jsonUser); *//** * 情况四:包含值为null的属性,但是排除country和city这两个属性 *//* jsonUser = JSONObject.toJSONString(user, excludefilter, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue); System.out.println("情况四:\n" + jsonUser); *//** * 情况五:默认忽略值为null的属性,但是包含id、username和mobile这三个属性 *//* jsonUser = JSONObject.toJSONString(user, includefilter, SerializerFeature.PrettyFormat); System.out.println("情况五:\n" + jsonUser); *//** * 情况六:包含值为null的属性,但是包含id、username和mobile这三个属性 *//* jsonUser = JSONObject.toJSONString(user, includefilter, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue); System.out.println("情况六:\n" + jsonUser);*/
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)