springboot 통합 ueditor 가 밟 은 구덩이
9299 단어 springboot통합ueditor
며칠 간 의 밤낮 을 거 쳐 주말 휴식 시간 까지 희생 하고 자 료 를 뒤 적 이기 시작 했다.
잔말 말고 튜 토리 얼 을 시작 하 세 요.
첫 번 째 단계:
그의 소스 코드 를 다운로드 하 다.
두 번 째 단계:
압축 해제 다운로드 원본 코드(다운로드 가 느 릴 수 있 습 니 다.벽 을 넘 어 다운로드 해 야 할 것 같 습 니 다)
그리고 프로젝트 를 열 어 프로젝트 의 resources/static 에 원본 코드 를 끌 어 옵 니 다.
세 번 째 단계
포인트 입 니 다.
springboot 은 현재 기본적으로 jsp 를 지원 하지 않 기 때문에 jap 의 controller.jsp 가 실 행 된 후 springboot 는 경 로 를 찾 지 못 하면 부 텍스트 가 존재 합 니 다.그림 이나 동 영상 을 올 리 는 곳 은 표 시 됩 니 다(백 엔 드 설정 되 지 않 음)
다음은 소스 코드 에 있 는 jsp 아래 에 4 개의 jar 가방 이 있어 야 합 니 다.프로젝트 에 복사 한 다음 에 add 를 넣 거나 maven 주 소 를 찾 아 도 됩 니 다.하지만 시간 을 낭비 하 는 것 을 권장 하지 않 습 니 다.
네 번 째 단계:주 소 를 가 져 올 수 없 기 때문에 우 리 는 스스로 controller 를 써 서 매 핑 을 합 니 다.여러분 이 게 을 러 질 까 봐 제 가 제공 하 는 것 을 복사 합 니 다.
@RestController
@RequestMapping("/Test")
public class UeTestController {
/**
* : config.json, config.json , ,
* @return
*/
@RequestMapping(value = "/ueditor/config",method = RequestMethod.GET)
@ResponseBody
public String uploadConfig(String action,String noCache) {
// :imageActionName ActionName : :multipleCarouselFiles
//imageUrlPrefix: 【 , 】
System.out.println(" config====================");
System.out.println("action="+action+" callback="+noCache);
String s = "{
" +
" \"basePath\": \"C:/\",
" +
" \"imageActionName\": \"/Test/multipleCarouselFiles\",
" +
" \"imageFieldName\": \"upfile\",
" +
" \"imageMaxSize\": 2048000,
" +
" \"imageAllowFiles\": [\".png\", \".jpg\", \".jpeg\", \".gif\", \".bmp\"],
" +
" \"imageCompressEnable\": true,
" +
" \"imageCompressBorder\": 1600,
" +
" \"imageInsertAlign\": \"none\",
" +
" \"imageUrlPrefix\": \"http://localhost:8082/images/upload\",
" +
" \"imagePathFormat\": \"/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}\", /* */
" +
" \"videoActionName\": \"/Test/multipleCarouselFiles\", /* action */
" +
" \"videoFieldName\": \"upfile\", /* */
" +
" \"videoPathFormat\": \"/ueditor/jsp/upload/video/{yyyy}{mm}{dd}/{time}{rand:6}\", /* , */
" +
" \"videoUrlPrefix\": \"http://localhost:8082/images/upload\", /* */
" +
" \"videoMaxSize\": 102400000, /* , B, 100MB */
" +
" \"videoAllowFiles\": [
" +
" \".flv\", \".swf\", \".mkv\", \".avi\", \".rm\", \".rmvb\", \".mpeg\", \".mpg\",
" +
" \".ogg\", \".ogv\", \".mov\", \".wmv\", \".mp4\", \".webm\", \".mp3\", \".wav\", \".mid\"]/* */ }";
return s;
}
/**
* Ueditor
* , ,imgPath ,
* @param file
* @return
*/
@RequestMapping(value = "/multipleCarouselFiles",method = RequestMethod.POST)
@ResponseBody
public String uploadimage(@RequestParam("upfile") MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
//
String Scheme =request.getScheme();
//
String ServerName= request.getServerName();
//
int Port= request.getServerPort();
String url=Scheme+"://"+ServerName+":"+Port;
Results results=new Results();
//
if (file.isEmpty()) {
return " ";
}
try {
//1、 jar
File path = new File(ResourceUtils.getURL("classpath:").getPath());
if(!path.exists()){
path = new File("");
}
System.out.println(" jar path:"+path.getAbsolutePath());
//2、 /static/images/upload/, :
File upload = new File(path.getAbsolutePath(),"static/images/upload/New_img/");
if(!upload.exists()){
upload.mkdirs();
}
System.out.println(" /static/images/upload/ ---upload url:"+upload.getAbsolutePath());
// MultipartFile
System.out.println("[ ContentType] -:"+file.getContentType());
System.out.println("[ Name] -:"+file.getName());
System.out.println("[ OriginalFileName] -:"+file.getOriginalFilename());
System.out.println("[ ] -:"+file.getSize());
System.out.println(this.getClass().getName()+" :"+upload);
//
String uploadPath=upload+"\\";
File dir = new File(uploadPath + file.getOriginalFilename());
//
file.transferTo(dir);
// , :{ }/target/static/images/upload/
// jar , :{ jar }/static/images/upload/
results.setMessage(" ");
} catch (Exception e) {
e.printStackTrace();
results.setMessage(" ");
}
String result = "";
if(!file.isEmpty()) {
String originalFileName = file.getOriginalFilename();
//
// String imgPath = fileUtil.uploadImg(file);
String imgPath = "/New_img/"+originalFileName;
result = "{
" +
" \"state\": \"SUCCESS\",
" +
" \"url\": \"" + imgPath + "\",
" +
" \"title\": \"" + originalFileName + "\",
" +
" \"original\": \"" + originalFileName + "\"
" +
"}";
}
return result;
}
}
다음은 형 이 보 내 준 파일 업로드 용 Results 를 첨부 하 겠 습 니 다.
import com.fasterxml.jackson.annotation.JsonProperty;
/*
* ueditor
* */
public class Results {
private Object Data;
private String Message;
private boolean Status;
@Override
public String toString() {
return "Results{" +
"Data=" + Data +
", Message='" + Message + '\'' +
", Status=" + Status +
'}';
}
@JsonProperty("Data")
public Object getData() {
return Data;
}
public void setData(Object data) {
Data = data;
}
@JsonProperty("Message")
public String getMessage() {
return Message;
}
public void setMessage(String message) {
Message = message;
}
@JsonProperty("Status")
public boolean isStatus() {
return Status;
}
public void setStatus(boolean status) {
Status = status;
}
}
다음은 ueditor 에서 가장 중요 한 맵 주소 위치(ueditor.config.js)를 수정 해 야 합 니 다.즉,그 가 왜 당신 이 쓴 testcontroller 를 불 러 올 수 있 습 니까?바로 이곳 이 역할 을 합 니 다(부도).만약 당신 이 위 에서 나 와 경 로 를 계속 한다 면,나의 주 소 를 직접 복사 할 수 있 습 니 다.
이 때 프로젝트 를 실행 하면 자신 이 쓴 controller 에 들 어 갑 니 다.
위 에 사실 나 는 한 걸음 한 걸음 다 썼 는데,사실은 내 가 하 는 과정 에서 또 만 났 다.
(그림 은 내 가 찾 았 지만 문 제 는 똑 같 았 다)구체 적 으로 어떤 이 유 는 사진 업로드 경 로 를 설정 하지 않 았 기 때 문 입 니까?
이 쯤 되면 부 텍스트 를 도입 한 곳 을 말씀 드 리 겠 습 니 다.이 설정 을 해 야 합 니 다.
다른 자 리 는 움 직 이지 않 으 면 됩 니 다.여기까지 상세 하 죠?이것 을 하 는 것 은 정말 머리 가 큽 니 다.다행히 한 형 이 저 를 도와 주 었 습 니 다.감사합니다. 또 무슨 문제 가 있 으 면 메 시 지 를 남 겨 주시 면 됩 니 다.보시 면 돌아 오 겠 습 니 다.
springboot 통합 ueditor 가 밟 은 구 덩이 를 상세 하 게 설명 하 는 이 글 은 여기까지 입 니 다.더 많은 springboot 통합 ueditor 내용 은 저희 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 많은 응원 부 탁 드 리 겠 습 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin Springboot -- 파트 14 사용 사례 REST로 전환하여 POST로 JSON으로 전환前回 前回 前回 記事 の は は で で で で で で を 使っ 使っ 使っ て て て て て リクエスト を を 受け取り 、 reqeustbody で 、 その リクエスト の ボディ ボディ を を 受け取り 、 関数 内部 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.