》》》》idea中在项目多模块下springboot 整合freemaker ,进行web浏览显示《《《《

一.新建项目:03-spt-freemaker-demo

   /**
注意:springBoot 要求模板形式的视图层技术的文件必须要放到 src/main/resources 目录下必 须要一个名称为 templates
*/

1.1 配置pom文件

    
    
      org.springframework.boot
      spring-boot-starter-web
    
    
    
      org.springframework.boot
      spring-boot-starter-freemarker
    
    
    
      org.springframework.cloud
      spring-cloud-starter-config
      2.0.1.RELEASE
    

1.2 controller

@Controller
public class UserController {
    /*
     * 处理请求,产生数据
     */
    @RequestMapping("/showUser")
    public String showUser(Model model){
        List list = new ArrayList<>();
        list.add(new Users(1,"张三",20));
        list.add(new Users(2,"李四",22));
        list.add(new Users(3,"王五",24));
        //需要一个Model对象
        model.addAttribute("list", list);
        //跳转视图
        return "userList";
    }
}

1.3  model

package com.ljf.spt.freemaker.model;

/**
 * @ClassName: Users
 * @Description: TODO
 * @Author: liujianfu
 * @Date: 2020/08/06 11:13:05
 * @Version: V1.0
 **/
public class Users {
    private Integer userid;
    private String username;
    private Integer userage;
    public Integer getUserid() {
        return userid;
    }
    public void setUserid(Integer userid) {
        this.userid = userid;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public Integer getUserage() {
        return userage;
    }
    public void setUserage(Integer userage) {
        this.userage = userage;
    }
    public Users(Integer userid, String username, Integer userage) {
        super();
        this.userid = userid;
        this.username = username;
        this.userage = userage;
    }
    public Users() {
        super();
        // TODO Auto-generated constructor stub
    }

}

1.4 启动类

package com.ljf.spt.freemaker;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Hello world!
 *
 */
@SpringBootApplication
public class App 
{
    public static void main( String[] args )
    {    /**
     注意:springBoot 要求模板形式的视图层技术的文件必须要放到 src/main/resources 目录下必 须要一个名称为 templates
    */

        SpringApplication.run(App.class, args);
        System.out.println("整个freemaker启动程序完成!!!");
    }
}

1.5 配置资源文件

在resources文件夹下新建一个templates文件夹,新建一个freemaker文件,内容如下:

》》》》idea中在项目多模块下springboot 整合freemaker ,进行web浏览显示《《《《_第1张图片


	
		用户信息展示用户数据
		
	
	
	
		显示用户信息
		
			
			<#list list as user >
				
ID Name Age
${user.userid} ${user.username} ${user.userage}

1.6  application文件

#服务端端口号,名称
server.servlet.port=8080
spring.profiles.active=prod

1.7 启动类:

package com.ljf.spt.freemaker;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Hello world!
 *
 */
@SpringBootApplication
public class App 
{
    public static void main( String[] args )
    {    /**
     注意:springBoot 要求模板形式的视图层技术的文件必须要放到 src/main/resources 目录下必 须要一个名称为 templates
    */

        SpringApplication.run(App.class, args);
        System.out.println("整个freemaker启动程序完成!!!");
    }
}

1.8启动访问结果

》》》》idea中在项目多模块下springboot 整合freemaker ,进行web浏览显示《《《《_第2张图片

 

你可能感兴趣的:(springboot)