首页 > 数据库技术 > 详细

关系型数据库的 简单使用

时间:2020-03-05 15:01:00      阅读:58      评论:0      收藏:0      [点我收藏+]

特点

运行速度快  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 的控制台

输入 http://localhost:8080/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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!