java 过滤敏感数据_java spring中的过滤敏感字段浅谈

xmlns:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"

default-lazy-init="true">

代码配置

//日期转换问题

@InitBinder

public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {

DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

binder.registerCustomEditor(Date.class,new CustomDateEditor(format, true));

JsonWriterConfiguratorTemplateRegistry registry = JsonWriterConfiguratorTemplateRegistry.load(request);

registry.registerConfiguratorTemplate(new SojoJsonWriterConfiguratorTemplate()

{

@Override

public SojoConfig getJsonConfig() {

SojoConfig config = new SojoConfig();

//String[] excludes1 = {"allCategories","role","password"};

//String[] excludes2 = {"role","password"};

config.setExcludedProperties(excludes1);

return config;

}

});

}

首先,这里我对bean中的日期进行了格式化,其次要需要过滤一些字段!

注意:this.getHibernateTemplate().find(from User);

这样的语句会把user全部查询出来,并得到一个集合,这时如果使用excludes2,将会把role和password两个字段过滤掉。

第二种情况,this.getHibernateTemplate().find(from User);我也得到一个List,但是我又将这个list保存到一个Map.put("allCategories",list);然后将这个Map返回到控制层,控制层又将这个返回的map放进另外一个Map后返回jsonView,这样使用excludes2,你会发现数据根本没有过滤掉,不要着急!!淡定

因为spring默认只处理一层数据,至于我刚才说的是2层了,所以没有过滤掉,换成excludes1就ok了,原因是第一个allCategories搜索到后找平级的role和password没有找到,但是发现还有一曾,在进入下一层的时候发现ok找到了!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值