1.从
http://ueditor.baidu.com/website/ 下载jsp版本
2.将下载的压缩文件解压,命名为ueditor,复制整个文件夹到项目中
3.在页面上新建一个textarea的标签
<textarea id="container" name="content" style="width: 100%; height: 350px; margin: 0 auto;"></textarea>
4.
<!-- 配置文件 -->
<script type="text/javascript" src="plugins/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="plugins/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
var ue = UE.getEditor('container');
UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
UE.Editor.prototype.getActionUrl = function(action) {
if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') {
return '<%=basePath%>app s/editUpload';
} else if (action == 'uploadvideo') {
return '<%=basePath%>app s/editUpload';
} else {
return this._bkGetActionUrl.call(this, action);
}
}
</script>
5.springmvc后台代码
/**
* 上传图片到OOS
*
* @param file
* @param response
* @throws IOException
*/
@RequestMapping(value = "/editUpload", method = RequestMethod.POST)
@ResponseBody
public UploaderParam editUpload(@RequestParam(value = "upfile", required = false) MultipartFile file) throws IOException {
// 将MultipartFile转换成file
CommonsMultipartFile cf = (CommonsMultipartFile) file;
DiskFileItem fi = (DiskFileItem) cf.getFileItem();
File f = fi.getStoreLocation();
String prefix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);// 后缀名
String key = "upload/" + UuidUtil.get32UUID() + "." + prefix;
try {
OOSUtils.upload2(f, key);
} catch (Exception e) {
// error = e.getMessage();
}
String url = " http://couponworld.oss-cn-shenzhen.aliyuncs.com/" + key;
UploaderParam uploaderParam = new UploaderParam(file.getName(), file.getOriginalFilename(), file.getSize(),
"SUCCESS", file.getContentType(), url, file.getOriginalFilename());
return uploaderParam;
}
uploadParam实体类:
public class UploaderParam {
private String name; // 通过upfile获取
private String originalName; // 通过upfile获取
private Long size; // 通过upfile获取
private String state;// 成功必须为"SUCCESS"
private String type; // 通过upfile获取
private String url; // 图片回显url
private String title;
public UploaderParam() {
super();
}
public UploaderParam(String name, String originalName, Long size, String state, String type, String url,
String title) {
super();
this.name = name;
this.originalName = originalName;
this.size = size;
this.state = state;
this.type = type;
this.url = url;
this.title = title;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getOriginalName() {
return originalName;
}
public void setOriginalName(String originalName) {
this.originalName = originalName;
}
public Long getSize() {
return size;
}
public void setSize(Long size) {
this.size = size;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
2.将下载的压缩文件解压,命名为ueditor,复制整个文件夹到项目中
3.在页面上新建一个textarea的标签
<textarea id="container" name="content" style="width: 100%; height: 350px; margin: 0 auto;"></textarea>
4.
<!-- 配置文件 -->
<script type="text/javascript" src="plugins/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="plugins/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
var ue = UE.getEditor('container');
UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
UE.Editor.prototype.getActionUrl = function(action) {
if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') {
return '<%=basePath%>app s/editUpload';
} else if (action == 'uploadvideo') {
return '<%=basePath%>app s/editUpload';
} else {
return this._bkGetActionUrl.call(this, action);
}
}
</script>
5.springmvc后台代码
/**
* 上传图片到OOS
*
* @param file
* @param response
* @throws IOException
*/
@RequestMapping(value = "/editUpload", method = RequestMethod.POST)
@ResponseBody
public UploaderParam editUpload(@RequestParam(value = "upfile", required = false) MultipartFile file) throws IOException {
// 将MultipartFile转换成file
CommonsMultipartFile cf = (CommonsMultipartFile) file;
DiskFileItem fi = (DiskFileItem) cf.getFileItem();
File f = fi.getStoreLocation();
String prefix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);// 后缀名
String key = "upload/" + UuidUtil.get32UUID() + "." + prefix;
try {
OOSUtils.upload2(f, key);
} catch (Exception e) {
// error = e.getMessage();
}
String url = " http://couponworld.oss-cn-shenzhen.aliyuncs.com/" + key;
UploaderParam uploaderParam = new UploaderParam(file.getName(), file.getOriginalFilename(), file.getSize(),
"SUCCESS", file.getContentType(), url, file.getOriginalFilename());
return uploaderParam;
}
uploadParam实体类:
public class UploaderParam {
private String name; // 通过upfile获取
private String originalName; // 通过upfile获取
private Long size; // 通过upfile获取
private String state;// 成功必须为"SUCCESS"
private String type; // 通过upfile获取
private String url; // 图片回显url
private String title;
public UploaderParam() {
super();
}
public UploaderParam(String name, String originalName, Long size, String state, String type, String url,
String title) {
super();
this.name = name;
this.originalName = originalName;
this.size = size;
this.state = state;
this.type = type;
this.url = url;
this.title = title;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getOriginalName() {
return originalName;
}
public void setOriginalName(String originalName) {
this.originalName = originalName;
}
public Long getSize() {
return size;
}
public void setSize(Long size) {
this.size = size;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}