JAVA SprimgMVC JSON returns Chinese question mark

problem description

controller of the request

@ControllerAdvice
@ResponseBody
public class ControllerException {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @ExceptionHandler(BindException.class)
    public String bindException(Exception e) {
        List<ObjectError> eList = ((BindException) e).getBindingResult().getAllErrors();
        String errStr = "";
        for(int i=0; i< eList.size(); iPP) {
            errStr += ((FieldError) eList.get(i)).getField() + " " + eList.get(i).getDefaultMessage() + " ";
        }
        return resultError(e, CodeEnum.CODE_1402, errStr);
    }

    
    
    /**
     * 
     * @param e 
     * @param c 
     * @return
     */
    private String resultError(Exception e, CodeEnum c) {
        logger.warn(e.getMessage());
        logger.warn(c.getMessage());
        return JsonUtil.formatJSON(c, e.getMessage());
    }

}

related codes

in addition, I added -Dfile.encoding=utf-8

to the startup of tomcat.

what result do you expect? What is the error message actually seen?

when an exception occurs, the request to the controller object verification fails to return. What else do you need to configure so that the global return of json Chinese will not be a problem?

Nov.25,2021

add a produces parameter to @ RequestMapping:
produces = "application/json; charset=UTF-8"

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e58eda-44224.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e58eda-44224.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?