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;
        }
    }
  • 相关阅读:
    修改apache的默认访问目录
    禁止浏览器直接访问php文件
    使用Apache Bench进行压力测试
    关于mysql(或MariaDB)中的用户账号格式
    单表查询
    CSS设计指南之一 HTML标记与文档结构
    SQL SERVER技术内幕之10 可编程对象
    SQL SERVER技术内幕之10 事务并发
    观察者模式
    中介者模式
  • 原文地址:https://www.cnblogs.com/proyuan/p/11802127.html
Copyright © 2011-2022 走看看