springboot2.0 集成freemark

pom文件



	4.0.0

	com.freemark
	demo
	0.0.1-SNAPSHOT
	jar

	freemarkDemo
	Demo project for Spring Boot

	
		org.springframework.boot
		spring-boot-starter-parent
		2.0.2.RELEASE
		 
	

	
		UTF-8
		UTF-8
		1.8
	

	
		
			org.springframework.boot
			spring-boot-starter-freemarker
		

		
			org.springframework.boot
			spring-boot-starter-web
		

		
		
			org.springframework.boot
			spring-boot-starter-log4j2
		


		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	

	
		
			
				org.springframework.boot
				spring-boot-maven-plugin
			
		
	

controller测试类:

package com.freemark.demo;


import com.freemark.bean.UserInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by  lpw'ASUS on 2018/5/24.
 */
@Controller
@RequestMapping("/student")
public class StudentController {

    @RequestMapping("show")
    public String show(Model model){
        model.addAttribute("str11","hello springboot2.0 -freemark");
        UserInfo userInfo =new UserInfo(12,"李四");
        UserInfo userInfo1 =new UserInfo(18,"王五");

//        model.addAttribute("user",userInfo);
        List list =new ArrayList();
        list.add(userInfo);
        list.add(userInfo1);
        model.addAttribute("list",list);
        return "template";
    }
}

html页面:




    
    freemark template


    

hello freemark

${str11}


<#if user??> 用户为:${user.id}
${user.name} <#else> user不存在

<#list list as user> id为:${user.id}
${user.name}
==============
其中,#if中的??代表是否为空,不为空执行里面内容,else嵌套在if里面。




你可能感兴趣的:(springboot,freemark)