| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.util.Base64; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | Long showTime = jsonObject.getLong("time"); |
| | | siteNews.setShowTime(new Date(showTime)); |
| | | if(jsonObject.has("img")){ |
| | | siteNews.setImgurl(jsonObject.getString("img")); |
| | | String imgBase = convertBase64ToImage(jsonObject.getString("img"),"/www/wwwroot/dabao/"+newsId+".jpg"); |
| | | siteNews.setImgurl("https://img.jumptalk.net/"+newsId+".jpg"); |
| | | } |
| | | siteNews.setDescription(jsonObject.getString("content")); |
| | | siteNews.setContent(jsonObject.getString("content")); |
| | |
| | | return k; |
| | | } |
| | | |
| | | public static String convertBase64ToImage(String base64Str, String path) { |
| | | byte[] imageBytes = Base64.getDecoder().decode(base64Str); |
| | | try { |
| | | File file = new File(path); |
| | | FileOutputStream fos = new FileOutputStream(file); |
| | | fos.write(imageBytes); |
| | | fos.flush(); |
| | | fos.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return path; |
| | | } |
| | | |
| | | } |