特点
运行速度快 Java 编写的
1、引入相关的依赖
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
2、application.properties 中的日志
#用的是内存中的 数据库,名称是test #spring.datasource.url=jdbc:h2:mem:test #可以使用 本地文件的 spring.datasource.url=jdbc:h2:file:./db/h2-demo spring.datasource.driver-class-name=org.h2.Driver spring.datasource.username=sa spring.datasource.password=123456 spring.jpa.database-platform=org.hibernate.dialect.H2Dialect #后台管理的 地址 spring.h2.console.path=/h2 #数据库管理后台是否可用 可以用这里配置的 spring.h2.console.enabled=true #不打印 log spring.h2.console.settings.trace=false #是否可以远程访问 spring.h2.console.settings.web-allow-others=false
3、h2 的控制台
4、控制层
@RestController public class EmployController { @Autowired private EmployRep employRep; @RequestMapping("/list") public List<Employee> findAll(){ return employRep.findAll(); } @RequestMapping("/save") public Boolean save(){ Employee employee = new Employee(); employee.setId(12); employee.setName("ao"); employRep.save(employee); return Boolean.TRUE; }
5、看结果
原文:https://www.cnblogs.com/gaohq/p/12419704.html