zoukankan      html  css  js  c++  java
  • springMvc 中返回字符串 乱码解决

    /**
    	 * produces=MediaType.APPLICATION_JSON_VALUE+";charset=utf-8"  乱码解决
    	 * @param callback
    	 * @return
    	 */
    	@RequestMapping(value="/itemcat/list", produces=MediaType.APPLICATION_JSON_VALUE+";charset=utf-8")
    	@ResponseBody
    	public String getItemCatList(String callback) {
    		CatResult itemCatList = itemCatService.getItemCatList();
    		String json = JsonUtils.objectToJson(itemCatList);
    		String result = callback+"("+json+");";
    		return result;
    	}
    

     方法二:返回object,使用工具类自动添加回调函数

    @RequestMapping("/itemcat/list2")
    	@ResponseBody
    	public Object getItemCatList2(String callback) {
    		CatResult itemCatList = itemCatService.getItemCatList();
    		//使用 MappingJacksonValue 工具类来添加回调函数自动拼装字符串
    		MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(itemCatList);
    		mappingJacksonValue.setJsonpFunction(callback);
    		return mappingJacksonValue;
    	}
    

      

  • 相关阅读:
    Sliding Window
    方程的解数
    [JLOI2011]不重复数字
    A−B数对
    2007年分区联赛提高组之一 统计数字
    Magic Squares 魔板 (BFS+HASH)
    集合(normal)
    Place the Robots
    LoadRunner监控Linux
    CentOS6.3(64位)下安装Oracle11gR2(64)服务器
  • 原文地址:https://www.cnblogs.com/redhat0019/p/10065516.html
Copyright © 2011-2022 走看看