国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - springboot配置內存數據庫H2教程詳解

springboot配置內存數據庫H2教程詳解

2020-11-28 14:55zhanglf02 Java教程

這篇文章主要介紹了springboot配置內存數據庫H2的詳細教程,需要的朋友可以參考下

業務背景:因soa系統要供外網訪問,處于安全考慮用springboot做了個前置模塊,用來轉發外網調用的請求和soa返回的應答。其中外網的請求接口地址在db2數據庫中對應專門的一張表來維護,要是springboot直接訪問數據庫,還要專門申請權限等,比較麻煩,而一張表用內置的h2數據庫維護也比較簡單,就可以作為替代的辦法。

環境:springboot+maven3.3+jdk1.7

1.springboot的maven工程結構

springboot配置內存數據庫H2教程詳解

說明一下,resource下的templates文件夾沒啥用。我忘記刪掉了。。。

2. 首先引入依賴jar包 pom.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!--?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.zlf</groupid>
 spring-boot</artifactid>
 <version>1.0-snapshot</version>
 <!-- 增加父pom ,spring-boot-starter-parent包含了大量配置好的依賴管理,他是個特殊的starter,它提供了有用的maven默認設置 -->
 <parent>
  <groupid>org.springframework.boot</groupid>
  spring-boot-starter-parent</artifactid>
  <version>1.4.3.release</version>
 </parent>
 <!-- spring默認使用jdk1.6,如果你想使用jdk1.8,你需要在pom.xml的屬性里面添加java.version,如下: -->
 <properties>
  <project.build.sourceencoding>utf-8</project.build.sourceencoding>
  <tomcat.version>7.0.72</tomcat.version>
  <java.version>1.8</java.version>
 </properties>
 <!-- spring通過添加spring-boot-starter-*這樣的依賴就能支持具體的某個功能。 -->
 <!-- 我們這個示例最終是要實現web功能,所以添加的是這個依賴。 -->
 <dependencies>
  <dependency>
   <!-- 指定為web應用,并啟動一個內嵌的servlet容器(默認是tomcat)用于處理http請求 -->
   <groupid>org.springframework.boot</groupid>
   spring-boot-starter-web</artifactid>
  </dependency>
  <!-- 對java 持久化api的支持,包括spring-data-jap,spring-orm,hibernate-->
  <dependency>
   <groupid>org.springframework.boot</groupid>
   spring-boot-starter-data-jpa</artifactid>
  </dependency>
  <!-- lombok插件,方便model對象的處理 -->
  <dependency>
   <groupid>org.projectlombok</groupid>
   lombok</artifactid>
  </dependency>
  <!-- 內嵌數據庫 -->
  <dependency>
   <groupid>com.h2database</groupid>
   h2</artifactid>
  </dependency>
  <!-- mysql驅動 -->
<!--  <dependency> -->
<!--   <groupid>mysql</groupid> -->
<!--   mysql-connector-java</artifactid> -->
<!--  </dependency> -->
  <dependency>
   <groupid>junit</groupid>
   junit</artifactid>
   <scope>test</scope>
  </dependency>
<!--  <dependency> -->
<!--   <groupid>javax.servlet</groupid> -->
<!--   jstl</artifactid> -->
<!--  </dependency> -->
 </dependencies>
 <build>
  <!-- 打包后的jar包名稱 -->
  <finalname>example</finalname>
  <plugins>
   <plugin>
    <groupid>org.springframework.boot</groupid>
    <!-- 必須要的springboot繼承的maven插件,缺少了無法打包jar。 -->
    spring-boot-maven-plugin</artifactid>
    <dependencies>
     <!-- 在我們開發過程中,我們需要經常修改,為了避免重復啟動項目,我們可以啟用熱部署。 spring-loaded項目提供了強大的熱部署功能,
      添加/刪除/修改 方法/字段/接口/枚舉 等代碼的時候都可以熱部署,速度很快,很方便。 想在spring boot中使用該功能非常簡單 ,就是在spring-boot-maven-plugin插件下面添加依賴: -->
     <dependency>
      <groupid>org.springframework</groupid>
      springloaded</artifactid>
      <version>1.2.5.release</version>
     </dependency>
    </dependencies>
   </plugin>
  </plugins>
 </build>
</project>

3.在src/main/resource根目錄下進行配置h2數據庫。

schema.sql中建表。可以見多個表。用分號隔開

?
1
2
3
4
5
create table staff(
id char(20) not null primary key,
name char(20),
age integer
);

data.sql 為新建的表進行初始化數據的操作。可以放入多個表的插入語句。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
insert into staff values(
 's01',
 '張三',
 26
);
insert into staff values(
 's02',
 '春天里asdglkj',
 23
);
insert into staff values(
 's03',
 '劉三',
 26
);
insert into staff values(
 's04',
 '萬里高空',
 26
);
insert into staff values(
 's05',
 '火影',
 26
);
insert into staff values(
 's06',
 'xiaopang',
 26
);
insert into staff values(
 's07',
 '海賊王',
 26
);
insert into staff values(
 's08',
 '王者榮耀',
 26
)

application.properties db2數據庫設置和控制臺現實設置等。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#spring.datasource.url = jdbc:mysql://localhost:3306/zhanglfdatabase
#spring.datasource.username = root
#spring.datasource.password =
#spring.datasource.driverclassname = com.mysql.jdbc.driver
#數據庫支持多種連接模式和連接設置,不同的連接模式和連接設置是通過不同的url來區分的,url中的設置是不區分大小寫。內存數據庫(私有)
#jdbc:h2:mem:
#內存數據庫(被命名)
#jdbc:h2:mem:<databasename>
#jdbc:h2:mem:test_mem
spring.datasource.url =jdbc:h2:mem:soa_service_api
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.driverclassname = org.h2.driver
#進行該配置后,每次啟動程序,程序都會運行resources/schema.sql文件,對數據庫的結構進行操作,相當于新建一個表。
spring.datasource.schema=classpath:schema.sql
#進行該配置后,每次啟動程序,程序都會運行resources/data.sql文件,對數據庫的數據操作,相當于往表中插入數據。
spring.datasource.data=classpath:data.sql
# 數據庫類型聲明
spring.jpa.database = h2
# 是否開啟查詢語句在控制臺打印
spring.jpa.show-sql = true
# hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update
# naming strategy
#spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.improvednamingstrategy
#開啟h2控制臺功能和訪問地址。
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console</databasename>
這里有必要強調h2數據庫設置的屬性:
spring.datasource.url =jdbc:h2:mem:soa_service_api

因為數據庫支持多種連接模式和連接設置,不同的連接模式和連接設置是通過不同的url來區分的,url中的設置是不區分大小寫。其中幾種常用的設置如下圖

springboot配置內存數據庫H2教程詳解

前兩種對應的效果是:

1. jdbc:h2:file:e:/data/h2 表示將初始化的數據和h2 console控制臺執行的數據保存到e盤下data/h2文件夾中,即使應用重啟,數據不會丟失。

2. jdbc:h2:~/testdatabase這里就需要說明一下”~”這個符號在window操作系統下代表什么意思了,在window操作系統下,”~”這個符號代表的就是當前登錄到操作系統的用戶對應的用戶目錄,所以testdatabase數據庫對應的文件存放在登錄到操作系統的用戶對應的用戶目錄當中,比如我當前是使用administrator用戶登錄操作系統的,所以在”c:\documents and settings\administrator.h2”目錄中就可以找到test數據庫對應的數據庫文件了

持久化本地的問題:由于本地已經存在表,而應用每次啟動都會創建表,導致下次啟動時會啟動報錯。除非手動注掉application.properties中新建表的配置,或則刪除本地對應目錄的文件。

3.jdbc:h2:mem:soa_service_api、jdbc:h2:mem:~/.h2/url類似與這種配置的,表示將初始化和h2 console控制臺上操作的數據保存在內存(mem-memory)

保存到內存的問題:由于每次重啟應用內存釋放掉后,對應的數據也會消失,當然初始化的表+初始化數據就都沒了。然后重啟會從data.sql中重新初始化數據,啟動正常。但是你通過h2
console操作的其他數據則全部丟失。解決辦法是把在h2 console新添加的接口地址配置到data.sql中。然后重新啟動才行。

4.h2的配置說完,下面開始進行h2的測試代碼java文件部分,看看有沒有配置成功。我們用到jpa這個持久化的接口工具。

a.映射的pojo實體類-staffbo,注意點和說明都在代碼里了。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.zlf.bo;
import java.io.serializable;
import javax.persistence.column;
import javax.persistence.entity;
import javax.persistence.id;
import javax.persistence.table;
import lombok.data;
@data//可以省略get+set方法。
@entity
@table(name="staff")//注解的name屬性值要和schema.sql定義的表名一致。不然啟動雖然不報錯,但和表映射不上,就取不到任何值。
public class staffbo implements serializable {
 private static final long serialversionuid = 1l;
 //主鍵是必須聲明的。不然啟動會報實體中無定義主鍵的錯: no identifier specified for entity: com.zlf.bo.staffbo
 @id
 private string id;
// @column(name="name") 如果表中字段名稱和這里的屬性名稱一樣,可以不同加column注解。
 private string name;
 @column(name="age")
 private int age;
}

b.然后是類似與dao層接口的操作數據庫的接口,staffrepository這個接口要繼承pagingandsortingrepository才能實現對數據庫的crud操作。

?
1
2
3
4
5
6
package com.zlf.repository;
import org.springframework.data.repository.pagingandsortingrepository;
import com.zlf.bo.staffbo;
public interface staffrepository extends pagingandsortingrepository<staffbo,string> {
}
</staffbo,string>

c. 然后就是service層的接口和實現類,在實現類中注入api接口的實例,并用實例操作數據庫,這里是h2數據庫。

?
1
2
3
4
5
6
7
package com.zlf.service;
import java.util.list;
import com.zlf.bo.staffbo;
public interface istaffservice {
 public list<staffbo> queryallstafflist();
}
</staffbo>

這里我們只做了個查詢所有的操作。然后希望在頁面打印出來這些實體信息。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.zlf.service.impl;
import java.util.arraylist;
import java.util.iterator;
import java.util.list;
import org.springframework.beans.factory.annotation.autowired;
import org.springframework.stereotype.service;
import com.zlf.bo.staffbo;
import com.zlf.repository.staffrepository;
import com.zlf.service.istaffservice;
@service
public class staffserviceimpl implements istaffservice {
 @autowired
 private staffrepository staffrepository;
 @override
 public list<staffbo> queryallstafflist() {
  iterable<staffbo> iterable = staffrepository.findall();
  list<staffbo> list=new arraylist<staffbo>();
  iterator<staffbo> iterator = iterable.iterator();
  while(iterator.hasnext()){
   staffbo next = iterator.next();
   list.add(next);
  }
  return list;
 }
}
</staffbo></staffbo></staffbo></staffbo></staffbo>

d. controller層

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.zlf.controller;
import java.util.list;
import org.slf4j.logger;
import org.slf4j.loggerfactory;
import org.springframework.beans.factory.annotation.autowired;
import org.springframework.stereotype.controller;
import org.springframework.web.bind.annotation.requestmapping;
import org.springframework.web.bind.annotation.responsebody;
import com.zlf.bo.staffbo;
import com.zlf.service.istaffservice;
@controller
@requestmapping(path="/staff",produces="application/json;charset=utf-8")
public class staffcontroller {
 private static final logger logger=loggerfactory.getlogger(staffcontroller.class);
 @autowired
 private istaffservice staffservice;
 @requestmapping("/getlist")
 @responsebody
 public list<staffbo> getalllist(){
  list<staffbo> stafflist=null;
  try {
   stafflist = staffservice.queryallstafflist();
  } catch (exception e) {
   logger.error("查詢失敗");
  }
  return stafflist;
 }
}
</staffbo></staffbo>

e. 重點來了–應用的啟動入口application.java

這個java類最好放到和其他層級同級的根目錄中,這里就是com.zlf下,因為這個類的注解@springbootapplication會默認掃描與它同級目錄的其他文件。這樣才能完成注入等操作。如果你把它放到了和其他層的代碼一樣的級別中,則要用這種注解才行。

比如mianapplication下的application.java,就是我說的另一種放到和其他層同級的結構中的情形。

springboot配置內存數據庫H2教程詳解

它應該如何配置才能正常啟動呢?

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package mainapplication;
import org.springframework.boot.springapplication;
import org.springframework.boot.autoconfigure.springbootapplication;
import org.springframework.context.annotation.componentscan;
import org.springframework.stereotype.controller;
import org.springframework.web.bind.annotation.requestmapping;
/**
 * spring boot建議將我們main方法所在的這個主要的配置類配置在根包名下。
 *
 * @author administrator
 *
 *
 * @springbootapplication是spring boot提供的注解,他相當于加上如下注解:
 * @configuration,表明application是一個spring的配置對象,用于配置spring應用上下文。
 * @enableautoconfiguration,spring boot會根據類路徑(classpath)以及一些屬性值來自動完成一些配置行為,例如:開發基于spring
 *  mvc的web應用,需要在配置中加上
 * @enablewebmvc直接來激活一些默認的web配置, 一旦spring boot發現運行時類路徑上包含了 spring-webmvc
 *        依賴,它會自動的完成一個web應用的基本配置
 *        ——例如配置dispatcherservlet等等。
 * @componenscan告知spring應用從什么位置去發現spring構件(@component, @service,
 *              @configuration)等等
 */
@springbootapplication
@controller
// @restcontroller因為我們例子是寫一個web應用,因此寫的這個注解,這個注解相當于同時添加@controller和@responsebody注解
// @enableautoconfiguration// spring boot會自動根據你jar包的依賴來自動配置項目的數據源依賴
@componentscan(basepackages = { "controller", "service", "dao" })
// @componentscan路徑被默認設置為samplecontroller的同名package,也就是該package下的所有@controller
// ,@service , @component, @repository都會被實例化后并加入spring context中。這也是為什么要把這個類最好放到與其他包同級目錄 的原因了。
public class application {
 @requestmapping("")
 public string home() {
  // return "xiaozhang ,hello world!";
  return "/index";
 }
 public static void main(string[] args) {
  // 啟動spring boot項目最簡單的方法就是執行下面的方法
  springapplication.run(application.class);
 }
}

這樣就完成了測試代碼的簡單開發。在application.java中右鍵run as java application ,啟動程序。效果如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
. ____   _   __ _ _
 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/ ___)| |_)| | | | | || (_| | ) ) ) )
 ' |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: spring boot ::  (v1.4.3.release)
2017-07-05 20:50:07.579 info 5956 --- [   main] com.zlf.application      : starting application on pc-itwzhanglf02 with pid 5956 (e:\workspace\tsqa_springboot2_hibernate_jpa\target\classes started by administrator in e:\workspace\tsqa_springboot2_hibernate_jpa)
2017-07-05 20:50:07.579 info 5956 --- [   main] com.zlf.application      : no active profile set, falling back to default profiles: default
2017-07-05 20:50:07.657 info 5956 --- [   main] ationconfigembeddedwebapplicationcontext : refreshing org.springframework.boot.context.embedded.annotationconfigembeddedwebapplicationcontext@50103bfb: startup date [wed jul 05 20:50:07 cst 2017]; root of context hierarchy
2017-07-05 20:50:09.655 info 5956 --- [   main] trationdelegate$beanpostprocessorchecker : bean 'org.springframework.transaction.annotation.proxytransactionmanagementconfiguration' of type [class org.springframework.transaction.annotation.proxytransactionmanagementconfiguration$$enhancerbyspringcglib$$c3c549d9] is not eligible for getting processed by all beanpostprocessors (for example: not eligible for auto-proxying)
2017-07-05 20:50:10.094 info 5956 --- [   main] s.b.c.e.t.tomcatembeddedservletcontainer : tomcat initialized with port(s): 8080 (http)
2017-07-05 20:50:10.110 info 5956 --- [   main] o.apache.catalina.core.standardservice : starting service tomcat
2017-07-05 20:50:10.110 info 5956 --- [   main] org.apache.catalina.core.standardengine : starting servlet engine: apache tomcat/7.0.72
2017-07-05 20:50:10.297 info 5956 --- [ost-startstop-1] org.apache.catalina.startup.tldconfig : at least one jar was scanned for tlds yet contained no tlds. enable debug logging for this logger for a complete list of jars that were scanned but no tlds were found in them. skipping unneeded jars during scanning can improve startup time and jsp compilation time.
2017-07-05 20:50:10.297 info 5956 --- [ost-startstop-1] o.a.c.c.c.[tomcat].[localhost].[/]  : initializing spring embedded webapplicationcontext
2017-07-05 20:50:10.297 info 5956 --- [ost-startstop-1] o.s.web.context.contextloader   : root webapplicationcontext: initialization completed in 2655 ms
2017-07-05 20:50:10.540 info 5956 --- [ost-startstop-1] o.s.b.w.servlet.servletregistrationbean : mapping servlet: 'dispatcherservlet' to [/]
2017-07-05 20:50:10.540 info 5956 --- [ost-startstop-1] o.s.b.w.servlet.servletregistrationbean : mapping servlet: 'webservlet' to [/h2-console/*]
2017-07-05 20:50:10.540 info 5956 --- [ost-startstop-1] o.s.b.w.servlet.filterregistrationbean : mapping filter: 'characterencodingfilter' to: [/*]
2017-07-05 20:50:10.540 info 5956 --- [ost-startstop-1] o.s.b.w.servlet.filterregistrationbean : mapping filter: 'hiddenhttpmethodfilter' to: [/*]
2017-07-05 20:50:10.540 info 5956 --- [ost-startstop-1] o.s.b.w.servlet.filterregistrationbean : mapping filter: 'httpputformcontentfilter' to: [/*]
2017-07-05 20:50:10.540 info 5956 --- [ost-startstop-1] o.s.b.w.servlet.filterregistrationbean : mapping filter: 'requestcontextfilter' to: [/*]
2017-07-05 20:50:10.961 info 5956 --- [   main] o.s.jdbc.datasource.init.scriptutils  : executing sql script from class path resource [schema.sql]
2017-07-05 20:50:10.976 info 5956 --- [   main] o.s.jdbc.datasource.init.scriptutils  : executed sql script from class path resource [schema.sql] in 15 ms.
2017-07-05 20:50:10.992 info 5956 --- [   main] o.s.jdbc.datasource.init.scriptutils  : executing sql script from class path resource [data.sql]
2017-07-05 20:50:10.992 info 5956 --- [   main] o.s.jdbc.datasource.init.scriptutils  : executed sql script from class path resource [data.sql] in 0 ms.
2017-07-05 20:50:11.118 info 5956 --- [   main] j.localcontainerentitymanagerfactorybean : building jpa container entitymanagerfactory for persistence unit 'default'
2017-07-05 20:50:11.133 info 5956 --- [   main] o.hibernate.jpa.internal.util.loghelper : hhh000204: processing persistenceunitinfo [
 name: default
 ...]
2017-07-05 20:50:11.227 info 5956 --- [   main] org.hibernate.version     : hhh000412: hibernate core {5.0.11.final}
2017-07-05 20:50:11.227 info 5956 --- [   main] org.hibernate.cfg.environment   : hhh000206: hibernate.properties not found
2017-07-05 20:50:11.227 info 5956 --- [   main] org.hibernate.cfg.environment   : hhh000021: bytecode provider name : javassist
2017-07-05 20:50:11.273 info 5956 --- [   main] o.hibernate.annotations.common.version : hcann000001: hibernate commons annotations {5.0.1.final}
2017-07-05 20:50:11.398 info 5956 --- [   main] org.hibernate.dialect.dialect   : hhh000400: using dialect: org.hibernate.dialect.h2dialect
2017-07-05 20:50:11.793 info 5956 --- [   main] org.hibernate.tool.hbm2ddl.schemaupdate : hhh000228: running hbm2ddl schema update
2017-07-05 20:50:11.840 info 5956 --- [   main] j.localcontainerentitymanagerfactorybean : initialized jpa entitymanagerfactory for persistence unit 'default'
2017-07-05 20:50:12.536 info 5956 --- [   main] s.w.s.m.m.a.requestmappinghandleradapter : looking for @controlleradvice: org.springframework.boot.context.embedded.annotationconfigembeddedwebapplicationcontext@50103bfb: startup date [wed jul 05 20:50:07 cst 2017]; root of context hierarchy
2017-07-05 20:50:12.626 info 5956 --- [   main] s.w.s.m.m.a.requestmappinghandlermapping : mapped "{[]}" onto public java.lang.string com.zlf.application.home()
2017-07-05 20:50:12.629 info 5956 --- [   main] s.w.s.m.m.a.requestmappinghandlermapping : mapped "{[/staff/getlist],produces=[application/json;charset=utf-8]}" onto public java.util.list<com.zlf.bo.staffbo> com.zlf.controller.staffcontroller.getalllist()
2017-07-05 20:50:12.631 info 5956 --- [   main] s.w.s.m.m.a.requestmappinghandlermapping : mapped "{[/error]}" onto public org.springframework.http.responseentity<java.util.map<java.lang.string, java.lang.object="">> org.springframework.boot.autoconfigure.web.basicerrorcontroller.error(javax.servlet.http.httpservletrequest)
2017-07-05 20:50:12.632 info 5956 --- [   main] s.w.s.m.m.a.requestmappinghandlermapping : mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.modelandview org.springframework.boot.autoconfigure.web.basicerrorcontroller.errorhtml(javax.servlet.http.httpservletrequest,javax.servlet.http.httpservletresponse)
2017-07-05 20:50:12.670 info 5956 --- [   main] o.s.w.s.handler.simpleurlhandlermapping : mapped url path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.resourcehttprequesthandler]
2017-07-05 20:50:12.670 info 5956 --- [   main] o.s.w.s.handler.simpleurlhandlermapping : mapped url path [/**] onto handler of type [class org.springframework.web.servlet.resource.resourcehttprequesthandler]
2017-07-05 20:50:12.733 info 5956 --- [   main] o.s.w.s.handler.simpleurlhandlermapping : mapped url path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.resourcehttprequesthandler]
2017-07-05 20:50:13.232 info 5956 --- [   main] o.s.j.e.a.annotationmbeanexporter  : registering beans for jmx exposure on startup
2017-07-05 20:50:13.310 info 5956 --- [   main] s.b.c.e.t.tomcatembeddedservletcontainer : tomcat started on port(s): 8080 (http)
2017-07-05 20:50:13.310 info 5956 --- [   main] com.zlf.application      : started application in 6.213 seconds (jvm running for 6.478)
</java.util.map<java.lang.string,></com.zlf.bo.staffbo>

打開瀏覽器,訪問地址:http://localhost:8080/staff/getlist,可以看到初始化的數據都出來了。

springboot配置內存數據庫H2教程詳解

然后訪問地址:http://localhost:8080/h2-console 出現下面的h2 console界面

springboot配置內存數據庫H2教程詳解

在登陸頁面輸入在application.properties中配置的h2數據庫信息,登陸后可以看到左側已經有我們初始化的表,查詢數據,也能看到數據應初始化進來。則證明成功了!

springboot配置內存數據庫H2教程詳解

以上所述是小編給大家介紹的springboot配置內存數據庫h2教程詳解,希望對大家有所幫助!

原文鏈接:http://www.2cto.com/database/201707/654694.html

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 男女小网站 | 久久久久久久久久久福利观看 | 国产欧美日韩一级大片 | 色综合久久88色综合天天 | 国产成人黄色网址 | 精品一区二区三区四区五区 | 色综合网址 | 日本在线视频一区二区 | 免费污视频在线 | 久久这里有精品视频 | 一区高清| 午夜视频在线免费看 | 看av网址| 最近韩国日本免费高清观看 | 久久中文字幕电影 | 中国大陆高清aⅴ毛片 | 国产精品久久久久久久久晋中 | 天天天操操操 | 日韩成人一区二区 | 99久久免费精品国产男女性高好 | 综合亚洲精品 | 欧美自拍视频 | 欧美日韩精品电影 | 日韩在线观看中文 | 亚洲福利影院 | 一区二区精品在线视频 | 欧美亚洲激情 | 久久久久久久国产精品 | 蜜桃一区 | 一区二区三区高清 | 涩涩999 | 超级黄色毛片 | 日韩综合网 | 久草在线视频免费播放 | 日韩成人免费 | 中文字幕一区二区在线观看 | 国产精品视频入口 | 毛片视频免费播放 | 91在线资源 | 久久久久久国产精品高清 | 成人男女啪啪免费观软件 |