欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

IntelliJ Idea SpringBoot 數(shù)據(jù)庫(kù)增刪改查實(shí)例詳解

 更新時(shí)間:2018年02月08日 09:16:08   作者:無(wú)喱頭的菜園子  
SpringBoot 是 SpringMVC 的升級(jí),對(duì)于編碼、配置、部署和監(jiān)控,更加簡(jiǎn)單。這篇文章主要介紹了IntelliJ Idea SpringBoot 數(shù)據(jù)庫(kù)增刪改查實(shí)例,需要的朋友可以參考下

 

SpringBoot 是 SpringMVC 的升級(jí),對(duì)于編碼、配置、部署和監(jiān)控,更加簡(jiǎn)單

微服務(wù)

微服務(wù)是一個(gè)新興的軟件架構(gòu),就是把一個(gè)大型的單個(gè)應(yīng)用程序和服務(wù)拆分為數(shù)十個(gè)的支持微服務(wù)。一個(gè)微服務(wù)的策略可以讓工作變得更為簡(jiǎn)便,它可擴(kuò)展單個(gè)組件而不是整個(gè)的應(yīng)用程序堆棧,從而滿足服務(wù)等級(jí)協(xié)議。

Spring 為 微服務(wù)提供了一整套的組件-SpringClound , SpirngBoot 就是該基礎(chǔ)。

 

第一個(gè)SpringBoot程序

這里使用的開(kāi)發(fā)軟件是IntelliJ Idea,和Eclipse差不太多,界面更炫酷,功能更強(qiáng)大;Android Studio就是基于IntelliJ 開(kāi)發(fā)的,我之前使用過(guò)Android Studio,它倆界面幾乎一樣。

IntelliJ Idea官網(wǎng):http://www.jetbrains.com/idea/

配置好 maven, tomcat, jdk 就可以使用了

maven配置的中央倉(cāng)庫(kù)阿里云鏡像,這個(gè)地址下載 jar 包的速度,誰(shuí)用誰(shuí)知道!

setting.xml

.
.
 <mirrors>
 <mirror>
  <id>alimaven</id>
  <name>aliyun maven</name>
  <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  <mirrorOf>central</mirrorOf>  
 </mirror>
 </mirrors>
 .
 .

使用IDEA創(chuàng)建SpringBoot項(xiàng)目

我的IDEA版本:IntelliJ IDEA 2016.3.1

項(xiàng)目結(jié)構(gòu)為:

 

項(xiàng)目默認(rèn)的 maven pom.xml文件

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.jxust</groupId>
 <artifactId>spirngbootdemo</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>jar</packaging>
 <name>spirngbootdemo</name>
 <description>Demo project for Spring Boot</description>
 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.4.2.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <java.version>1.8</java.version>
 </properties>
 <dependencies>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>
 </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
  </plugins>
 </build>
</project>

運(yùn)行SpirngbootdemoApplication的main方法,就能開(kāi)始運(yùn)行。

其他啟動(dòng)方式,請(qǐng)看視頻教程http://www.imooc.com/learn/767\

控制臺(tái)輸出:

"C:\Program Files\Java\jdk1.8.0_91\bin\java" .... 
 . ____   _   __ _ _
 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/ ___)| |_)| | | | | || (_| | ) ) ) )
 ' |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::  (v1.4.2.RELEASE)
 2016-12-16 14:56:52.083 INFO 15872 --- [   main] o.s.j.e.a.AnnotationMBeanExporter  : Registering beans for JMX exposure on startup
2016-12-16 14:56:52.215 INFO 15872 --- [   main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-12-16 14:56:52.255 INFO 15872 --- [   main] com.jxust.SpirngbootdemoApplication  : Started SpirngbootdemoApplication in 7.795 seconds (JVM running for 9.177)

從這里可以看到 Tomcat 的端口號(hào),因?yàn)檫€沒(méi)有自定義Controller,所以還沒(méi)有視圖,下面來(lái)創(chuàng)建一個(gè)輸出Hello SpringBoot!的視圖。

創(chuàng)建一個(gè)HelloController,位于controller包下

 

HelloController.java

package com.jxust.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created by Peng
 * Time: 2016/12/16 15:45
 */
@RestController
public class HelloController {
 
 @RequestMapping("/hello")
 public String say(){
  return "Hello SpringBoot!";
 }
}

@RestController Spring4 之后新加的注解,原來(lái)返回json需要@ResponseBody配合@Controller,現(xiàn)在一個(gè)頂倆

在瀏覽器中輸入http://localhost:8080/hello就能輸出Hello SpringBoot!這句話。

 

自定義屬性配置

用到的是application.properties這個(gè)文件

 

配置端口號(hào)和訪問(wèn)前綴

application.properties
server.port=8081
server.context-path=/springboot

 

除了使用.properties格式的文件,還可以使用.yml格式的配置文件(推薦),更加簡(jiǎn)便

application.yml

 

把原來(lái)的application.properties文件刪除

注意格式,空格不能少

獲取配置文件中的屬性值

我們也可以在配置文件中,配置數(shù)據(jù),在 Controller 中獲取,比如:

application.yml

server:
 port: 8081
 context-path: /springboot
name: 小胖

HelloController 獲取配置文件中的值

HelloController.java

....
@RestController
public class HelloController {
 
 @Value("${name}")
 private String name;
 
 @RequestMapping(value = "/hello",method = RequestMethod.GET)
 public String say(){
  return name;
 }
}

返回的為name的值

 

配置文件中值配置方式的多樣化

配置文件的值可以是多個(gè),也可以是組合,如:

application.yml

name: 小胖
age: 22
或者
name: 小胖
age: 22
content: "name: ${name},age: ${age}"
或者
server:
 port: 8081
 context-path: /springboot
person:
 name: 小胖
 age: 22

前兩種配置獲取值的方式都是一樣的,但是對(duì)于這種方式,person 有相應(yīng)的兩個(gè)屬性,需要這樣處理

PersonProperties.java

package com.jxust;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
 * Created by Peng
 * Time: 2016/12/16 16:34
 */
@Component
@ConfigurationProperties(prefix = "person")
public class PersonProperties {
 private String name;
 private Integer age;
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public Integer getAge() {
  return age;
 }
 public void setAge(Integer age) {
  this.age = age;
 }
}

Alt+insert快捷鍵提示生成 Getter and Setter

pom.xml需要加入下面的依賴,處理警告

<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-configuration-processor</artifactId>
 <optional>true</optional>
</dependency>

HelloController.java

package com.jxust.controller;
import com.jxust.PersonProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created by Peng
 * Time: 2016/12/15 20:55
 */
@RestController
public class HelloController {
 @Autowired
 private PersonProperties personProperties;
 @RequestMapping(value = "/hello",method = RequestMethod.GET)
 public String say(){
  return personProperties.getName()+personProperties.getAge();
 }
}

 

關(guān)于配置文件application.yml的多套配置

類似 il8n 文件國(guó)際化的配置方式i18n_en_US.properties和i18n_zh_CN.properties

這樣能解決,需要頻繁修改配置的尷尬

 

由application.yml配置文件決定使用那套配置文件。

application.yml

spring:
 profiles:
 active: a

application-a.yml

server:
 port: 8081
 context-path: /springboot
person:
 name: 小雷
 age: 21

application-b.yml

server:
 port: 8081
 context-path: /springboot
person:
 name: 小胖
 age: 22

SpringBoot增刪改查實(shí)例

完整的項(xiàng)目結(jié)構(gòu)

Controller的使用

Controller的使用

@Controller chu處理http請(qǐng)求
@RestController Spring4 之后新加的注解,原來(lái)返回json需要@ResponseBody配合@Controller
@RequestMapping 配置url映射

對(duì)于 REST 風(fēng)格的請(qǐng)求

 

對(duì)于 Controller 中的方法上的注解

@RequestMapping(value = “/hello”,method = RequestMethod.GET) @RequestMapping(value = “/hello”,method = RequestMethod.POST) @RequestMapping(value = “/hello”,method = RequestMethod.DELETE) @RequestMapping(value = “/hello”,method = RequestMethod.PUT)

SpringBoot 對(duì)上面的注解進(jìn)行了簡(jiǎn)化

@GetMapping(value = “/girls”) @PostMapping(value = “/girls”) @PutMapping(value = “/girls/{id}”) @DeleteMapping(value = “/girls/{id}”)

瀏覽器需要發(fā)送不同方式的請(qǐng)求,可以安裝HttpRequester插件,火狐瀏覽器可以直接搜索該組件安裝。

 

 

spring-data-jpa

JPA全稱Java Persistence API.JPA通過(guò)JDK 5.0注解或XML描述對(duì)象-關(guān)系表的映射關(guān)系,并將運(yùn)行期的實(shí)體對(duì)象持久化到數(shù)據(jù)庫(kù)中。

Hibernate3.2+、TopLink 10.1.3以及OpenJPA都提供了JPA的實(shí)現(xiàn)。

利用JPA創(chuàng)建MySQL數(shù)據(jù)庫(kù)

pom.xml加入JPA和MySQL的依賴

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-jpa</artifactId>
  </dependency>
  <dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
  </dependency>

配置JPA和數(shù)據(jù)庫(kù)

application.yml

spring:
 profiles:
 active: a
 datasource:
  driver-class-name: com.mysql.jdbc.Driver
  url: jdbc:mysql://127.0.0.1:3306/db_person
  username: root
  password: root
 jpa:
 hibernate:
  ddl-auto: update
 show-sql: true

格式很重要

需要自己手動(dòng)去創(chuàng)建 db_person 數(shù)據(jù)庫(kù)

創(chuàng)建與數(shù)據(jù)表對(duì)應(yīng)的實(shí)體類Person

 

Person.java

package com.jxust.entity;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
 * Created by Peng
 * Time: 2016/12/16 17:56
 */
@Entity
public class Person {
 @Id
 @GeneratedValue
 private Integer id;
 private String name;
 private Integer age;
 //必須要有構(gòu)造函數(shù)
 public Person() {
 }
 public Integer getId() {
  return id;
 }
 public void setId(Integer id) {
  this.id = id;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public Integer getAge() {
  return age;
 }
 public void setAge(Integer age) {
  this.age = age;
 }
}

運(yùn)行項(xiàng)目后,查看數(shù)據(jù)庫(kù),會(huì)自動(dòng)創(chuàng)建表 person

mysql> use db_person;
Database changed
mysql> desc person;
+-------+--------------+------+-----+---------+----------------+
| Field | Type   | Null | Key | Default | Extra   |
+-------+--------------+------+-----+---------+----------------+
| id | int(11)  | NO | PRI | NULL | auto_increment |
| age | int(11)  | YES |  | NULL |    |
| name | varchar(255) | YES |  | NULL |    |
+-------+--------------+------+-----+---------+----------------+
3 rows in set (0.09 sec)

接下來(lái)就可以進(jìn)行person表的增刪改查了

創(chuàng)建控制器PersonController.java

 

首先創(chuàng)建一個(gè)接口PersonRepository,位于dao包下,PersonController調(diào)用該接口繼承自JpaRepository的方法,來(lái)實(shí)現(xiàn)和數(shù)據(jù)庫(kù)交互

這個(gè)PersonRepository接口的功能,與SSM框架中 dao 層接口功能有異曲同工之妙;在SSM框架中,Service層通過(guò)該接口,間接執(zhí)行Mybatis數(shù)據(jù)庫(kù)映射文件(.xml)里的相應(yīng)sql語(yǔ)句,執(zhí)行數(shù)據(jù)庫(kù)增刪改查的操作。(Mapper自動(dòng)實(shí)現(xiàn)DAO接口)

PersonRepository.java

package com.jxust.dao;
import com.jxust.entity.Person;
import org.springframework.data.jpa.repository.JpaRepository;
/**
 * Created by Peng
 * Time: 2016/12/16 18:07
 */
public interface PersonRepository extends JpaRepository<Person,Integer> {
}

PersonController.java

package com.jxust.controller;
import com.jxust.dao.PersonRepository;
import com.jxust.entity.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
 * Created by Peng
 * Time: 2016/12/16 18:04
 */
@RestController
public class PersonController {
 @Autowired
 PersonRepository personRepository;
 @GetMapping(value = "/person")
 private List<Person> personList() {
  return personRepository.findAll();
 }
}

在數(shù)據(jù)庫(kù)中添加兩條數(shù)據(jù)

mysql> select * from person;
+----+------+--------+
| id | age | name |
+----+------+--------+
| 1 | 23 | 夏洛 |
| 2 | 21 | 馬冬梅 |
+----+------+--------+
2 rows in set (0.04 sec)

啟動(dòng)項(xiàng)目執(zhí)行請(qǐng)求http://localhost:8081/springboot/person

 

控制臺(tái)輸出的sql語(yǔ)句:

Hibernate: select person0_.id as id1_0_, person0_.age as age2_0_, person0_.name as name3_0_ from person person0_

其他增刪改查的方法

PersonController.java

....
 /**
  * 添加一個(gè)人員
  *
  * @param name
  * @param age
  * @return
  */
 @PostMapping(value = "/person")
 public Person personAdd(@RequestParam("name") String name,
      @RequestParam("age") Integer age) {
  Person person = new Person();
  person.setName(name);
  person.setAge(age);
 
  return personRepository.save(person);
 }
 
 /**
  * 查詢一個(gè)人員
  *
  * @param id
  * @return
  */
 @GetMapping(value = "/person/{id}")
 public Person personFindOne(@PathVariable("id") Integer id) {
  return personRepository.findOne(id);
 }
 
 /**
  * 刪除一個(gè)人員
  *
  * @param id
  */
 @DeleteMapping(value = "/person/{id}")
 public void personDelete(@PathVariable("id") Integer id) {
  personRepository.delete(id);
 }
 
 /**
  * 更新一個(gè)人員
  *
  * @param id
  * @param name
  * @param age
  * @return
  */
 @PutMapping(value = "/person/{id}")
 public Person personUpdate(@PathVariable("id") Integer id,
       @RequestParam("name") String name,
       @RequestParam("age") Integer age) {
  Person person = new Person();
  person.setId(id);
  person.setName(name);
  person.setAge(age);
  return personRepository.save(person);
 }

對(duì)應(yīng)的請(qǐng)求方式為:

查詢一個(gè)用戶:

 

添加一個(gè)用戶

 

刪除一個(gè)用戶(無(wú)返回值)

 

更新一個(gè)用戶

 

那么根據(jù)年齡查詢,可不可以呢。答案是此刻還不行

從控制臺(tái)的語(yǔ)句可以看出,sql 語(yǔ)句都是根據(jù)id來(lái)查詢的

Hibernate: select person0_.id as id1_0_0_, person0_.age as age2_0_0_, person0_.name as name3_0_0_ from person person0_ where person0_.id=?

根據(jù)年齡查詢

在PersonRepository增加一個(gè)方法findByAge(Integer age)

public interface PersonRepository extends JpaRepository<Person,Integer> {
 /**
  * 通過(guò)年齡來(lái)查詢
  * 方法名固定findByAge
  * @param age
  * @return
  */
 public List<Person> findByAge(Integer age);
}

在PersonController中加入相應(yīng)的查詢方法

....
 /**
  * 通過(guò)年齡來(lái)查詢
  * @param age
  * @return
  */
 @GetMapping(value = "/person/age/{age}")
 public List<Person> personListByAge(@PathVariable("age") Integer age) {
  return personRepository.findByAge(age);
 }

輸入請(qǐng)求http://localhost:8081/springboot/person/age/23,查詢年齡為23的人員

 

控制臺(tái)輸出SQL語(yǔ)句:

Hibernate: select person0_.id as id1_0_, person0_.age as age2_0_, person0_.name as name3_0_ from person person0_ where person0_.age=?

事務(wù)管理

兩條 sql 語(yǔ)句同時(shí)在一個(gè)方法中執(zhí)行,為了防止一個(gè) sql 語(yǔ)句執(zhí)行成功而另一個(gè) sql 語(yǔ)句執(zhí)行失敗,引入了事務(wù)管理,需要在方法上加 @Transactional事務(wù)注解

事務(wù)確保了數(shù)據(jù)庫(kù)數(shù)據(jù)的完整性和一致性

 

PersonService.java

在PersonControll

package com.jxust.service;
import com.jxust.dao.PersonRepository;
import com.jxust.entity.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
/**
 * Created by Peng
 * Time: 2016/12/16 19:30
 */
@Service
public class PersonService {
 @Autowired
 private PersonRepository personRepository;
 /**
  * 事務(wù)管理測(cè)試
  * 兩條數(shù)據(jù)同時(shí)成功,或者同時(shí)不成功
  * 保證數(shù)據(jù)庫(kù)數(shù)據(jù)的完整性和一致性
  */
 @Transactional
 public void insertTwo(){
  Person personA = new Person();
  personA.setName("秋雅");
  personA.setAge(19);
  personRepository.save(personA); 
  System.out.print(1/0);
  Person personB = new Person();
  personB.setName("夢(mèng)特嬌");
  personB.setAge(25);
  personRepository.save(personB);
 }
}

er中測(cè)試

...
 @Autowired
 private PersonService personService;
 ...
  /**
  * 事務(wù)測(cè)試
  */
 @PostMapping("/person/two")
 public void personTwo(){
  personService.insertTwo();
 }

重新運(yùn)行項(xiàng)目,執(zhí)行請(qǐng)求 post方式http://localhost:8081/springboot/person/two

數(shù)據(jù)庫(kù)并沒(méi)有添加第一條數(shù)據(jù),說(shuō)明存在事務(wù)管理

完整的PersonController.java、PersonRepository.java和pom.xml

PersonController.java

package com.jxust.controller;
import com.jxust.dao.PersonRepository;
import com.jxust.entity.Person;
import com.jxust.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * Created by Peng
 * Time: 2016/12/16 18:04
 */
@RestController
public class PersonController {
 @Autowired
 PersonRepository personRepository;
 @Autowired
 private PersonService personService;
 /**
  * 查詢所有人員列表
  *
  * @return
  */
 @GetMapping(value = "/person")
 private List<Person> personList() {
  return personRepository.findAll();
 }
 /**
  * 添加一個(gè)人員
  *
  * @param name
  * @param age
  * @return
  */
 @PostMapping(value = "/person")
 public Person personAdd(@RequestParam("name") String name,
      @RequestParam("age") Integer age) {
  Person person = new Person();
  person.setName(name);
  person.setAge(age);
  return personRepository.save(person);
 }
 /**
  * 查詢一個(gè)人員
  *
  * @param id
  * @return
  */
 @GetMapping(value = "/person/{id}")
 public Person personFindOne(@PathVariable("id") Integer id) {
  return personRepository.findOne(id);
 }
 /**
  * 刪除一個(gè)人員
  *
  * @param id
  */
 @DeleteMapping(value = "/person/{id}")
 public void personDelete(@PathVariable("id") Integer id) {
  personRepository.delete(id);
 }
 /**
  * 更新一個(gè)人員
  *
  * @param id
  * @param name
  * @param age
  * @return
  */
 @PutMapping(value = "/person/{id}")
 public Person personUpdate(@PathVariable("id") Integer id,
       @RequestParam("name") String name,
       @RequestParam("age") Integer age) {
  Person person = new Person();
  person.setId(id);
  person.setName(name);
  person.setAge(age);
  return personRepository.save(person);
 }
 /**
  * 通過(guò)年齡來(lái)查詢
  * @param age
  * @return
  */
 @GetMapping(value = "/person/age/{age}")
 public List<Person> personListByAge(@PathVariable("age") Integer age) {
  return personRepository.findByAge(age);
 }
 /**
  * 事務(wù)測(cè)試
  */
 @PostMapping("/person/two")
 public void personTwo(){
  personService.insertTwo();
 }
}

PersonRepository.java

package com.jxust.dao;
import com.jxust.entity.Person;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
 * Created by Peng
 * Time: 2016/12/16 18:07
 */
public interface PersonRepository extends JpaRepository<Person,Integer> {
 /**
  * 通過(guò)年齡來(lái)查詢
  * 方法名固定
  * @param age
  * @return
  */
 public List<Person> findByAge(Integer age);
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.jxust</groupId>
 <artifactId>spirngbootdemo</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>jar</packaging>
 <name>spirngbootdemo</name>
 <description>Demo project for Spring Boot</description>
 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.4.2.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <java.version>1.8</java.version>
 </properties>
 <dependencies>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-configuration-processor</artifactId>
   <optional>true</optional>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-jpa</artifactId>
  </dependency>
  <dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
  </dependency>
 </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
  </plugins>
 </build>
</project>

總結(jié)

以上所述是小編給大家介紹的IntelliJ Idea SpringBoot 數(shù)據(jù)庫(kù)增刪改查實(shí)例詳解,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • java可變參數(shù)(不定向參數(shù))的作用與實(shí)例

    java可變參數(shù)(不定向參數(shù))的作用與實(shí)例

    這篇文章主要給大家介紹了關(guān)于java可變參數(shù)(不定向參數(shù))的作用與實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • java中實(shí)體類和JSON對(duì)象之間相互轉(zhuǎn)化

    java中實(shí)體類和JSON對(duì)象之間相互轉(zhuǎn)化

    Java中關(guān)于Json格式轉(zhuǎn)化Object,Map,Collection類型和String類型之間的轉(zhuǎn)化在我們實(shí)際項(xiàng)目中應(yīng)用的很是普遍和廣泛。最近工作的過(guò)程中也是經(jīng)常有,因此,自己封裝了一個(gè)類分享給大家。
    2015-05-05
  • java后端PayPal支付實(shí)現(xiàn)教程

    java后端PayPal支付實(shí)現(xiàn)教程

    本文主要介紹了java后端PayPal支付實(shí)現(xiàn)教程,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • Java中枚舉的實(shí)現(xiàn)原理介紹

    Java中枚舉的實(shí)現(xiàn)原理介紹

    大家好,本篇文章主要講的是Java中枚舉的實(shí)現(xiàn)原理介紹,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • 一文搞清楚Java中Comparable和Comparator的區(qū)別

    一文搞清楚Java中Comparable和Comparator的區(qū)別

    Java中的Comparable和Comparator都是用于集合排序的接口,但它們有明顯的區(qū)別,文中通過(guò)一些實(shí)例代碼詳細(xì)介紹了Java中Comparable和Comparator的區(qū)別,感興趣的同學(xué)跟著小編一起學(xué)習(xí)吧
    2023-05-05
  • SpringBoot注入Bean的四種方式總結(jié)

    SpringBoot注入Bean的四種方式總結(jié)

    這篇文章主要給大家總結(jié)SpringBoot注入Bean的四種方式,啟動(dòng)類注入Bean,啟動(dòng)類掃描@ComponentScan,啟動(dòng)類@EnableConfigurationProperties以及啟動(dòng)類@Import這四種方式,文章通過(guò)代碼示例講解非常詳細(xì),需要的朋友可以參考下
    2023-11-11
  • Spring MVC學(xué)習(xí)教程之RequestMappingHandlerMapping匹配

    Spring MVC學(xué)習(xí)教程之RequestMappingHandlerMapping匹配

    這篇文章主要給大家介紹了關(guān)于Spring MVC學(xué)習(xí)教程之RequestMappingHandlerMapping匹配的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-11-11
  • 詳解Spring-boot中讀取config配置文件的兩種方式

    詳解Spring-boot中讀取config配置文件的兩種方式

    這篇文章主要介紹了詳解Spring-boot中讀取config配置文件的兩種方式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Spring循環(huán)依賴的解決方法詳解

    Spring循環(huán)依賴的解決方法詳解

    Spring的解決循環(huán)依賴是有前置條件的,要解決循環(huán)依賴我們首先要了解Spring Bean對(duì)象的創(chuàng)建過(guò)程和依賴注入的方式。依賴注入方式,我之前的博客有所分享,大家可以在看本篇文章之前進(jìn)行一下小小的回顧
    2022-08-08
  • Java中的逃逸問(wèn)題心得

    Java中的逃逸問(wèn)題心得

    本篇文章是作者在學(xué)習(xí)了Java中的逃逸相關(guān)知識(shí)后的心得分享,一起跟著小編學(xué)習(xí)下。
    2018-02-02

最新評(píng)論