首页 > Web开发 > 详细

ajax返回中文乱码问题

时间:2015-10-08 17:58:20      阅读:320      评论:0      收藏:0      [点我收藏+]

ajax返回值中如果有中文,会出现乱码,解决方案:

@RequestMapping(value="/release", method=RequestMethod.POST)
public @ResponseBody ResponseEntity<String> release(Comment comment, @RequestParam("userId") String userId){
		
	commentService.publish(comment,userId);
	PageModel<LessonCommentVo> pageModel = this.getCommentData(comment.getLessonId());
	String commentHTML = this.getCommentHTML(pageModel);
	HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setContentType(new MediaType("text","html",Charset.forName("UTF-8"))); 
	return new ResponseEntity<String>(commentHTML, responseHeaders, HttpStatus.OK);
}

 返回值类型不能直接使用String ,要使用ResponseEntity<String>包装

ajax返回中文乱码问题

原文:http://www.cnblogs.com/zhoucl/p/4861574.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!