JavaEE 之 SpringBoot

1.Springboot

  a.定义:Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程

  b.约定目录结构:(Maven的资源文件目录/src/java/resources中)

      spring-boot项目静态文件目录:/src/java/resources/static(一般放img、css、js等)

      spring-boot项目模板文件目录:/src/java/resources/templates(一般放html文件)

 

 

2.使用

  a.Controller中

    @GetMapping("/")    //输入路径http://127.0.0.1:8080/ 即可访问到
    public String index(){
        return "index";
    }

    @GetMapping("/loginPapge")
    public String loginPapge(){
        return "login";
    }

  b.html中

<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>Title</title>
</head>
<body>
欢迎你:<span th:text="${session.user.getUserName()}"></span>
    <table>
        <tr>
            <th>id</th>
            <th>姓名</th>
            <th>密码</th>
            <th>状态</th>
        </tr>
        <tr  th:each="user,userStat: ${users}">
            <td th:text="${user.userId}"></td>
            <td th:text="${user.userName}"></td>
            <td th:text="${user.userPwd}"></td>
            <td th:text="${user.userType}"></td>

        </tr>
    </table>
</body>
</html>

  c.如需使用Spring Data Jpa,需在/src/java/resources中配置application.yml

spring:
  thymeleaf:
    cache: false
  datasource:
    username: root
    url: jdbc:mysql://127.0.0.1:3306/j135
    driver-class-name: com.mysql.jdbc.Driver
    password: admin
  jpa:
    show-sql: true
    database-platform: org.hibernate.dialect.MySQL5Dialect

 

    

posted @ 2017-04-25 19:41  晨M风  阅读(2191)  评论(0编辑  收藏  举报