Spring MVC 解决乱码的 2 种方法

版权声明:借鉴时注明出处就行 https://blog.csdn.net/weixin_42144379/article/details/85994879

方法一: 在@RequestMapping 中添加 produces="application/json;charset=UTF-8"

案例:

    @RequestMapping(value = "/findJobs",produces="application/json;charset=UTF-8", method = RequestMethod.GET)
    @ResponseBody
    public List<Job> findJobs(HttpServletResponse response, HttpServletRequest request,SouJob zhaopin) {
        System.out.println(zhaopin);
        return service.findJobs(zhaopin);
    }

方法二.在修改配置文件的 <mvc:annotation-driven/> 驱动

把 mvc 的注解驱动改为:

	<!-- 注解驱动 -->
<mvc:annotation-driven>
    <!-- 消息转换器 -->
	  <mvc:message-converters register-defaults="true">
	     <bean class="org.springframework.http.converter.StringHttpMessageConverter">
	       <property name="supportedMediaTypes" value="text/html;charset=UTF-8"/>
	     </bean>
	  </mvc:message-converters>
  </mvc:annotation-driven>

猜你喜欢

转载自blog.csdn.net/weixin_42144379/article/details/85994879