org.springframework.util.StringUtils#arrayToCommaDelimitedString ( )源码实例Demo

下面列出了org.springframework.util.StringUtils#arrayToCommaDelimitedString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@RequestMapping(value = "/add", method = RequestMethod.POST)
public String processAddNewProductForm(@ModelAttribute("newProduct") Product productToBeAdded, ModelMap map, BindingResult result, HttpServletRequest request) {
	String[] suppressedFields = result.getSuppressedFields();
	
	if (suppressedFields.length > 0) {
		throw new RuntimeException("Attempting to bind disallowed fields: " + StringUtils.arrayToCommaDelimitedString(suppressedFields));
	}
	
	MultipartFile productImage = productToBeAdded.getProductImage();
	String rootDirectory = request.getSession().getServletContext().getRealPath("/");
			
		if (productImage!=null && !productImage.isEmpty()) {
	       try {
	      	productImage.transferTo(new File(rootDirectory+"resources\\images\\"+productToBeAdded.getProductId() + ".png"));
	       } catch (Exception e) {
			throw new RuntimeException("Product Image saving failed", e);
	   }
	   }

	
   	productService.addProduct(productToBeAdded);
	return "redirect:/products";
}
 
@Override
public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) {
	// Create field error with the exceptions's code, e.g. "typeMismatch".
	String field = ex.getPropertyName();
	Assert.state(field != null, "No field in exception");
	String[] codes = bindingResult.resolveMessageCodes(ex.getErrorCode(), field);
	Object[] arguments = getArgumentsForBindError(bindingResult.getObjectName(), field);
	Object rejectedValue = ex.getValue();
	if (ObjectUtils.isArray(rejectedValue)) {
		rejectedValue = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(rejectedValue));
	}
	FieldError error = new FieldError(bindingResult.getObjectName(), field, rejectedValue, true,
			codes, arguments, ex.getLocalizedMessage());
	error.wrap(ex);
	bindingResult.addError(error);
}
 
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String processAddNewProductForm(@ModelAttribute("newProduct") @Valid Product productToBeAdded, BindingResult result, HttpServletRequest request) {
	if(result.hasErrors()) {
		return "addProduct";
	}

	String[] suppressedFields = result.getSuppressedFields();
	
	if (suppressedFields.length > 0) {
		throw new RuntimeException("Attempting to bind disallowed fields: " + StringUtils.arrayToCommaDelimitedString(suppressedFields));
	}
	
	MultipartFile productImage = productToBeAdded.getProductImage();
	String rootDirectory = request.getSession().getServletContext().getRealPath("/");
			
		if (productImage!=null && !productImage.isEmpty()) {
	       try {
	      	productImage.transferTo(new File(rootDirectory+"resources\\images\\"+productToBeAdded.getProductId() + ".png"));
	       } catch (Exception e) {
			throw new RuntimeException("Product Image saving failed", e);
	   }
	   }

	
   	productService.addProduct(productToBeAdded);
	return "redirect:/products";
}
 
@Override
public Object getValue(@Nullable String name) {
	Object value = this.delegate.getValue(name);
	if (ObjectUtils.isArray(value)) {
		value = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(value));
	}
	return value;
}
 
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String processAddNewProductForm(@ModelAttribute("newProduct") @Valid Product productToBeAdded, BindingResult result, HttpServletRequest request) {
	if(result.hasErrors()) {
		return "addProduct";
	}

	String[] suppressedFields = result.getSuppressedFields();
	
	if (suppressedFields.length > 0) {
		throw new RuntimeException("Attempting to bind disallowed fields: " + StringUtils.arrayToCommaDelimitedString(suppressedFields));
	}
	
	MultipartFile productImage = productToBeAdded.getProductImage();
	String rootDirectory = request.getSession().getServletContext().getRealPath("/");
			
		if (productImage!=null && !productImage.isEmpty()) {
	       try {
	      	productImage.transferTo(new File(rootDirectory+"resources\\images\\"+productToBeAdded.getProductId() + ".png"));
	       } catch (Exception e) {
			throw new RuntimeException("Product Image saving failed", e);
	   }
	   }

	
   	productService.addProduct(productToBeAdded);
	return "redirect:/products";
}
 
源代码6 项目: blade-tool   文件: StartEventListener.java
@Async
@Order
@EventListener(WebServerInitializedEvent.class)
public void afterStart(WebServerInitializedEvent event) {
	Environment environment = event.getApplicationContext().getEnvironment();
	String appName = environment.getProperty("spring.application.name").toUpperCase();
	int localPort = event.getWebServer().getPort();
	String profile = StringUtils.arrayToCommaDelimitedString(environment.getActiveProfiles());
	log.info("---[{}]---启动完成,当前使用的端口:[{}],环境变量:[{}]---", appName, localPort, profile);
}
 
源代码7 项目: spring-cloud-cluster   文件: LoggingListener.java
/**
 * Constructs Logger listener with given level.
 *
 * @param level the level string
 */
public LoggingListener(String level) {
	try {
		this.level = Level.valueOf(level.toUpperCase());
	}
	catch (IllegalArgumentException e) {
		throw new IllegalArgumentException("Invalid log level '" + level
				+ "'. The (case-insensitive) supported values are: "
				+ StringUtils.arrayToCommaDelimitedString(Level.values()));
	}
}
 
源代码8 项目: lams   文件: DefaultBindingErrorProcessor.java
@Override
public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) {
	// Create field error with the exceptions's code, e.g. "typeMismatch".
	String field = ex.getPropertyName();
	String[] codes = bindingResult.resolveMessageCodes(ex.getErrorCode(), field);
	Object[] arguments = getArgumentsForBindError(bindingResult.getObjectName(), field);
	Object rejectedValue = ex.getValue();
	if (rejectedValue != null && rejectedValue.getClass().isArray()) {
		rejectedValue = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(rejectedValue));
	}
	bindingResult.addError(new FieldError(
			bindingResult.getObjectName(), field, rejectedValue, true,
			codes, arguments, ex.getLocalizedMessage()));
}
 
源代码9 项目: lams   文件: HierarchicalUriComponents.java
@Override
public Object getValue(String name) {
	Object value = this.delegate.getValue(name);
	if (ObjectUtils.isArray(value)) {
		value = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(value));
	}
	return value;
}
 
源代码10 项目: jdal   文件: ControlBindingErrorProcessor.java
/** 
 * Add a ControlError instead FieldError to hold component that has failed.
 * @param control
 * @param ex
 * @param bindingResult
 */
public void processPropertyAccessException(Object control, PropertyAccessException ex, 
		BindingResult bindingResult ) {
	// Create field error with the exceptions's code, e.g. "typeMismatch".
	String field = ex.getPropertyName();
	String[] codes = bindingResult.resolveMessageCodes(ex.getErrorCode(), field);
	Object[] arguments = getArgumentsForBindError(bindingResult.getObjectName(), field);
	Object rejectedValue = ex.getValue();
	if (rejectedValue != null && rejectedValue.getClass().isArray()) {
		rejectedValue = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(rejectedValue));
	}
	bindingResult.addError(new ControlError(control,
			bindingResult.getObjectName(), field, rejectedValue, true,
			codes, arguments, ex.getLocalizedMessage()));
}
 
源代码11 项目: onetwo   文件: MethodSimpleKey.java
@Override
public String toString() {
	return getClass().getSimpleName() + " [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}
 
@Override
public String toString() {
	return "Packages annotation filter: " +
			StringUtils.arrayToCommaDelimitedString(this.prefixes);
}
 
/**
 * Create a new PortletRequestMethodNotSupportedException.
 * @param supportedMethods the actually supported HTTP methods
 */
public PortletRequestMethodNotSupportedException(String[] supportedMethods) {
	super("Mapped handler only supports client data requests with methods " +
			StringUtils.arrayToCommaDelimitedString(supportedMethods));
	this.supportedMethods = supportedMethods;
}
 
/**
 * Show the configuration of this MessageSource.
 */
@Override
public String toString() {
	return getClass().getName() + ": basenames=[" +
			StringUtils.arrayToCommaDelimitedString(this.basenames) + "]";
}
 
源代码15 项目: java-technology-stack   文件: SimpleKey.java
@Override
public String toString() {
	return getClass().getSimpleName() + " [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}
 
源代码16 项目: spring4-understanding   文件: SimpleKey.java
@Override
public String toString() {
	return getClass().getSimpleName() + " [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}
 
源代码17 项目: lams   文件: MBeanClientInterceptor.java
@Override
public String toString() {
	return this.name + "(" + StringUtils.arrayToCommaDelimitedString(this.parameterTypes) + ")";
}
 
源代码18 项目: lams   文件: TypeConverterDelegate.java
/**
 * Convert the value to the required type (if necessary from a String),
 * using the given property editor.
 * @param oldValue the previous value, if available (may be {@code null})
 * @param newValue the proposed new value
 * @param requiredType the type we must convert to
 * (or {@code null} if not known, for example in case of a collection element)
 * @param editor the PropertyEditor to use
 * @return the new value, possibly the result of type conversion
 * @throws IllegalArgumentException if type conversion failed
 */
private Object doConvertValue(Object oldValue, Object newValue, Class<?> requiredType, PropertyEditor editor) {
	Object convertedValue = newValue;

	if (editor != null && !(convertedValue instanceof String)) {
		// Not a String -> use PropertyEditor's setValue.
		// With standard PropertyEditors, this will return the very same object;
		// we just want to allow special PropertyEditors to override setValue
		// for type conversion from non-String values to the required type.
		try {
			editor.setValue(convertedValue);
			Object newConvertedValue = editor.getValue();
			if (newConvertedValue != convertedValue) {
				convertedValue = newConvertedValue;
				// Reset PropertyEditor: It already did a proper conversion.
				// Don't use it again for a setAsText call.
				editor = null;
			}
		}
		catch (Exception ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("PropertyEditor [" + editor.getClass().getName() + "] does not support setValue call", ex);
			}
			// Swallow and proceed.
		}
	}

	Object returnValue = convertedValue;

	if (requiredType != null && !requiredType.isArray() && convertedValue instanceof String[]) {
		// Convert String array to a comma-separated String.
		// Only applies if no PropertyEditor converted the String array before.
		// The CSV String will be passed into a PropertyEditor's setAsText method, if any.
		if (logger.isTraceEnabled()) {
			logger.trace("Converting String array to comma-delimited String [" + convertedValue + "]");
		}
		convertedValue = StringUtils.arrayToCommaDelimitedString((String[]) convertedValue);
	}

	if (convertedValue instanceof String) {
		if (editor != null) {
			// Use PropertyEditor's setAsText in case of a String value.
			if (logger.isTraceEnabled()) {
				logger.trace("Converting String to [" + requiredType + "] using property editor [" + editor + "]");
			}
			String newTextValue = (String) convertedValue;
			return doConvertTextValue(oldValue, newTextValue, editor);
		}
		else if (String.class == requiredType) {
			returnValue = convertedValue;
		}
	}

	return returnValue;
}
 
源代码19 项目: lams   文件: SimpleKey.java
@Override
public String toString() {
	return getClass().getSimpleName() + " [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}
 
源代码20 项目: jhipster   文件: PrefixedSimpleKey.java
@Override
public String toString() {
    return this.prefix + " " + getClass().getSimpleName() + this.methodName + " [" + StringUtils.arrayToCommaDelimitedString(this.params) + "]";
}