十年網站開發(fā)經驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網站問題一站解決
這篇文章將為大家詳細講解有關使用Springboot怎么對Freemarker進行整合,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
創(chuàng)新互聯建站是專業(yè)的解放網站建設公司,解放接單;提供成都做網站、網站制作、成都外貿網站建設,網頁設計,網站設計,建網站,PHP網站建設等專業(yè)做網站服務;采用PHP框架,可快速的進行解放網站開發(fā)網頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網站,專業(yè)的做網站團隊,希望更多企業(yè)前來合作!1、導入依賴
org.springframework.boot spring-boot-starter-freemarker
@Controller @RequestMapping("/goodItem") public class GoodItemController { @Reference private IGoodsService goodsService; @Autowired private Configuration configuration; @RequestMapping("/createHtml") @ResponseBody public String createHtml(int gid, HttpServletRequest request){ //通過商品id獲取商品詳情信息 Goods goods = goodsService.queryById(gid); String [] images=goods.getGimage().split("\\|"); //通過模板生成商品靜態(tài)頁面 try { //獲取商品詳情的模板對象 Template template = configuration.getTemplate("goodsItem.ftl"); //準備商品數據 Mapmap=new HashMap<>(); map.put("goods",goods); map.put("context",request.getContextPath()); //freemarker頁面沒有分割功能,所以通過后臺將圖片分割后,將圖片數組傳到后臺 map.put("images",images); //生成靜態(tài)頁 //獲得classpath路徑 //靜態(tài)頁面的名稱必須和商品有所關聯,最簡單的方式就是用商品的id作為頁面的名字 String path = this.getClass().getResource("/static/page/").getPath()+goods.getId()+".html";; template.process(map,new FileWriter(path)); } catch (Exception e) { e.printStackTrace(); } return ""; } }
注意:
1、freemarker頁面不能通過
因此可從后臺將根路徑傳到前端,然后通過
2、當page是一個空文件夾的時候,會報錯。這是因為maven項目不會對空文件夾進行打包編譯。
FreeMarker的基本語法
關于使用Springboot怎么對Freemarker進行整合就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。