我不能让这个工作:
@RequestMapping(value = "/people", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody
List<IPerson> searchPerson(@RequestParam(value = "birthDay", required = false) @DateTimeFormat(pattern="yyyy-MM-dd") Date birthDay) {
Run Code Online (Sandbox Code Playgroud)
随请求:
http://localhost:8080/rest/people?birthDay=2014-05-25
Run Code Online (Sandbox Code Playgroud)
错误总是:
"HTTP状态400 - 客户端发送的请求在语法上不正确".
我找不到任何资源能给我一个明确的答案/指南来理解潜在的问题......有人可以帮助我吗?谢谢!
编辑: 例外是:
Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat java.util.Date for value '2010-10-10'; nested exception is java.lang.IllegalArgumentException
at org.springframework.core.convert.support.ObjectToObjectConverter.convert(ObjectToObjectConverter.java:78)
at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:35)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:168)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:161)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:93)
at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:61)
... 40 more
Caused by: java.lang.IllegalArgumentException
at java.util.Date.parse(Date.java:615)
at java.util.Date.<init>(Date.java:272)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) …Run Code Online (Sandbox Code Playgroud) 我需要编写一个java-class"Fraction".
这个类应该能够理解基本的算术运算,如+, - ,*,/.我找到了许多"分数"类并理解它们,但都使用类似" f1.add(f2); "的方法(f1,f2是Fraction的对象,例如:
f1 = new Fraction(1,5);
f2 = new Fraction(2,5);
Run Code Online (Sandbox Code Playgroud)
我需要的是直接操作,例如整数操作,例如:
**f1 = f1 + f2;**
Run Code Online (Sandbox Code Playgroud)
代替
f1.add(f2);
Run Code Online (Sandbox Code Playgroud) 我寻找一个干净的CDI解决方案,而不是WELD依赖的解决方案,但到目前为止没有...
我需要测试,如果我用@Inject @Any MyInterface的豆获得对象的列表中的每个元素是一个代理,而当真正的我需要得到真正的对象做反省和获取对象的所有属性.
我的WELD实施:
MyInterface interf = obj;
if (isProxy(interf )) {
interf = (Config) ((TargetInstanceProxy)interf ).getTargetInstance();
}
Run Code Online (Sandbox Code Playgroud)
其中isProxy是如此定义的(CDI解决方案?):
public boolean isProxy(Object obj) {
try{
return Class.forName("org.jboss.weld.bean.proxy.ProxyObject").isInstance(obj);
} catch (Exception e) {
LOGGER.error("Unable to check if object is proxy", e);
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
任何建议/指示.在官方文档中我没有提到内省(这里)
然后我想得到bean的所有属性,如下所示:
Arrays.stream(interf.getClass().getDeclaredFields()).forEach(
field -> extractStuff(...)
);
Run Code Online (Sandbox Code Playgroud)
我们使用Wildfly和WELD,但不想将我们绑定到CDI的实现.提前致谢!
编辑: 问题是,更确切地说:您是否知道WELD 已经使用TargetInstanceProxy实施的干净CDI解决方案?如果我需要回到学校或者我理解我在写什么,那就不行了.感谢您花时间帮忙!
java ×3
cdi ×1
class ×1
fractions ×1
jboss-weld ×1
json ×1
methods ×1
rest ×1
spring-mvc ×1
wrapper ×1