-
2021-02-13 00:45:31
packageio.renren.modules.company;import java.io.*;importjava.net.URLDecoder;importorg.apache.commons.lang3.StringUtils;importorg.springframework.stereotype.Controller;importorg.springframework.ui.Model;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.ResponseBody;importio.renren.common.utils.JsonResult;
@Controller
@RequestMapping("/company")public classCompanyController {private static String path = CompanyController.class.getClassLoader().getResource("").getPath();
@RequestMapping("/list")publicString list(Model model) {
String string=readWord();if(StringUtils.isNotEmpty(string)) {
model.addAttribute("words", string);
}return "company/company_index";
}/*** 读取文件内容*/
public staticString readWord () {try(
FileInputStream fileInputStream= new FileInputStream(URLDecoder.decode(path, "UTF-8")+"static\\company\\企业介绍.txt");
InputStreamReader inputStreamReader= new InputStreamReader(fileInputStream,"UTF-8");
BufferedReader br= newBufferedReader(inputStreamReader);
){
String line= null;
StringBuffer sBuffer= newStringBuffer();while((line = br.readLine())!=null){
sBuffer.append(line);
}returnsBuffer.toString();
}catch(IOException e) {
e.printStackTrace();throw newRuntimeException(e);
}
}/*** 书写文件内容*/
public static void writeWord(String str) throwsIOException {try(
FileOutputStream fileOutputStream= new FileOutputStream(URLDecoder.decode(path, "UTF-8")+"static\\company\\企业介绍.txt");
OutputStreamWriter outputStreamWriter= new OutputStreamWriter(fileOutputStream,"UTF-8");
PrintWriter out= newPrintWriter(outputStreamWriter);
){
out.write(str);
out.flush();
}catch(IOException e) {
e.printStackTrace();throw newRuntimeException(e);
}
}/*** 保存*/@RequestMapping("/company_save")
@ResponseBodypublicJsonResult companySave(String words) {try{
String content= URLDecoder.decode(URLDecoder.decode(words, "UTF-8"), "UTF-8");
writeWord(content);returnJsonResult.success();
}catch(IOException e) {
e.printStackTrace();returnJsonResult.error();
}
}
}
更多相关内容 -
富文本编辑器导出word
2021-01-14 14:05:49将系统中富文本编辑器内容导出到word文件(包含图片) -
富文本编辑器保存网络图片到本地
2015-08-03 23:35:59简易的富文本编辑器保存网络图片到本地的方法,简单易懂易用 -
百度富文本编辑器ueditor上传图片宽高超范围问题
2018-06-08 18:24:40百度ueditor上传图片超范围后有两个问题,一是编辑器里图片显示不完整,二是添加图片后的网页在显示时也会超出网页不好看。想让它自适应100%,网上的方案能解决第一个问题,基本没有第二个问题的方案,经过多次测试... -
C# .NET MVC UEditor富文本编辑器
2019-04-30 18:39:35实现UEditor富文本编辑器与服务器的文件交互(图片,视频),该实例采用 C#后台开发语言完成! 请在vs2017中打开! -
LayEdit(layer 富文本编辑器使用,包含图片的上传)
2017-10-18 14:11:42layer 富文本编辑器layedit与form的使用,包含form提交时获取富文本的内容以及编辑器的图片上传 -
保存富文本编辑器内容
2019-07-11 20:57:09在这里我使用的是layUI的layedit模块,layUI中的富文本编辑器模块。 第一步我们先将页面搭建好,引入layui.layedit模块和layui.form模块。form模块可用于表单的数据验证和提交 在form表单中建一个textarea <...在这里我使用的是layUI的layedit模块,layUI中的富文本编辑器模块。
第一步我们先将页面搭建好,引入
layui.layedit模块和layui.form模块
。form模块可用于表单的数据验证和提交在form表单中建一个textarea
<textarea class="layui-textarea" id="example" name="example"></textarea>
var form = layui.form;//引入form模块 var layedit = layui.layedit;//引入layedit模块 var laybuild = layedit.build("example",{ tool:['strong' ,'italic','underline','del','|','left','center','right','|','face'] }); //tool 自定义工具栏
使用
layedit.build
方法,将textare替换为layui富文本编辑器。tool为工具栏,不设置则显示默认的工具栏。在form表单的【提交】按钮中设置lay-filter属性,可以对表单数据进行完整性验证。
<button class="layui-btn layui-btn-blue" lay-submit lay-filter="formDemo">提交</button>
之后就可以提交表单了,使用
form.on
方法监听表单提交,若想阻止表单跳转,则可以设置return false
form.on('submit(formDemo)',function(data){ var content = layedit.getContent(laybuild);//通过layedit.getContent()方法获得富文本编辑器内容 $.post("${ctx}/servlet/CliServlet?fun=saveExample",{examplecontent:content},function(e){ if(e){ layer.alert("新增成功!",{offset:'150px',icon:1,title:'提示'}); setTimeout(function(){ window.location.href="${ctx}/jsp/backstage/client-example.jsp"; }, 1500); } }); //阻止表单跳转,我们使用post方法提交给servlet return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。 });
这里要区分的是,
getContent()
方法是获取富文本编辑器内的所有内容,包括字体、对齐、表情和图片等等,而getText()
是获取编辑器纯文本内容。public void saveExample(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{ boolean state=false; String examplecontent = request.getParameter("examplecontent");//接收文本内容 String name = System.currentTimeMillis()+".txt";//获取当前纳秒作为文件名 //获取服务器路径,拼接完整的文件路径 String uploadPath = request.getServletContext().getRealPath("") + File.separator + "example"+File.separator +"content"+File.separator +name; // 如果目录不存在则创建 File uploadDir = new File(uploadPath); if (!uploadDir.exists()) { //File.mkdirs()创建目录 uploadDir.getParentFile().mkdirs();//创建父级文件路径 //File.createNewFile()创建文件 uploadDir.createNewFile(); } //RandomAccessFile(File,'rw') 以”读写“模式打开刚才创建的文件 RandomAccessFile accessFile = new RandomAccessFile(uploadDir, "rw"); accessFile.seek(accessFile.length()); accessFile.write(examplecontent.getBytes());//将内容写入文件中 accessFile.close();//关闭流 ExampleVo example = new ExampleVo(); example.setComposedate(new Date(new Date().getTime())); example.setExamplecontent(name); //最后将保存时间和文件名保存进数据库 state = cliSer.saveExample(example); //返回结果 response.getWriter().write(String.valueOf(state)); }
这里用到了File类的
mkdirs()方法
和createNewFile()
方法,分别是创建目录和创建文件。之后再使用RandomAccessFile
类,对文件进行操作,将文本内容写入文件中。 -
springboot文件上传整合富文本编辑器(不完整)
2019-04-27 16:02:55springboot文件上传整合富文本编辑器 -
asp.net 使用ckeditor5富文本编辑器包含图片上传全部代码
2021-03-11 22:39:12asp.net 使用ckeditor5富文本编辑器包含图片上传全部代码 -
java百度富文本编辑器将图片保存至本地并返显
2018-09-03 23:06:41最近在弄一个新闻发布项目,需要使用到百度富文本编辑器,使用过程中发现很多坑,趟了很久才走出来,不多说了,直接上代码 步骤1,从百度富文本官网下载源码...最近在弄一个新闻发布项目,需要使用到百度富文本编辑器,使用过程中发现很多坑,趟了很久才走出来,不多说了,直接上代码
步骤1,从百度富文本官网下载源码http://ueditor.baidu.com/website/download.html#ueditor
分别下载完整源码和jsp-utf8两个版本源码
步骤2,解压jsp版本,改名为ueditor,并将其复制放入你的项目下面
修改路径,打开jsp/congfig.json文件,入下图进行修改
步骤3,解压源码版本,取出源码
将其复制放入你的项目src下
编写ConfigUtil类,直接上源码
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;public class ConfigUtil {
private static Properties pro;
static{
pro=new Properties();
//默认从类的所在包目录开始查找资源文件
//如果要classpath的根目录开始找,必须加上/
InputStream input = ConfigUtil.class.getClassLoader().getResourceAsStream("properties/config.properties");try {
pro.load(new InputStreamReader(input,
"UTF-8"));
} catch (IOException e) {
e.printStackTrace();
}finally{
if(input!=null){
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static String get(String key){
return pro.getProperty(key);
}public static int getInt(String key){
return Integer.parseInt(pro.getProperty(key));
}
public static void main(String[] args) {
String string = ConfigUtil.get("savepath");
System.out.println(string);
}}
新建config.properties文件,如下图,存放路径可根据你自己的进行配置
修改源码,该工程项目下ctrl+h进行搜索physicalPath,找出三个需要修改的文件
分别如下图进行修改
步骤四,修改tomcat下虚拟路径,conf/
写上存放路径
步骤5,好了前台进行测试
图片显示出来了,并按照我们的要求存放在D盘目录下
最后特别提醒一下,图片显示前缀,需要后台写好,这里就不多说了。
-
富文本编辑器如何保存图片?
2017-06-06 09:13:47发送邮件功能里面存放的图片是图片地址,但因为局域网限制,图片地址无法被外网所识别,被拦截了,要...有没有好的富文本插件,支持图片,文字,视频(最好支持),直接存放到数据库中,发送邮件的时候直接读取数据库? -
富文本编辑器上传到本地可以转二进制存数据库.rar
2020-06-11 10:14:55ueditor修改版,上传图片直接保存到想要的位置,不再是项目中,添加图文内容直接转为二进制存储数据库方法,直接在页面显示,不需要任何处理。 -
TinyMCE富文本编辑器导出为word文档(JS实现)
2020-11-16 16:43:25应用JS实现,TinyMCE富文本编辑器导出为word文档,可解决图片,表格的导出,这是实现的demo,可以直接取用 -
将内容富文本编辑器保存到mysql数据库中的blob字段
2021-07-19 19:13:09I'm trying to save the content from a rich text editor (ckeditor in my case) to my a blob field in my database.This is my ViewModel:public class ArticleViewModel{[Required][Display(Name = "Title")]pub...I'm trying to save the content from a rich text editor (ckeditor in my case) to my a blob field in my database.
This is my ViewModel:
public class ArticleViewModel
{
[Required]
[Display(Name = "Title")]
public string Title { get; set; }
[Required]
[Display(Name = "Description")]
public string Description { get; set; }
[Required]
[Display(Name = "Article Body")]
public string ArticleBody { get; set; }
}
The Article Body is my rich text field like this in my view:
@Html.LabelFor(model => model.ArticleBody)
@Html.TextAreaFor(model => model.ArticleBody, new { placeholder = "Type the content of the article", @class = "ckeditor" })
@Html.ValidationMessageFor(model => model.ArticleBody, string.Empty)
In my Action in my Controller:
[HttpPost]
public ActionResult Create(ArticleViewModel model)
{
if (ModelState.IsValid)
{
try
{
// Get the userID who created the article
User usr = userrepo.FindByUsername(User.Identity.Name);
model.UsernameID = usr.user_id;
repository.AddArticle(model.Title, model.Description, model.ArticleBody);
}
catch (ArgumentException ae)
{
ModelState.AddModelError("", ae.Message);
}
return RedirectToAction("Index");
}
return View(model);
}
But in my repository I get : Cannot convert type 'string' to 'byte[]'
Repository:
public void AddArticle(string Title, string Description, string ArticleBody)
{
item Item = new item()
{
item_title = Title,
item_description = Description,
article_body = ArticleBody,
item_createddate = DateTime.Now,
item_approved = false,
user_id = 1,
district_id = 2,
link = "",
type = GetType("Article")
};
try
{
AddItem(Item);
}
catch (ArgumentException ae)
{
throw ae;
}
catch (Exception)
{
throw new ArgumentException("The authentication provider returned an error. Please verify your entry and try again. " +
"If the problem persists, please contact your system administrator.");
}
Save();
// Immediately persist the User data
}
Can somebody give me a start or help me with this?
解决方案
Should be Repository method format like
Public void AddArticle(string title, string Description, string ArticleBody)
{
//logic
}
I think your repository method have byte type for any one argument . Check that like my method format .
Edit:
Check your article_body column data type in your database? its should me Nvarchar(Max) .
-
java阿里云oss整合ueditor富文本编辑器编译源码
2018-10-27 16:37:20ossEndPoint ueditor显示图片的访问域名 ossCliendEndPoint 阿里云文件存储的endpoint,在仓库概览里面可以看到 useCDN true/false是否启用cdn加速 cdnEndPoint cdn加速域名配置 useLocalStorager 是否启用本地存储 ... -
百度富文本编辑器
2014-12-20 15:32:45在很多后台发布消息的时候,总会用到富文本编辑器,这一款就是一款很好用的富文本编辑器! -
手把手教你百度富文本编辑器的相关配置包括图片上传(for jsp)
2021-04-03 08:11:32看到了很多文本编辑器,最后还是决定选择百度富文本编辑器,功能强大,接地气,蛮好看的。恩,于是去下载百度富文本编辑器吧,http://ueditor.baidu.com/website/download.html。我下载的是1.4.3jsp版(utf-8)。看看... -
百度富文本编辑器ueditor1.4.3 JSP版本案例(上传图片)
2016-10-13 18:26:57ueditor1.4.3 富文本插件完美使用,搭建后可以直接上传图片以及多图片上传回显。主要的配置在config.json。可以查看官网ip,一般人出问题都是在config.json,或者不知道案例文件该怎么放,放哪里。 -
富文本编辑器froalaEditor(全面)附教程
2018-10-31 20:50:38全面的froalaEditor插件,集成了第三方插件 使用方法:https://blog.csdn.net/lianzhang861/article/details/83590084 -
富文本编辑器上传图片的功能
2022-03-28 09:51:50今天,我们来讲一下富文本编辑器上传图片功能的操作。首先,在这里需要引入一个js插件 (config.js),在插件里面写下配置图片上传的路径。 接下来,既然要实现上传图片的功能,那我们就需要一个东西是用来接收... -
使用wangEditor富文本编辑器上传图片和文字
2019-09-06 16:05:51现在在web端的输入框需要直接复制图片进去,于是就用上了富文本编辑器。 正文 在研究了多个富文本编辑器后,基于免费、好用、简洁的原则(主要是基于免费),最终选择使用wangEditor。 使用场景 从Word中复制图片、... -
Django 的 admin后台使用富文本编辑器,保存数据之后,还要在html页面展示
2022-03-05 13:42:02目录admin后台使用富文本编辑器 CKEditor实现的效果CKEditor的安装在setting.py中的下面几个配置关于CKEditor的路由使用前端如何使用 admin后台使用富文本编辑器 CKEditor 实现的效果 CKEditor的安装 pip install ... -
百度Ueditor富文本编辑器基础使用配置以及怎样保存图片到磁盘
2018-05-25 18:19:57现在基本上就可以使用了,但在使用的时候也许会遇到一些问题,比如ueditor文本编辑器的字数限制以及隐藏元素路径,我们可以在配置文件editor.config.js里把这两个的注释打开,不要忘了还有逗号,把10000修改为你想要... -
VueQuillEditor富文本上传图片(非base64)
2020-11-20 15:46:52本篇文章将介绍vue-quill-editor上传图片的那些事,通常来说,我们数据库内都是保存图片路径的,所以上传完图片之后,要回传一个路径给前端,这才是完整的上传步骤。 第一步:上传图片,第二步:保存到服务器,并且... -
vue 富文本编辑器上传图片到服务器并显示到富文本中
2021-12-28 10:57:02问题:因为富文本编辑器上传图片后,是转成base64保存进数据库,图片过大时参数会很长。 前提条件:安装了quill富文本编辑器。npm install quill@1.3.6 1,安装好后在页面直接引入quill import Quill from "quill"; ... -
百度富文本编辑器 UEditor 1.4.3 自定义图片保存路径
2018-05-31 10:29:59百度UEditor图片文件改变默认保存到项目根路径,自定义上传路径或远程服务器:http://blog.csdn.net/slyn_2004/article/details/538685471. js实例化编辑器://实例化编辑器 var ue = UE.getEditor('notice-... -
哪位大神知道富文本编辑器内容(带图片)导出为word有什么好的解决方案吗。
2018-12-21 14:54:55RT,我使用uEditor对获取的freemarker内容进行编辑,然后将内容导出到word文件,但是如果加入图片导出后展示不了,请问有大神知道有什么好的解决方案么? 当前能实现的效果如下: ... -
summernote富文本编辑器保存复制 img 图片
2019-04-02 14:38:45//富文本监听事件 页面js监听富文本copy事件,正则表达式解析img标签获取图片路径 var imgReg = " /<img.*?(?:>|\\/>)/gi"; var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; var reg = "[a-zA-z]+://[^\s]*... -
基于bootstrap的富文本编辑器summernote,重写图片上传并添加进度条
2020-12-09 20:38:12据我了解,这是一款基于bootstrap的富文本编辑器,比较喜欢的它的样式风格和图片上传的功能。 问题1: 它默认的图片上传,是把图片转成base64编码并提交给后端。这显然不是我们想要的,我们希望图片以文件形式提交... -
将百度富文本编辑器(ueditor)中的内容转化为word文档格式
2021-12-09 07:46:16需求:根据富文本中的内容生成对应的word文档进行预览和下载功能。 实现: 采用 POIFSFileSystem 类相关实现,能够准确的将文字、格式相关内容转换成功,但是对于在线的网络图片,无法离线浏览或打开。因此最后采用...