日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

springBoot静态资源处理

發布時間:2025/6/17 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springBoot静态资源处理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Spring Boot?靜態資源處理

spring boot項目如果要展示靜態頁面,可以把html、js、css等文件放在resources目錄下的static或public目錄里面(如果沒有可以直接創建)。

Html測試

?

js測試

?

css測試

?

Spring Boot??data-jpa

1、添加依賴

<!--連接數據庫 需要使用mysql驅動做測試 --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.36</version></dependency><!--使用spring boot 開發data-jpa項目的基礎依賴 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency>

?

?

2、編寫實體對象,添加注解

?

3、書寫配置 在application.yml添加如下配置

#連接池的配置spring:datasource:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/springboot?characterEncoding=utf-8 username: rootpassword: rootjpa: hibernate:ddl-auto: update #ddl-auto: create 每次都創建表,若存在則先刪除 update 表不存在則創建,有更新字段才重新創建

?

4、啟動項目會發現數據庫中新增了一個表seller

?

Spring-data-jpa自動創建的,因為有配置ddl-auto:?update

5、編寫dao

只需要寫接口并繼承JpaRepository即可即可,不需要寫實現類

?

6、編寫controller,注入repository

package com.springboot.controller;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import com.springboot.dao.SellerRepository;import com.springboot.domain.Seller;@RestControllerpublic class SellerController {@Autowiredprivate SellerRepository sellerRepository;@RequestMapping("/addSeller")public String addSeller(Seller seller) {sellerRepository.save(seller);return "OK";}@RequestMapping("/sellerList")public List<Seller> sellerList() {return sellerRepository.findAll();}@RequestMapping("/updateSeller")public String updateSeller(Seller seller) {sellerRepository.save(seller);return "OK";}@RequestMapping("/deleteSeller")public String deleteSeller(Integer id) {sellerRepository.delete(id);return "OK";}}

?

?

7、測試

http://localhost:8088/addSeller?sellerName=alibaba&age=18 添加成功 http://localhost:8088/sellerList 查詢列表 http://localhost:8088/updateSeller?id=5&sellerName=alibaba5&age=25 更新成功 http://localhost:8088/deleteSeller?id=5 刪除成功

?

?

接口定義方法規則?fingBy{條件屬性首字母大寫}

package com.springboot.dao;import org.springframework.data.jpa.repository.JpaRepository;import com.springboot.domain.Seller;public interface SellerRepository extends JpaRepository<Seller, Integer> {Seller findById(Integer id);//不需要寫實現方法,只需要按照規則編寫方法名稱 }

?

Controller中添加條件查詢

@RequestMapping("/findSeller")

public Seller findSeller(Integer id) {

return sellerRepository.findById(id);

}

根據條件查詢

http://localhost:8088/findSeller?id=2?

?

轉載于:https://www.cnblogs.com/alexzhang92/p/10405696.html

總結

以上是生活随笔為你收集整理的springBoot静态资源处理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。