1、@RequestMapping 里的path和value启的作用是一样的,因为value是@interface不加属性说明@RequestMapping(“”)这样默认的赋值的字段,所有@RequestMapping会有个value,path与value不能同时存在
2、spring 方法的入参是不能为接口的,比如说不能直接传递一个List<>进来
@RequestMapping("test2")
@ResponseBody
public Object test2(List<String> params){
return params;
}
像上面这种方法就不可以,因为spring在给入参赋值的时候会经过这个方法
public static <T> T instantiateClass(Class<T> clazz) throws BeanInstantiationException {
Assert.notNull(clazz, "Class must not be null");
if(clazz.isInterface()) {
throw new BeanInstantiationException(clazz, "Specified class is an interface");
} else {
try {
return instantiateClass(clazz.getDeclaredConstructor(new Class[0]), new Object[0]);
} catch (NoSuchMethodException var2) {
throw new BeanInstantiationException(clazz, "No default constructor found", var2);
}
}
}
这里List作为一个接口是会被抛出异常的,所以spring的入参不能含有接口入参,但是做为一个入参对象里含有List却是可以的
@RequestMapping("test3")
@ResponseBody
public Object test3(FrontTestModel testModel){
return testModel;
}
public class FrontTestModel {
public String name;
public Integer id;
public List<String> phones;
}