문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
|
wiki:egovframe:ckeditor5 [2023/03/02 11:59] sgjang |
— (현재) | ||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| - | ====== Ckeditor5 ====== | ||
| - | <WRAP left notice 80%> | ||
| - | * description : Ckediotr5 관련 내용 기술 | ||
| - | * author | ||
| - | * email : sgjang@repia.com | ||
| - | * lastupdate | ||
| - | </ | ||
| - | <WRAP clear/> | ||
| - | ===== 적용 방법 ===== | ||
| - | * CKEditor5는 5가지의 형태가 있지만 Classic editor와 Document editor 2가지의 사용 방법이 다릅니다. | ||
| - | * 사용할 editor를 선택하고 그 후에 적용할 Ckeditor5 CDN Script를 head 태그 안에 삽입 | ||
| - | * 또는 [[https:// | ||
| - | |||
| - | < | ||
| - | <script src=" | ||
| - | </ | ||
| - | |||
| - | === Classic editor 적용 예시 === | ||
| - | * editor는 div 또는 textarea 사용 | ||
| - | |||
| - | < | ||
| - | < | ||
| - | <html lang=" | ||
| - | < | ||
| - | <meta charset=" | ||
| - | < | ||
| - | <script src=" | ||
| - | </ | ||
| - | < | ||
| - | < | ||
| - | <div id=" | ||
| - | < | ||
| - | </ | ||
| - | < | ||
| - | ClassicEditor | ||
| - | .create( document.querySelector( '# | ||
| - | .catch( error => { | ||
| - | console.error( error ); | ||
| - | } ); | ||
| - | </ | ||
| - | </ | ||
| - | </ | ||
| - | </ | ||
| - | |||
| - | === Document editor 적용 예시 === | ||
| - | * toolbar 부분과 editor 부분이 나뉨 | ||
| - | * editor와 toolbar 부분은 div 사용 | ||
| - | |||
| - | |||
| - | < | ||
| - | < | ||
| - | <html lang=" | ||
| - | < | ||
| - | <meta charset=" | ||
| - | < | ||
| - | <script src=" | ||
| - | </ | ||
| - | < | ||
| - | < | ||
| - | | ||
| - | <!-- editor의 toolbar container--> | ||
| - | <div id=" | ||
| - | |||
| - | <!-- editor 부분--> | ||
| - | <div id=" | ||
| - | < | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | DecoupledEditor | ||
| - | .create( document.querySelector( '# | ||
| - | .then( editor => { | ||
| - | const toolbarContainer = document.querySelector( '# | ||
| - | |||
| - | toolbarContainer.appendChild( editor.ui.view.toolbar.element ); | ||
| - | } ) | ||
| - | .catch( error => { | ||
| - | console.error( error ); | ||
| - | } ); | ||
| - | </ | ||
| - | </ | ||
| - | </ | ||
| - | </ | ||
| - | |||
| - | ===== Tip ===== | ||
| - | * get, | ||
| - | * CKEditor5는 getData()와 setData()로 값을 가져오거나 값을 삽입할 수 있다. | ||
| - | * 여기서 주의 사항은 아래를 참고 | ||
| - | * < | ||
| - | < | ||
| - | < | ||
| - | let testEditor; | ||
| - | |||
| - | // 생성 | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | }) | ||
| - | | ||
| - | | ||
| - | }); | ||
| - | | ||
| - | // 값 가져오기 | ||
| - | testEditor.getData(); | ||
| - | | ||
| - | // 값 세팅 | ||
| - | testEditor.setData('< | ||
| - | </ | ||
| - | </ | ||
| - | | ||
| - | |||
| - | |||
| - | |||
| - | ===== 이미지 업로드 ===== | ||
| - | * CKEditor5는 이미지 업로드 다양한 플러그인이 존재하지만 대부분 유료 플러그인이다. | ||
| - | * 그래서 Adapter부분을 새로 만들어야 한다. | ||
| - | |||
| - | === UploadAdapter 예시 === | ||
| - | * [[https:// | ||
| - | * 아래 사이트를 참고 | ||
| - | * [[https:// | ||
| - | * [[https:// | ||
| - | |||
| - | * 주의사항 | ||
| - | * 이미지 및 file의 데이터는 FormData 변경 후 controller에 보내야 함. | ||
| - | |||
| - | === Controller 예시 === | ||
| - | * url로 addObject 하는 이유 | ||
| - | * 이미지가 업로드가 되고 저장 경로가 base64로 인코딩되어 img 태그 안의 src부분에 들어간다. | ||
| - | * editor를 활용하여 등록할 경우 데이터베이스에 p 태그와 img 태그가 함께 저장이 되어 불러올 때 로딩시간이 길어진다. | ||
| - | |||
| - | < | ||
| - | @PostMapping(value = " | ||
| - | public ModelAndView imageUpload (MultipartHttpServletRequest request) throws Exception { | ||
| - | |||
| - | String currContextPath = request.getContextPath(); | ||
| - | ModelAndView mv = new ModelAndView(" | ||
| - | |||
| - | String savePath= null; | ||
| - | String originalImagename= null; | ||
| - | String imageName= null; | ||
| - | String extension= null; | ||
| - | String realPathtoUploads = EgovProperties.getProperty(" | ||
| - | |||
| - | List< | ||
| - | |||
| - | for (MultipartFile mf : imageList) { | ||
| - | if (imageList.get(0).getSize() > 0) { | ||
| - | originalImagename = mf.getOriginalFilename(); | ||
| - | extension = FilenameUtils.getExtension(originalImagename); | ||
| - | imageName = " | ||
| - | savePath = realPathtoUploads +"/" | ||
| - | File imageUpload = new File(savePath); | ||
| - | try { | ||
| - | mf.transferTo(imageUpload); | ||
| - | } catch (IllegalStateException | IOException e) { | ||
| - | e.printStackTrace(); | ||
| - | } | ||
| - | } | ||
| - | } | ||
| - | savePath = " | ||
| - | log.debug(" | ||
| - | mv.addObject(" | ||
| - | return mv; | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | === 이미지 업로드 후 처리 === | ||
| - | * Jenkins로 배포한 경우 | ||
| - | * globals.propertie 안에 저장경로를 다시 설정 해준다. | ||
| - | |||
| - | * < | ||
| - | * APPS Portal의 경우 | ||
| - | * CMD로 해당 서버로 들어가서 | ||
| - | * '/ | ||
| - | * 저장 경로는 '/ | ||
| - | |||
| - | |||
| - | |||
| - | ===== Ref ===== | ||
| - | * [[https:// | ||
| - | * [[https:// | ||
| - | |||
| - | |||
| - | {{tag> | ||