切换到jackson #10
12
pom.xml
12
pom.xml
@@ -77,12 +77,12 @@
|
||||
</dependency>
|
||||
|
||||
<!--Json-->
|
||||
<dependency>
|
||||
<groupId>net.sf.json-lib</groupId>
|
||||
<artifactId>json-lib</artifactId>
|
||||
<version>2.4</version>
|
||||
<classifier>jdk15</classifier>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>net.sf.json-lib</groupId>-->
|
||||
<!-- <artifactId>json-lib</artifactId>-->
|
||||
<!-- <version>2.4</version>-->
|
||||
<!-- <classifier>jdk15</classifier>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- 七牛云SDK -->
|
||||
<dependency>
|
||||
|
||||
@@ -5,7 +5,7 @@ import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.service.UserService;
|
||||
import cn.celess.blog.util.JwtUtil;
|
||||
import cn.celess.blog.util.RedisUtil;
|
||||
import net.sf.json.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -81,7 +81,7 @@ public class AuthenticationFilter implements HandlerInterceptor {
|
||||
response.setHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
try {
|
||||
logger.info("鉴权失败,[code:{},msg:{},path:{}]", e.getCode(), e.getMsg(), request.getRequestURI() + "?" + request.getQueryString());
|
||||
response.getWriter().println(JSONObject.fromObject(Response.response(e, null)));
|
||||
response.getWriter().println(new ObjectMapper().writeValueAsString(Response.response(e, null)));
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ import cn.celess.blog.service.QiniuService;
|
||||
import cn.celess.blog.util.HttpUtil;
|
||||
import cn.celess.blog.util.RedisUtil;
|
||||
import cn.celess.blog.util.VeriCodeUtil;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -140,7 +140,8 @@ public class CommonController {
|
||||
*/
|
||||
@PostMapping("/imgUpload")
|
||||
public void upload(HttpServletRequest request, HttpServletResponse response, @RequestParam("editormd-image-file") MultipartFile file) throws IOException {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String uploadTimesStr = redisUtil.get(request.getRemoteAddr() + "-ImgUploadTimes");
|
||||
int uploadTimes = 0;
|
||||
if (uploadTimesStr != null) {
|
||||
@@ -150,11 +151,11 @@ public class CommonController {
|
||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
||||
}
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setContentType("text/html");
|
||||
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
|
||||
if (file.isEmpty()) {
|
||||
jsonObject.put("success", 0);
|
||||
jsonObject.put("message", "上传失败,请选择文件");
|
||||
response.getWriter().println(jsonObject.toString());
|
||||
map.put("success", 0);
|
||||
map.put("message", "上传失败,请选择文件");
|
||||
response.getWriter().println(mapper.writeValueAsString(map));
|
||||
return;
|
||||
}
|
||||
String fileName = file.getOriginalFilename();
|
||||
@@ -162,29 +163,28 @@ public class CommonController {
|
||||
if (".png".equals(mime.toLowerCase()) || ".jpg".equals(mime.toLowerCase()) ||
|
||||
".jpeg".equals(mime.toLowerCase()) || ".bmp".equals(mime.toLowerCase())) {
|
||||
QiniuResponse qiniuResponse = qiniuService.uploadFile(file.getInputStream(), "img_" + System.currentTimeMillis() + mime);
|
||||
jsonObject.put("success", 1);
|
||||
jsonObject.put("message", "上传成功");
|
||||
jsonObject.put("url", "http://cdn.celess.cn/" + qiniuResponse.key);
|
||||
response.getWriter().println(jsonObject.toString());
|
||||
map.put("success", 1);
|
||||
map.put("message", "上传成功");
|
||||
map.put("url", "http://cdn.celess.cn/" + qiniuResponse.key);
|
||||
response.getWriter().println(mapper.writeValueAsString(map));
|
||||
redisUtil.setEx(request.getRemoteAddr() + "-ImgUploadTimes", uploadTimes + 1 + "", 2, TimeUnit.HOURS);
|
||||
return;
|
||||
}
|
||||
jsonObject.put("success", 0);
|
||||
jsonObject.put("message", "上传失败,请上传图片文件");
|
||||
response.getWriter().println(jsonObject.toString());
|
||||
map.put("success", 0);
|
||||
map.put("message", "上传失败,请上传图片文件");
|
||||
response.getWriter().println(mapper.writeValueAsString(map));
|
||||
}
|
||||
|
||||
@GetMapping("/bingPic")
|
||||
public Response bingPic() {
|
||||
|
||||
JSONObject imageObj;
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode root;
|
||||
try {
|
||||
imageObj = JSONObject.fromObject(HttpUtil.get("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN"));
|
||||
root = mapper.readTree(HttpUtil.get("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN"));
|
||||
} catch (IOException e) {
|
||||
return Response.failure(null);
|
||||
}
|
||||
JSONArray jsonArray = imageObj.getJSONArray("images");
|
||||
String imageName = jsonArray.getJSONObject(0).getString("url");
|
||||
return Response.success("https://cn.bing.com" + imageName);
|
||||
JsonNode images = root.get("images").elements().next();
|
||||
return Response.success("https://cn.bing.com" + images.get("url").asText());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,13 @@ package cn.celess.blog.controller;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.model.TagModel;
|
||||
import cn.celess.blog.service.TagService;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
@@ -44,13 +45,13 @@ public class TagController {
|
||||
|
||||
@GetMapping("/tags/nac")
|
||||
public Response getTagNameAndCount() {
|
||||
List<JSONObject> nameAndCount = new ArrayList<>();
|
||||
List<Map<String, Object>> nameAndCount = new ArrayList<>();
|
||||
List<TagModel> all = tagService.findAll();
|
||||
for (TagModel t : all) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("name", t.getName());
|
||||
jsonObject.put("size", t.getArticles().size());
|
||||
nameAndCount.add(jsonObject);
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("name", t.getName());
|
||||
map.put("size", t.getArticles().size());
|
||||
nameAndCount.add(map);
|
||||
}
|
||||
return Response.success(nameAndCount);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Data;
|
||||
import net.sf.json.JSONObject;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -56,9 +57,9 @@ public class Response<T> implements Serializable {
|
||||
return new Response(r.getCode(), r.getMsg(), result);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public String toString() {
|
||||
JSONObject jsonObject = JSONObject.fromObject(this);
|
||||
return jsonObject.toString();
|
||||
return new ObjectMapper().writeValueAsString(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ import cn.celess.blog.service.UserService;
|
||||
import cn.celess.blog.util.*;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -28,9 +26,7 @@ import org.springframework.stereotype.Service;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.beans.Transient;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@@ -312,14 +308,14 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
@Override
|
||||
public Object deleteUser(Integer[] id) {
|
||||
JSONArray status = new JSONArray();
|
||||
List<Map<String, Object>> status = new ArrayList<>();
|
||||
if (id == null || id.length == 0) {
|
||||
return null;
|
||||
}
|
||||
for (Integer integer : id) {
|
||||
String role = userMapper.getRoleById(integer);
|
||||
int deleteResult = 0;
|
||||
JSONObject deleteStatus = new JSONObject();
|
||||
Map<String, Object> deleteStatus = new HashMap<>(3);
|
||||
deleteStatus.put("id", integer);
|
||||
// 管理员账户不可删
|
||||
if ("admin".equals(role)) {
|
||||
|
||||
Reference in New Issue
Block a user