zoukankan      html  css  js  c++  java
  • Springboot集成velocity

    1.加入maven包

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
      </parent>
    

    2.velocity配置

    spring.velocity.cache= false
    spring.velocity.charset=UTF-8
    spring.velocity.check-template-location=true
    spring.velocity.content-type=text/html  #模板文件的内容类型
    spring.velocity.enabled=true
    spring.velocity.resource-loader-path=/templates   #模板文件所在的位置
    spring.velocity.prefix=/templates/   
    spring.velocity.suffix=.vm  #文件名后缀
    

    3.测试页面 index.vm

    <html>
    <body>
    亲爱的${toUserName},你好!
    
        ${message}
    
    祝:开心!
        ${fromUserName}55
        ${time}
    
    </body>
    </html>
    

    4.后台数据接口

    @Controller
    @SpringBootApplication
    public class DemoApplication {
        @RequestMapping("/")
        public String velocityTest(Map map){
            map.put("message", "这是测试的内容。。。");
            map.put("toUserName", "张三1");
            map.put("fromUserName", "老许");
            return "index";
        }
    

    5.springboot启动器

    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class DemoApplicationTests {
    
        @Test
        public void contextLoads() {
        }
    
        @Autowired
        VelocityEngine velocityEngine;
    
        @Test
        public void velocityTest(){
            Map<String, Object> model = new HashMap<String, Object>();
            model.put("message", "这是测试的内容。。。");
            model.put("toUserName", "张三");
            model.put("fromUserName", "老许");
            System.out.println(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/templates/index.vm", "UTF-8", model));
        }
    }
    

      

     

     

     

  • 相关阅读:
    转载文章:用.NET开发MSN聊天机器人 MSN聊天机器人开发揭秘
    ppc全屏程序(转)
    表设计中遇到的多对多的关系解决方案 (zt)
    using ZedGraph
    DataTable.Select(expression)
    你认识它吗?什么是QR码?
    分享《Windows Mobile平台应用与开发》源代码
    收藏信息
    六世喇嘛仓央嘉措诗集
    使用Axis开发Web Service程序
  • 原文地址:https://www.cnblogs.com/cainame/p/11350072.html
Copyright © 2011-2022 走看看