springBoot静态资源处理
生活随笔
收集整理的這篇文章主要介紹了
springBoot静态资源处理
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Spring Boot?靜態(tài)資源處理
spring boot項目如果要展示靜態(tài)頁面,可以把html、js、css等文件放在resources目錄下的static或public目錄里面(如果沒有可以直接創(chuàng)建)。
Html測試
?
js測試
?
css測試
?
Spring Boot?–?data-jpa
1、添加依賴
<!--連接數(shù)據(jù)庫 需要使用mysql驅動做測試 --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.36</version></dependency><!--使用spring boot 開發(fā)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 每次都創(chuàng)建表,若存在則先刪除 update 表不存在則創(chuàng)建,有更新字段才重新創(chuàng)建?
4、啟動項目會發(fā)現(xiàn)數(shù)據(jù)庫中新增了一個表seller
?
Spring-data-jpa自動創(chuàng)建的,因為有配置ddl-auto:?update
5、編寫dao
只需要寫接口并繼承JpaRepository即可即可,不需要寫實現(xiàn)類
?
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 刪除成功?
?
接口定義方法規(guī)則?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);//不需要寫實現(xiàn)方法,只需要按照規(guī)則編寫方法名稱 }?
Controller中添加條件查詢
@RequestMapping("/findSeller")
public Seller findSeller(Integer id) {
return sellerRepository.findById(id);
}
根據(jù)條件查詢
http://localhost:8088/findSeller?id=2?
?
轉載于:https://www.cnblogs.com/alexzhang92/p/10405696.html
總結
以上是生活随笔為你收集整理的springBoot静态资源处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Google protobuf使用技巧和
- 下一篇: MySQL 关于性能的参数配置梳理