从数据库

时间:2018-06-12 08:58:01

标签: java sql-server eclipse spring-boot jpa

我创建了一个Spring Boot项目,并希望与在Docker容器上运行的SQL Server 2017数据库进行通信。

在Eclipse中为模型类生成代码的最快方法是什么(Oxygen.2版本4.7.2)?

如果有帮助,我会将pom.xmlapplication.properties放在这里。

的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.blahblahblah</groupId>
    <artifactId>querytofile</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>querytofile</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.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-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <scope>runtime</scope>
        </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>

application.properties

spring.datasource.url=jdbc:sqlserver://localhost;databaseName=myDB
spring.datasource.username=sa
spring.datasource.password=BLAHBLAHBLAH
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.jpa.hibernate.ddl-auto = create-drop

更新:来自市场的快照

enter image description here

1 个答案:

答案 0 :(得分:1)

打开eclipse IDE:

转到&gt;帮助&gt; eclipse marketplace&gt;搜索JPA&gt;选择g9数据库导入如下。

plugin

重启eclipse IDE。

右键点击项目&gt;导入&gt;搜索导入数据库模型如下。

Import DB

提供必填字段并生成实体。