本文整理汇总了Java中org.springframework.web.bind.annotation.ValueConstants类的典型用法代码示例。如果您正苦于以下问题:Java ValueConstants类的具体用法?Java ValueConstants怎么用?Java ValueConstants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValueConstants类属于org.springframework.web.bind.annotation包,在下文中一共展示了ValueConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: contributeMethodArgument
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {
Class<?> paramType = parameter.getNestedParameterType();
if (Map.class.isAssignableFrom(paramType)) {
return;
}
WxApiParam wxApiParam = parameter.getParameterAnnotation(WxApiParam.class);
String name = (wxApiParam == null || StringUtils.isEmpty(wxApiParam.name()) ? parameter.getParameterName() : wxApiParam.name());
WxAppAssert.notNull(name, "请添加编译器的-parameter或者为参数添加注解名称");
if (value == null) {
if (wxApiParam != null) {
if (!wxApiParam.required() || !wxApiParam.defaultValue().equals(ValueConstants.DEFAULT_NONE)) {
return;
}
}
builder.queryParam(name);
} else if (value instanceof Collection) {
for (Object element : (Collection<?>) value) {
element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
builder.queryParam(name, element);
}
} else {
builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
}
}
示例2: updateNamedValueInfo
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
/**
* Create a new NamedValueInfo based on the given NamedValueInfo with sanitized values.
*/
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {
String name = info.name;
if (info.name.length() == 0) {
name = parameter.getParameterName();
Assert.notNull(name, "Name for argument type [" + parameter.getParameterType().getName()
+ "] not available, and parameter name information not found in class file either.");
}
String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
return new NamedValueInfo(name, info.required, defaultValue);
}
示例3: RequestParamResolveBean
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
public RequestParamResolveBean(Class<?> clazz, String paraName, boolean required, String defaultValue, DataConverter dataConverter) {
this.clazz = clazz;
this.paraName = paraName;
this.required = required;
if (ValueConstants.DEFAULT_NONE.equals(defaultValue)) {
this.defaultValue = dataConverter.defaultValue();
} else if (StringUtils.isNotEmpty(defaultValue)) {
this.defaultValue = dataConverter.toObject(defaultValue);
} else {
this.defaultValue = dataConverter.defaultValue();
}
this.dataConverter = dataConverter;
this.isReference = dataConverter instanceof ReferenceDataConverter;
}
示例4: getMethodWxApiRequestPath
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
private String getMethodWxApiRequestPath(Method method) {
WxApiRequest wxApiRequest = AnnotatedElementUtils.findMergedAnnotation(method, WxApiRequest.class);
if (wxApiRequest == null || StringUtils.isEmpty(wxApiRequest.path()) || ValueConstants.DEFAULT_NONE.equals(wxApiRequest.path())) {
// 默认情况下取方法名为变量名,尝试从环境变量中获取信息
return WxContextUtils.resolveStringValue("${" + this.wxApiTypeInfo.getPropertyPrefix() + "." + method.getName() + "}");
}
return wxApiRequest.path();
}
示例5: getFormBody
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
/**
* 要发送文件,使用这种方式,请查看源码:FormHttpMessageConverter
*
* @param wxApiMethodInfo
* @param args
* @return dummy
*/
private Object getFormBody(WxApiMethodInfo wxApiMethodInfo, Object[] args) {
MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
wxApiMethodInfo.getMethodParameters().stream()
.filter(p -> !BeanUtils.isSimpleValueType(p.getParameterType()) || p.hasParameterAnnotation(WxApiForm.class) || p.hasParameterAnnotation(WxApiBody.class))
.forEach(p -> {
// 为空则直接返回不加这个参数
if (args[p.getParameterIndex()] == null) {
return;
}
WxApiForm wxApiForm = p.getParameterAnnotation(WxApiForm.class);
String paramName;
Object param;
if (wxApiForm == null || ValueConstants.DEFAULT_NONE.equals(wxApiForm.value())) {
paramName = p.getParameterName();
} else {
paramName = wxApiForm.value();
}
// 加入Assert
WxAppAssert.notNull(paramName, "请添加编译器的-parameter或者为参数添加注解名称");
if (WxWebUtils.isMutlipart(p.getParameterType())) {
param = getFormResource(args[p.getParameterIndex()]);
} else {
param = args[p.getParameterIndex()];
}
params.add(paramName, param);
});
return params;
}
示例6: updateNamedValueInfo
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
/**
* Create a new NamedValueInfo based on the given NamedValueInfo with sanitized values.
*/
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {
String name = info.name;
if (info.name.length() == 0) {
name = parameter.getParameterName();
if (name == null) {
throw new IllegalArgumentException("Name for argument type [" + parameter.getParameterType().getName() +
"] not available, and parameter name information not found in class file either.");
}
}
String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
return new NamedValueInfo(name, info.required, defaultValue);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:AbstractNamedValueMethodArgumentResolver.java
示例7: updatePathRequestProperties
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
/**
* Update the contextPath, servletPath, and pathInfo of the request.
*/
private void updatePathRequestProperties(MockHttpServletRequest request, String requestUri) {
Assert.isTrue(requestUri.startsWith(this.contextPath),
"requestURI [" + requestUri + "] does not start with contextPath [" + this.contextPath + "]");
request.setContextPath(this.contextPath);
request.setServletPath(this.servletPath);
if (ValueConstants.DEFAULT_NONE.equals(this.pathInfo)) {
Assert.isTrue(requestUri.startsWith(this.contextPath + this.servletPath),
"Invalid servletPath [" + this.servletPath + "] for requestURI [" + requestUri + "]");
String extraPath = requestUri.substring(this.contextPath.length() + this.servletPath.length());
this.pathInfo = (StringUtils.hasText(extraPath)) ? extraPath : null;
}
request.setPathInfo(this.pathInfo);
}
示例8: handleArg
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
protected void handleArg(MultiValueMap<String, Object> values, ApiClientMethodParameter mp, final Object pvalue, boolean flatable){
Object paramValue = pvalue;
if(mp.hasParameterAnnotation(RequestParam.class)){
RequestParam params = mp.getParameterAnnotation(RequestParam.class);
if(pvalue==null && params.required() && (paramValue=params.defaultValue())==ValueConstants.DEFAULT_NONE){
throw new BaseException("parameter["+params.name()+"] must be required : " + mp.getParameterName());
}
}
if(flatable){
beanToMapConvertor.flatObject(mp.getParameterName(), paramValue, (k, v, ctx)->{
if(v instanceof Enum){
Enum<?> e = (Enum<?>)v;
if(e instanceof ValueEnum){
v = ((ValueEnum<?>)e).getValue();
}else{//默认使用name
v = e.name();
}
}
if(ctx!=null){
// System.out.println("ctx.getName():"+ctx.getName());
values.add(ctx.getName(), v.toString());
}else{
values.add(k, v.toString());
}
// values.put(k, v);
});
}else{
values.add(mp.getParameterName(), pvalue);
}
}
示例9: build
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
@Override
public Param build(Method javaMethod, int paramIndex, Annotation paramAnnotation) {
final RequestParam requestParam = (RequestParam) paramAnnotation;
final Param param = new Param()
.withName(discoverParamName(javaMethod, paramIndex, requestParam.value()))
.withStyle(ParamStyle.QUERY)
.withRequired(requestParam.required())
.withType(grammarsDiscoverer.discoverQNameFor(new ClassMetadataFromParam(javaMethod, paramIndex)));
if (!ValueConstants.DEFAULT_NONE.equals(requestParam.defaultValue())) {
param.setDefault(requestParam.defaultValue());
}
return param;
}
示例10: RequestParamNamedValueInfo
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
public RequestParamNamedValueInfo() {
super("", false, ValueConstants.DEFAULT_NONE);
}
示例11: parseDefaultValueAttribute
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
protected String parseDefaultValueAttribute(String value) {
return (ValueConstants.DEFAULT_NONE.equals(value) ? null : value);
}
示例12: RequestParamNamedValueInfo
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
public RequestParamNamedValueInfo() {
super("", false, ValueConstants.DEFAULT_NONE);
}
示例13: getTypeWxApiHost
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
private String getTypeWxApiHost(WxApiRequest wxApiRequest, String defaultHost) {
if (wxApiRequest == null || StringUtils.isEmpty(wxApiRequest.host()) || ValueConstants.DEFAULT_NONE.equals(wxApiRequest.host())) {
return defaultHost;
}
return wxApiRequest.host();
}
示例14: getTypeWxApiPropertyPrefix
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
private String getTypeWxApiPropertyPrefix(WxApiRequest wxApiRequest) {
if (wxApiRequest == null || StringUtils.isEmpty(wxApiRequest.prefix()) || ValueConstants.DEFAULT_NONE.equals(wxApiRequest.prefix())) {
return WX_API_PROPERTY_PREFIX;
}
return wxApiRequest.prefix();
}
示例15: getTypeWxApiRequestPath
import org.springframework.web.bind.annotation.ValueConstants; //导入依赖的package包/类
private String getTypeWxApiRequestPath(WxApiRequest wxApiRequest) {
if (wxApiRequest == null || StringUtils.isEmpty(wxApiRequest.path()) || ValueConstants.DEFAULT_NONE.equals(wxApiRequest.path())) {
return "/";
}
return wxApiRequest.path();
}