天天看點

SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二

上一篇:SpringBoot如何整合WebSocket? | 帶你讀《SpringBoot實戰教程》之四十一

本文來自于千鋒教育在阿裡雲開發者社群學習中心上線課程《SpringBoot實戰教程》,主講人楊紅豔,

點選檢視視訊内容

SpringBoot整合AngularJS

我們需要結合資料庫來進行分析。我們使用db1資料庫中的t_order表

添加依賴:

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.nekohtml</groupId>
        <artifactId>nekohtml</artifactId>
        <version>1.9.22</version>
</dependency>
<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.3.2</version>
</dependency>           

全局配置:

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.url=jdbc:mysql://localhost:3306/db1

#springboot整合thymeleaf
#<!-- 關閉thymeleaf緩存 開發時使用 否則沒有實時畫面-->
spring.thymeleaf.cache=false
## 檢查模闆是否存在,然後再呈現
spring.thymeleaf.check-template-location=true
#Content-Type值
spring.thymeleaf.content-type=text/html
#啟用MVC Thymeleaf視圖分辨率
spring.thymeleaf.enabled=true
## 應該從解決方案中排除的視圖名稱的逗号分隔清單
spring.thymeleaf.excluded-view-names=
#模闆編碼
spring.thymeleaf.mode=LEGACYHTML5
# 在建構URL時預先檢視名稱的字首
spring.thymeleaf.prefix=classpath:/templates/
# 建構URL時附加檢視名稱的字尾.
spring.thymeleaf.suffix=.html
# 鍊中模闆解析器的順序
#spring.thymeleaf.template-resolver-order= o
# 可以解析的視圖名稱的逗号分隔清單
#spring.thymeleaf.view-names=
#thymeleaf end           

com.qianfeng.pojo:

public class Order {

    public String id;
    public String no;
    public Date date;
    public int quantity;

     //get,set略
}           

com.qianfeng.dao:

public interface OrderDao {

    List<Order> findAll();
    Order findById(String id);
    String addOrder(Order order);
    void updateOrder(Order order);
    void deleteById(String id);
}           

com.qianfeng.dao.impl:

SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二

com.qianfeng.controller:

SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二
SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二
SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二

前端頁面:

SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二
SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二
SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二
SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二
SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二
SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二
SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二

啟動類:

SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二

執行結果:

SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二

點選添加:

SpringBoot如何整合AngularJS? | 帶你讀《SpringBoot實戰教程》之四十二

配套視訊