springmvc:Failed to convert value of type

环境:springmvc + ajax

前端代码:

<script type="text/javascript">
				var menu = {id:1,name:"首页"};
				$.getJSON("/site/menu/queryMenuPage", {
					menu :$.toJSON(menu),
					pageNum : 1,
					pageSize : 5
				}, function(data) {
					alert(data);
				});
			</script>

控制器代码:

@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping(value="/queryMenuPage")
	public @ResponseBody Page<Menu> queryMenuPage(@RequestParam Menu menu,Integer pageNum,Integer pageSize){
		com.github.pagehelper.Page<Menu> _page = PageHelper.startPage(pageNum, pageSize, true);
		List<Menu> menuList = menuService.queryMenuList(null);
		try {
			System.err.println("pageSize:"+JsonUtil.bean2JsonStr(pageSize));
			System.err.println("pageNum:"+JsonUtil.bean2JsonStr(pageNum));
			System.err.println("menu:"+JsonUtil.bean2JsonStr(menu));
			System.err.println("_page:"+JsonUtil.bean2JsonStr(_page));
			System.err.println("menuList:"+JsonUtil.bean2JsonStr(menuList));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new Page(_page,menuList);
	}

报错:

message Failed to convert value of type 'java.lang.String' to required type 'com.join.stump.site.domain.Menu'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.join.stump.site.domain.Menu]: no matching editors or conversion strategy found

解决办法:

前端传值一律通过基本类型和String传递,在控制层后,自己使用jackson工具将String转换成自己需要的对象。
 

你可能感兴趣的:(Ajax,springMVC,error,convert)