package com.stylefeng.guns.modular.system.controller;
|
|
import com.baidu.ueditor.ActionEnter;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.util.ClassUtils;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.*;
|
import java.net.URLDecoder;
|
import java.util.HashMap;
|
import java.util.Map;
|
import java.util.UUID;
|
|
/**
|
* 百度富文本控制器
|
*/
|
@Controller
|
public class UEditorController {
|
|
|
|
@RequestMapping("/config.json")
|
public void ueditorConfig(HttpServletRequest request, HttpServletResponse response){
|
String rootPath = ClassUtils.getDefaultClassLoader().getResource("").getPath() + "static/ueditor1_4_3_3/jsp";
|
String property = System.getProperty("os.name");
|
try {
|
rootPath = URLDecoder.decode(rootPath, "UTF-8");
|
if(property.indexOf("Windows") != -1){
|
rootPath = rootPath.substring(1);
|
}
|
response.setContentType("application/json");
|
PrintWriter out = response.getWriter();
|
String exec = new ActionEnter(request, rootPath).exec();
|
// StringBuilder builder = new StringBuilder();
|
// InputStreamReader reader = new InputStreamReader(new FileInputStream(rootPath), "UTF-8");
|
// BufferedReader bfReader = new BufferedReader(reader);
|
// String tmpContent = null;
|
// while((tmpContent = bfReader.readLine()) != null) {
|
// builder.append(tmpContent);
|
// }
|
// bfReader.close();
|
// String s = builder.toString().replaceAll("/\\*[\\s\\S]*?\\*/", "");
|
|
out.write(exec);
|
out.flush();
|
out.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
|
|
|
@RequestMapping("/ueditor/uploadFileData")
|
@ResponseBody
|
public Map<String,String> uploadFileData(@RequestParam("upfile") MultipartFile upfile, HttpServletRequest request) throws IOException {
|
//文件原名称
|
String fileName = upfile.getOriginalFilename();
|
// 保存文件的新名字
|
String nowName = fileName.substring(upfile.getOriginalFilename().lastIndexOf("."));
|
// String s = uploadUtil.uploadFile(2, "file", upfile);
|
String s = "";
|
//返回结果信息(UEditor官方要求这个json格式)
|
Map<String,String> map = new HashMap<String,String >();
|
//是否上传成功
|
map.put("state", "SUCCESS");
|
//现在文件名称
|
map.put("title", nowName);
|
//文件原名称
|
map.put("original", fileName);
|
//文件类型 .+后缀名
|
map.put("type", fileName.substring(upfile.getOriginalFilename().lastIndexOf(".")));
|
//文件路径
|
map.put("url", s);
|
//文件大小(字节数)
|
map.put("size", upfile.getSize()+"");
|
return map;
|
}
|
|
|
@RequestMapping("/ueditor/uploadImageData")
|
@ResponseBody
|
public Map<String,String> uploadImage(@RequestParam("upfile") MultipartFile upfile, HttpServletRequest request) throws IOException {
|
//文件原名称
|
String fileName = upfile.getOriginalFilename();
|
// 保存文件的新名字
|
String nowName = UUID.randomUUID()+fileName.substring(upfile.getOriginalFilename().lastIndexOf("."));
|
// String s = uploadUtil.uploadFile(1, "img", upfile);
|
String s = "";
|
//返回结果信息(UEditor官方要求这个json格式)
|
Map<String,String> map = new HashMap<String,String >();
|
//是否上传成功
|
map.put("state", "SUCCESS");
|
//现在文件名称
|
map.put("title", nowName);
|
//文件原名称
|
map.put("original", fileName);
|
//文件类型 .+后缀名
|
map.put("type", fileName.substring(upfile.getOriginalFilename().lastIndexOf(".")));
|
//文件路径
|
map.put("url", s);
|
//文件大小(字节数)
|
map.put("size", upfile.getSize()+"");
|
return map;
|
}
|
}
|