日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

springBoot静态资源处理

發(fā)布時(shí)間:2025/6/17 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springBoot静态资源处理 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Spring Boot?靜態(tài)資源處理

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

Html測(cè)試

?

js測(cè)試

?

css測(cè)試

?

Spring Boot??data-jpa

1、添加依賴

<!--連接數(shù)據(jù)庫(kù) 需要使用mysql驅(qū)動(dòng)做測(cè)試 --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.36</version></dependency><!--使用spring boot 開(kāi)發(fā)data-jpa項(xiàng)目的基礎(chǔ)依賴 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency>

?

?

2、編寫(xiě)實(shí)體對(duì)象,添加注解

?

3、書(shū)寫(xiě)配置 在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 每次都創(chuàng)建表,若存在則先刪除 update 表不存在則創(chuàng)建,有更新字段才重新創(chuàng)建

?

4、啟動(dòng)項(xiàng)目會(huì)發(fā)現(xiàn)數(shù)據(jù)庫(kù)中新增了一個(gè)表seller

?

Spring-data-jpa自動(dòng)創(chuàng)建的,因?yàn)橛信渲胐dl-auto:?update

5、編寫(xiě)dao

只需要寫(xiě)接口并繼承JpaRepository即可即可,不需要寫(xiě)實(shí)現(xiàn)類

?

6、編寫(xiě)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、測(cè)試

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 刪除成功

?

?

接口定義方法規(guī)則?fingBy{條件屬性首字母大寫(xiě)}

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);//不需要寫(xiě)實(shí)現(xiàn)方法,只需要按照規(guī)則編寫(xiě)方法名稱 }

?

Controller中添加條件查詢

@RequestMapping("/findSeller")

public Seller findSeller(Integer id) {

return sellerRepository.findById(id);

}

根據(jù)條件查詢

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

?

轉(zhuǎn)載于:https://www.cnblogs.com/alexzhang92/p/10405696.html

總結(jié)

以上是生活随笔為你收集整理的springBoot静态资源处理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。