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静态资源处理相关推荐
- 第14章 SpringBoot静态资源处理
第14章 SpringBoot静态资源处理 14.1 WebMvcAutoConfiguration的默认配置 14.2 自定义静态资源映射 14.3 前端资源的引用方法
- springBoot静态资源优先级)
springBoot静态资源优先级 springboot项目结构 默认优先级 自己设置指定某目录内文件为静态资源 springboot项目结构 默认优先级 /META-INF/resources> ...
- springboot 静态资源访问,和文件上传 ,以及路径问题
springboot 静态资源访问: 这是springboot 默认的静态资源访问路径 访问顺序依次从前到后(http://localhost:8080/bb.jpg) spring.resourc ...
- SpringBoot - 静态资源映射处理
SpringBoot - 静态资源映射处理 [1]静态资源文件映射规则 同样查看WebMVCAutoConfiguration源码如下: @Overridepublic void addResourc ...
- SpringBoot静态资源目录
SpringBoot静态资源目录 前言 今天博主将为大家分享SpringBoot静态资源目录!不喜勿喷,如有异议欢迎讨论! 以下所写内容均与以前的文章有联系可以前往博文查看,陈永佳的博客 之前的一系列 ...
- springboot 静态资源缓存设置
springboot 静态资源 js css 缓存设置 @Configuration public class WebMvcConfiguration implements WebMvcConfig ...
- springboot静态资源访问
springboot的项目中,默认的开启的静态资源目录有: classpath:/META-INF/resources/, classpath:/resources/, classpath:/stat ...
- SpringBoot静态资源的映射
一, webjars 所有的webjars被导入后,目录结构都是这样的 : springboot的底层告诉我们 , 如果要引用webjars , 我们只需要在引用的位置使用 " /webja ...
- springboot静态资源的配置
1. springboot默认的静态资源存放路径 静态资源的存放路径为classpath,也就是resources目录下的: /META-INF/resources /resources /stati ...
最新文章
- Flash中的“插入关键帧”和“插入空白关键帧”的区别
- 使用Lock and Load X 插件时导致Final Cat Pro意外退出的解决办法
- Android Images
- 管脚自动分配_lattice器件管脚评估与功耗评估
- thinkphp5杂谈--模板
- c语言超时自动退出,Golang实现for循环运行超时后自动退出的方法
- 推送MobPush-API说明
- Oracle数据恢复顾问(Data Recovery Advisor)
- VS201-无法打开源文件hpp(或链接库文件)的解决方法
- 【0520】密钥管理技术
- OPENGL ES 2.0 知识串讲(2)――EGL详解
- 机器视觉算法与应用读书笔记(算法)
- 核心单词Word List 40
- 浅谈对软件企业OEM的理解
- 100%基于深度强化学习的对冲基金
- SpringBoot使用validator校验
- 前端工程师必备的PS技能——切图篇
- 如何省时省力验证模型效果?达观数据在线分层实验平台给你支招
- 面试前必读【面经+(BAT面试题)】
- BLE协议--SMP(安全管理协议)