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;
        }
    }
  • 相关阅读:
    前端基础(2)CSS
    前端基础(1)、HTML
    MySQL数据库,这一篇就够啦!!!(持续更新)
    十、数据库之流程控制
    九、数据库之存储过程和函数
    spring注解总结
    eclipse导入项目后错误的处理方式
    ssm分页查询错误
    字节编址和字的区别(转)
    数据库查询练习
  • 原文地址:https://www.cnblogs.com/proyuan/p/11802127.html
Copyright © 2011-2022 走看看