日期:2014-05-16 浏览次数:20350 次
@RequestMapping(params = "method=getAllBmForList") @ResponseBody public List<DepartGenInfo> getAllBmForList(HttpServletRequest request, HttpServletResponse response) throws Exception { BmDto dto = bmglService.getAllBm(); return dto.getBmList(); }
public class DepartGenInfo implements java.io.Serializable { private String depid; private String name; private Company company; //getter... //setter... } public class Company { private String comid; private String name; <pre name="code" class="java"> //getter... //setter... }
@RequestMapping(params = "method=getAllBmForList") public void getAllBmForList(HttpServletRequest request, HttpServletResponse response) throws Exception { BmDto dto = bmglService.getAllBm(); ObjectMapper mapper = new ObjectMapper(); SerializationConfig serializationConfig = mapper.getSerializationConfig(); serializationConfig.addMixInAnnotations(DepartGenInfo.class, DepartGenInfoFilter.class); serializationConfig.addMixInAnnotations(Company.class, CompanyFilter.class); mapper.writeValue(response.getOutputStream(),dto.getBmList()); return; }
@JsonIgnoreProperties(value={"name"}) //希望动态过滤掉的属性 public interface DepartGenInfoFilter { }
serializationConfig.addMixInAnnotations();
@XunerJsonFilters(value={@XunerJsonFilter(mixin=DepartGenInfoFilter.class, target=DepartGenInfo.class) ,@XunerJsonFilter(mixin=CompanyFilter.class, target=Company.class)}) @RequestMapping(params = "method=getAllBmForList") @ResponseBody public List getAllBmForList(HttpServletRequest request, HttpServletResponse response) throws Exception { BmDto dto = bmglService.getAllBm(); return dto.getBmList(); }
@Retention(RetentionPolicy.RUNTIME) public @interface XunerJsonFilters { XunerJsonFilter[] value(); } @Retention(RetentionPolicy.RUNTIME) public @interface XunerJsonFilter { Class<?> mixin() default Object.class; Class<?> target() default Object.class; }
public class XunerJsonFilterAdvice { public Object doAround(ProceedingJoinPoint pjp) throws Throwable { MethodSignature msig = (MethodSignature) pjp.getSignature(); XunerJsonFilter annotation = msig.getMethod().getAnnotation( XunerJsonFilter.class); XunerJsonFilters annotations = msig.getMethod().getAnnotation( XunerJsonFilters.class); if (annotation == null && annotations == null) { return pjp.proceed