hybris interceptor 应用于对象保存前的数据验证
Posted wahaha603
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hybris interceptor 应用于对象保存前的数据验证相关的知识,希望对你有一定的参考价值。
package com.aaa.backoffice.Interceptors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import com.aaa.core.model.CAHOrderApprovedConfigModel; import com.aaa.core.services.util.dao.CahCommonDao; import de.hybris.platform.servicelayer.interceptor.InterceptorContext; import de.hybris.platform.servicelayer.interceptor.InterceptorException; import de.hybris.platform.servicelayer.interceptor.PrepareInterceptor; import de.hybris.platform.servicelayer.model.ModelService; public class OrderApprovedConfigSavingInterceptor implements PrepareInterceptor<OrderApprovedConfigModel> { private final static Logger LOG = LoggerFactory.getLogger(OrderApprovedConfigSavingInterceptor.class); @Autowired private ModelService modelService; @Autowired private CahCommonDao cahCommonDao; @Override public void onPrepare(OrderApprovedConfigModel config, InterceptorContext arg1) throws InterceptorException { // 内容check checkSavedValues(config); // 保存Code String code = config.getSalesOrg().getUid()+"-"+config.getOrderReason().getCode()+"-"+config.getOrderType(); config.setCode(code); } private void checkSavedValues(OrderApprovedConfigModel config) throws InterceptorException { if (null == config.getSalesOrg()) { throw new InterceptorException("请选择xxx!"); } if (null == config.getOrderReason()) { throw new InterceptorException("请选择xxx!"); } if (null == config.getOrderType()) { throw new InterceptorException("请选择xxx!"); } if (null == config.getRoles()) { throw new InterceptorException("请选择角色!"); } } }
以上是关于hybris interceptor 应用于对象保存前的数据验证的主要内容,如果未能解决你的问题,请参考以下文章
如何在Hybris commerce里创建一个media对象
(十六)ATP应用测试平台——java应用中的过滤器Filter拦截器Interceptor参数解析器ResolverAop切面,你会了吗?