kindeditor的简单尝试 maven项目

刚刚毕业,在工作上遇到了很多问题。这里把我尝试kindeditor编辑器的过程和大家分享一下,希望和我一样的新人可以有所收获,也希望大牛们多多指点


kindeditor官网http://kindeditor.net/


下载并解压,保留自己需要的部分,我用的是jsp


将文件夹复制到项目里


kindeditor/jsp中的file_manager_json.jsp中

//根目录路径,可以指定绝对路径,比如 /var/www/attached/
String rootPath = pageContext.getServletContext().getRealPath("/") + "/static/kindeditor/attached/";
//根目录URL,可以指定绝对路径,比如 http://www.yoursite.com/attached/
String rootUrl  = request.getContextPath() + "/static/kindeditor/attached/";
upload_json.jsp中
//文件保存目录路径
String savePath = pageContext.getServletContext().getRealPath("/") + "/static/attached/";

//文件保存目录URL
String saveUrl  = request.getContextPath() + "/static/attached/";



在相应的jsp引入js和css


然后是

	<script>
		KindEditor.ready(function(K) {
			var editor1 = K.create('textarea[name="content"]', {
				cssPath : 'static/kindeditor/plugins/code/prettify.css',
				uploadJson : 'static/kindeditor/jsp/upload_json.jsp',
				fileManagerJson : 'static/kindeditor/jsp/file_manager_json.jsp',
				allowFileManager : true,
				  allowImageUpload : true, 
			//	imageUploadJson:'static/kindeditor/jsp/upload_json.jsp',
				afterCreate : function() {
					var self = this;
					K.ctrl(document, 13, function() {
						self.sync();
						document.forms['example'].submit();
					});
					K.ctrl(self.edit.doc, 13, function() {
						self.sync();
						document.forms['example'].submit();
					});
				}
			});
			prettyPrint();
		});
	</script>

在想要显示的地方添加

 	<textarea name="content" cols="100" rows="8" style="width:700px;height:200px;visibility:hidden;"></textarea>
基本就是这样。
在实际操作的时候可能出现了一个问题:页面上只有一个多行文本框。那么可能是js和css没引入成功。我建议直接把js和css从项目的相应位置拖到script里面,我的spring-mvc.xml文件中是这样配的 <mvc:resources mapping="/static/**" location="/static/" /> 所以我的js和css路径是从static开始的。
如果要传入数据库只要再加一个content就好了

Controller

@RequestMapping(value="addd")

public String addd(User user,String name,int age,String nice_name,String content){
	
	user.setName(name);
	user.setAge(age);
	user.setNice_name(nice_name);
user.setContent(content);
	usersService.ADD(user);



总结一下,kindeditor很好用,只要路径对了基本就可以成功。


  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值