老师 对接口及乱码问题请教
接口问题
@RequestMapping("upload.do")
@ResponseBody
public ServerResponse upload(HttpSession session, @RequestParam(value = "upload_file", required = false) MultipartFile file, HttpServletRequest request) {
User user = (User)session.getAttribute(Const.CURRENT_USER);
if (user == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "用户未登录, 请登录管理员");
}
if (iUserService.checkAdminRole(user).isSuccess()) {
String path = request.getSession().getServletContext().getRealPath("upload");
String targetFileName = iFileService.upload(file, path);
String url = PropertiesUtil.getProperty("ftp.server.http.prefix") + targetFileName;
Map fileMap = Maps.newHashMap();
fileMap.put("uri", targetFileName);
fileMap.put("url", url);
return ServerResponse.createBySuccess(fileMap);
} else {
return ServerResponse.createByErrorMessage("无权限操作");
}
}
这个问题 应该比较好回答, 跟着老师的课程, 实现admin接口都需要进行权限验证, 如上述代码带参 HttpSession session, 及 HttpServletRequest request, 这些参数是每个接口都会固定传过来的参数吗? 需要这些参数才能进行校验, 那还有其他的默认参数吗?
2 页面乱码
<html>
<meta charset="utf-8">
<body>
<h2>Hello World!</h2>
springmvcä¸ä¼ æ件
<form name="form1" action="/manage/product/upload.do" method="post" enctype="multipart/form-data">
<input type="file" name="upload_file"/>
<input type="submit" value="springmvcä¸ä¼ æ件"/>
</form>
å¯ææ¬å¾çä¸ä¼ æ件
<form name="form2" action="/manage/product/richtext_img_upload.do" method="post" enctype="multipart/form-data">
<input type="file" name="upload_file"/>
<input type="submit" value="å¯ææ¬å¾çä¸ä¼ æ件"/>
</form>
</body>
</html>
已经通过charset="utf-8"来设置字符集, 但是view-source后还是出现了乱码, 请问是什么原因
以上问题请老师解答 谢谢.