/** * Check condition node property exist. * * @author wangyi8 * @taskId * @param node the node * @param clz the clz * @param errMsg the err msg */ private void checkConditionNodePropertyExist(ConditionNode node, Class clz, String errMsg) { if (StringUtil.containBrace(node.getValue())) { if (clz == null || ArrayUtil.contains(Config.IGNORE_PARAMETER_TYPES, clz)) { return; } else { List<String> propertyNames = StringUtil.extractBrace(node.getValue()); for (String propertyName : propertyNames) { if (node.getConditionType().equals("in") && (propertyName.equals("item") || propertyName.startsWith("item."))) { // foreach 条件在foreach标签中判断,这里不判断 return; } try { ReflectHelper.haveGetMethod(propertyName, clz); } catch (MapperException e) { e.setDescription( errMsg + String.format(MessageConstant.EXPRESS_MSG, node.toString()) + SymbolConstant.SYMBOL_BLANK + e.getDescription()); e.printException(); } } } } }
/** * 自验证方法 * * @param parameterType 参数类型 * @throws MapperException 异常 */ public boolean validate(Class parameterType) throws MapperException { super.validate(parameterType); MapperException mapperException = null; if (getIfContent() == null) { throw new MapperException( ExceptionCommonConstant.IF_TAG_EXPLAIN_ERROR, String.format(ERROR_MSG, getContents())); } if (!getIfContent().trim().endsWith(SymbolConstant.SYMBOL_COMMA)) { mapperException = new MapperException( ExceptionCommonConstant.INSERT_END_WITH_COMMA, String.format(ERROR_MSG, getIfContent())); } if (!StringUtil.containBrace(getIfContent())) { // 不包含赋值标记,表示赋值为固定值,不做验证 return true; } List<String> propertyNames = StringUtil.extractBrace(getIfContent()); String propertyName = propertyNames.get(0); if (propertyName.contains(SqlHelperConstant.JDBC_TYPE_TAG)) { propertyName = propertyName.substring(0, propertyName.indexOf(SqlHelperConstant.JDBC_TYPE_TAG)); } boolean result = ReflectHelper.haveGetMethod(propertyName, parameterType); if (!result) { if (mapperException != null) { mapperException.appendMessage(ExceptionCommonConstant.COLUMN_NOT_EXIST); } else { mapperException = new MapperException( ExceptionCommonConstant.COLUMN_NOT_EXIST, String.format(ERROR_MSG, getIfContent())); } } if (mapperException != null) { throw mapperException; } else { return true; } }