我能对付杰克逊吗 UnrecognizedPropertyException的@RequestBody参数吗?我该如何配置?
我正在做一个 spring MVC 项目,我使用 jackson 作为 json 插件。json 请求中字段名称的任何拼写错误都会导致错误页面,该页面应该是由错误消息组成的 json 字符串。我是 spring 的新手,我认为这个错误处理可以通过一些 spring 配置来完成,但在多次尝试后失败了。有什么帮助吗?
这是我的 mvc 配置:
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver resolver() {
InternalResourceViewResolver bean = new InternalResourceViewResolver();
return bean;
}
@Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
Run Code Online (Sandbox Code Playgroud)
我的控制器:
@RequestMapping(value = "/Login", method = RequestMethod.POST,
consumes="application/json", produces = "application/json")
public @ResponseBody AjaxResponse login(
@RequestBody UserVO user, HttpServletRequest request) {
//do something ...
}
Run Code Online (Sandbox Code Playgroud)
正常请求json是:
{"Username":"123123", …Run Code Online (Sandbox Code Playgroud) 有没有办法创建迭代器来重复列表中的元素某些时间?例如,列出了一个列表:
color = ['r', 'g', 'b']
Run Code Online (Sandbox Code Playgroud)
有没有办法以itertools.repeatlist(color, 7)可以生成以下列表的形式创建迭代器?
color_list = ['r', 'g', 'b', 'r', 'g', 'b', 'r']
Run Code Online (Sandbox Code Playgroud)