赞
踩
@GetMapping("/avatar") public void avatar(String userId, Integer avatarType, HttpServletResponse response) throws IOException { if (StringUtils.isBlank(userId)) { throw new RuntimeException("userId不能为空", null); } if (null == avatarType) { avatarType = 1; } ResultResponse<byte[]> avatar = xxxxxService.avatar(userId, avatarType); byte[] data = avatar.getData(); ServletOutputStream out = response.getOutputStream(); out.write(data); out.flush(); }
访问地址:
http://localhost:8080/api/v1/user/avatar?userId=xxx&avatarType=1
byte[] 和String 互相转换
上面的byte[] data 如果转换成String存储,需要用字符集编码ISO-8859-1
不能使用utf-8
例如:
String str = new String(data,"ISO-8859-1");
byte[] data = str.getBytes("ISO-8859-1");
只有这样才能完整转换
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。