CKEditor如何在springboot上使用
时间: 2023-05-31 18:02:06 浏览: 49
要在Spring Boot上使用CKEditor,可以按照以下步骤进行操作:
1. 添加Maven依赖
在pom.xml文件中添加以下依赖:
```xml
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>ckeditor5-build-classic</artifactId>
<version>17.0.0</version>
</dependency>
```
这将从WebJars仓库中下载CKEditor 5的经典构建版本。
2. 在HTML页面中引入CKEditor
在HTML页面中添加以下代码:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CKEditor Example</title>
<!-- 引入CKEditor -->
<script th:src="@{/webjars/ckeditor5-build-classic/ckeditor.js}"></script>
</head>
<body>
<textarea id="editor"></textarea>
<script>
ClassicEditor
.create( document.querySelector( '#editor' ) )
.then( editor => {
console.log( editor );
} )
.catch( error => {
console.error( error );
} );
</script>
</body>
</html>
```
这将在页面上创建一个CKEditor实例,并将其绑定到id为“editor”的textarea元素上。
3. 运行Spring Boot应用程序
在Spring Boot应用程序中运行“mvn spring-boot:run”命令,并访问http://localhost:8080/查看CKEditor示例页面。
注意:如果使用Thymeleaf模板引擎,则应在HTML页面中使用th:src指令引用CKEditor脚本。