Example Analysis of SpringBoot Integrated in-memory Database hsqldb
This article introduces you SpringBoot integrated memory database hsqldb example analysis, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Integrate the main memory database hsqldb. SpringBoot.
Why
Such as H2, hsqldb, derby, sqlite, such as in-memory database, small and lovely, do small server demo program, very easy to use. The most important feature is that you do not need to install another database.
Operation steps
Modify the pom.xml file
Org.hsqldb hsqldb
Modify the project configuration file application.yml
Spring: datasource: username: hsp password: 123456 url: jdbc:hsqldb:mem://localhost/blogdb;shutdown=true driver-class-name: org.hsqldb.jdbcDriver schema: classpath:schema.sql data: classpath:data.sql initialization-mode: always continue-on-error: true
Add initialization data file
Table creation script: schema.sql
CREATE TABLE blog (id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1) NOT NULL PRIMARY KEY, title varchar (255) DEFAULT NULL,)
Import data script: data.sql
Insert into blog (id,title) values (1pm 'Peanut skin programming blog')
Startup class: HspApplication
MapperScan ({"cn.hsp.blog"}) @ SpringBootApplicationpublic class HspApplication {public static void main (String [] args) {SpringApplication.run (HspApplication.class, args);}}
Controller class: BlogController
RestController@RequestMapping ("/ blog") public class BlogController {@ Autowired private BlogMapper blogMapper; @ GetMapping (value= "/ query") public List query () {return blogMapper.query ();}}
Mapper class: BlogMapper
Repositorypublic interface BlogMapper {@ Select (value = "select * from blog") List query ();}
Data bean:Blog
@ Datapublic class Blog {private int id; private String title;} project screenshot
Running
Just run HspApplication.
On the SpringBoot integrated memory database hsqldb example analysis is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.