码迷,mamicode.com
首页 > 编程语言 > 详细

springBoot静态资源处理

时间:2019-02-20 12:51:03      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:sources   word   处理   cat   frame   ann   string   查询   coding   

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.Driver

    url: jdbc:mysql://localhost:3306/springboot?characterEncoding=utf-8

    username: root

    password: root

  jpa: 

    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;

@RestController

public class SellerController {

@Autowired

private 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 

 

springBoot静态资源处理

标签:sources   word   处理   cat   frame   ann   string   查询   coding   

原文地址:https://www.cnblogs.com/alexzhang92/p/10405696.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!