开发环境:JDK1.八、Eclipse、Sping Boot + Thymeleaf框架。javascript
一. 构建Sping Boot + Thymeleaf框架的项目(再也不详述):css
1. 新建一个maven project项目:demo。html
2. 修改pom.xml配置,把项目配置为Spring Boot项目;java
3. 配置Thymeleaf:添加Thymeleaf依赖,并在application.properties文件中添加Thymeleaf的配置;jquery
4. 新建DemoController,添加showWord、showIndex方法:web
@RequestMapping(value="/word", method=RequestMethod.GET) public ModelAndView showWord(HttpServletRequest request, Map<String,Object> map){ ModelAndView mv = new ModelAndView("Word"); return mv; } @RequestMapping(value="/index", method=RequestMethod.GET) public ModelAndView showIndex(){ ModelAndView mv = new ModelAndView("Index"); return mv; }
5. 新建Thymeleaf模板页:Word.html、Index.html;sql
6. 运行demo项目,并成功访问:http://localhost:8080/index服务器
2、 集成PageOfficeapp
1. 在pom.xml中添加PageOffice的依赖:框架
<!-- 添加Sqlite依赖(可选:若是不须要使用印章功能的话,不须要添加此依赖)--> <dependency> <groupId>org.xerial</groupId> <artifactId>sqlite-jdbc</artifactId> <version>3.7.2</version> </dependency> <!-- 添加PageOffice依赖(必须) --> <dependency> <groupId>com.zhuozhengsoft</groupId> <artifactId>pageoffice</artifactId> <version>4.3.0.2</version> </dependency>
2. 在application.properties文件中添加两个自定义参数配置,posyspath:指定一个磁盘目录用来存放PageOffice注册成功以后生成的license.lic文件;popassword:设置PageOffice自带印章管理程序的登陆密码;以备给PageOffice的服务器端Servlet程序使用:
######################################################## ###PageOffice ######################################################## posyspath=d:/lic/ popassword=111111
3. 在DemoController中添加代码获取上一步在application.properties中定义的两个参数:
@Value("${posyspath}") private String poSysPath; @Value("${popassword}") private String poPassWord;
4. 在DemoController中添加PageOffice的Servlet的注册代码:
/** * 添加PageOffice的服务器端受权程序Servlet(必须) * @return */ @Bean public ServletRegistrationBean servletRegistrationBean() { com.zhuozhengsoft.pageoffice.poserver.Server poserver = new com.zhuozhengsoft.pageoffice.poserver.Server(); //设置PageOffice注册成功后,license.lic文件存放的目录 poserver.setSysPath(poSysPath); ServletRegistrationBean srb = new ServletRegistrationBean(poserver); srb.addUrlMappings("/poserver.zz"); srb.addUrlMappings("/posetup.exe"); srb.addUrlMappings("/pageoffice.js"); srb.addUrlMappings("/jquery.min.js"); srb.addUrlMappings("/pobstyle.css"); srb.addUrlMappings("/sealsetup.exe"); return srb; // }
5. 在DemoController的showWord方法中添加建立PageOfficeCtrl对象的代码,其中WebOpen方法的第一个参数是office文件在服务器端的磁盘路径,在此demo中暂时使用常量:d:\\test.doc
@RequestMapping(value="/word", method=RequestMethod.GET) public ModelAndView showWord(HttpServletRequest request, Map<String,Object> map){ //--- PageOffice的调用代码 开始 ----- PageOfficeCtrl poCtrl=new PageOfficeCtrl(request); poCtrl.setServerPage("/poserver.zz");//设置受权程序servlet poCtrl.addCustomToolButton("保存","Save",1); //添加自定义按钮 poCtrl.setSaveFilePage("/save");//设置保存的action poCtrl.webOpen("d:\\test.doc",OpenModeType.docAdmin,"张三"); map.put("pageoffice",poCtrl.getHtmlCode("PageOfficeCtrl1")); //--- PageOffice的调用代码 结束 ----- ModelAndView mv = new ModelAndView("Word"); return mv; }
6. 在Word.html中添加PageOffice客户端控件所在的div和js代码:
<div style="width:1000px;height:700px;" th:utext="${pageoffice}"> </div> <script type="text/javascript"> function Save() { document.getElementById("PageOfficeCtrl1").WebSave(); } </script>
7. 在Word.html中添加pageoffice.js和jquery.min.js的引用,并添打开文件的超连接:
<script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript" src="pageoffice.js" id="po_js_main"></script> <a href="javascript:POBrowser.openWindowModeless('/word','width=1200px;height=800px;');">打开文件</a>
8. 在DemoController添加saveFile方法,用来接收PageOffice客户端上传的文件流并保存到服务器指定磁盘目录,在此demo中暂时使用常量:d:\\
@RequestMapping("/save") public void saveFile(HttpServletRequest request, HttpServletResponse response){ FileSaver fs = new FileSaver(request, response); fs.saveToFile("d:\\" + fs.getFileName()); fs.close(); }
9. 在d盘根目录下准备一个test.doc文件(不要用0字节的文件)以备测试;
10. 运行demo项目,访问:http://localhost:8080/index点击“打开文件”的超连接便可在线打开、编辑和保存文件。
3、源码下载
下载地址:http://www.zhuozhengsoft.com/download/PageOffice4.3.0.2ForSpringBoot.zip