zoukankan      html  css  js  c++  java
  • spring data jpa 页面展示 模板技术 freemarker

    添加依赖

    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-freemarker</artifactId>
            </dependency>

    创建模板文件

      ---保存位置resources/templates 目录下 文件后缀名.ftl

    <html>
        <head>
            <title>spring boot</title>
        </head>
        <body>
            <table border="1px">
                <thead>
                <tr>
                    <th>id</th>
                    <th>用户名</th>
                    <th>密码</th>
                    <th>姓名</th>
                </tr>
                </thead>
                <tbody>
                    <#list userList as user>
                    <tr>
                        <td>${user.id}</td>
                        <td>${user.username}</td>
                        <td>${user.password}</td>
                        <td>${user.name}</td>
                    </tr>
                    </#list>
                </tbody>
            </table>
        </body>
    </html>
    View Code

    编写application.yml配置文件

    spring:
      datasource:
        driverClassName: com.mysql.jdbc.Driver
        url: jdbc:mysql://127.0.0.1:3306/springboot
        username: root
        password: root
      jpa:
        database: MySQL
        show-sql: true
        generate-ddl: true
    page:
      rows: 50

    编写Controller,将结果传给模板

    @Controller
    public class PageController {
        @Autowired
        private UserDao userDao;
        @Value("${page.rows}")
        private Integer rows;
        @RequestMapping("/page/user/list")
        public String showUserList(Model model){
            List<User> userList=userDao.findAll();
            model.addAttribute("userList",userList);
            return "user";
        }
        @RequestMapping("/page/rows")
        @ResponseBody
        public Map showRows(){
            Map map = new HashMap();
            map.put("rows",rows);
            return map;
        }
    }
  • 相关阅读:
    JavaScript与C# Windows应用程序交互
    用DateTime.ToString(string format)输出不同格式的日期
    时间间隔与暂停
    C#中比较两个时间的时间差
    lambda函数的用法
    Tornado笔记
    DjangoWeb应用开发实战笔记
    再看装饰器
    描述符
    flask简单代码回顾
  • 原文地址:https://www.cnblogs.com/proyuan/p/11802127.html
Copyright © 2011-2022 走看看