Java Bean和SQL异常

Java Bean和SQL异常,java,spring,hibernate,spring-mvc,Java,Spring,Hibernate,Spring Mvc,我正在使用SpringBoot构建一个简单的CRUD操作,MySQL和Hibernate在这个操作中需要帮助。在谷歌搜索了很多次,StackOverflow没有找到合适的解决方案 问题:服务器时区值“未知”无法识别或表示多个时区。如果要利用时区支持,必须将服务器或JDBC驱动程序(通过serverTimezoneconfiguration属性)配置为使用更具体的时区值 com.mysql.cj.core.exceptions.InvalidConnectionAttributeException

我正在使用SpringBoot构建一个简单的CRUD操作,MySQL和Hibernate在这个操作中需要帮助。在谷歌搜索了很多次,StackOverflow没有找到合适的解决方案

问题:服务器时区值“未知”无法识别或表示多个时区。如果要利用时区支持,必须将服务器或JDBC驱动程序(通过
serverTimezone
configuration属性)配置为使用更具体的时区值

com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value 'unknown' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_91]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_91]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_91]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_91]
Unable to open JDBC Connection for DDL execution
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection(DdlTransactionIsolatorNonJtaImpl.java:69) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.jdbcStatement(GenerationTargetToDatabase.java:77) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:53) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:359) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:241) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:154) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:126) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:145) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:73) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:316) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:469) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1259) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]

[PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution


Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution


 Error creating bean with name 'digitalEmployeeRepo' defined in com.eg.demo.repository.DigitalEmployeeRepo defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
服务器时区值“未知”无法识别或表示多个时区。如果要利用时区支持,必须配置服务器或JDBC驱动程序(通过serverTimezone配置属性)以使用更具体的时区值

com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value 'unknown' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_91]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_91]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_91]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_91]
Unable to open JDBC Connection for DDL execution
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection(DdlTransactionIsolatorNonJtaImpl.java:69) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.jdbcStatement(GenerationTargetToDatabase.java:77) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:53) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:359) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.dropFromMetadata(SchemaDropperImpl.java:241) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.performDrop(SchemaDropperImpl.java:154) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:126) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.internal.SchemaDropperImpl.doDrop(SchemaDropperImpl.java:112) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:145) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:73) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:316) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:469) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1259) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]

[PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution


Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution


 Error creating bean with name 'digitalEmployeeRepo' defined in com.eg.demo.repository.DigitalEmployeeRepo defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
。。。。。。。。。。。 回购

package com.eg.demo.controller;

import com.eg.demo.model.DigitalEmployee;
import com.eg.demo.service.DigitalEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.List;

public class DigitalController {
    @Autowired
    DigitalEmployeeService digitalEmployeeService;


    @RequestMapping(value = "/DigitalEmployee/", method = RequestMethod.GET)
    public ResponseEntity<List<DigitalEmployee>> listAllUsers() {
        List<DigitalEmployee> digitalEmployees = digitalEmployeeService.allEmployee();
        if (digitalEmployees.isEmpty()) {
            return new ResponseEntity(HttpStatus.NO_CONTENT);

        }
        return new ResponseEntity<List<DigitalEmployee>>(digitalEmployees, HttpStatus.OK);
    }

    // -------------------Retrieve Single User------------------------------------------

    @RequestMapping(value = "/digitalEmployee/{id}", method = RequestMethod.GET)
    public ResponseEntity<?> getEmployee(@PathVariable("id") long id) {

        DigitalEmployee digitalEmployee = digitalEmployeeService.findById(id);

        return new ResponseEntity<DigitalEmployee>(digitalEmployee, HttpStatus.OK);
    }

    // -------------------Create a User-------------------------------------------

    @RequestMapping(value = "/digitalEmployee/", method = RequestMethod.POST)
    public ResponseEntity<?> createEmployee(@RequestBody DigitalEmployee digitalEmployee) {
        digitalEmployeeService.save(digitalEmployee);
        return new ResponseEntity<DigitalEmployee>(HttpStatus.CREATED);
    }

    // ------------------- Update a User ------------------------------------------------

    @RequestMapping(value = "/digitalEmployee/{id}", method = RequestMethod.PUT)
    public ResponseEntity<?> updateEmployee(@PathVariable("id") long id, @RequestBody DigitalEmployee digitalEmployee) {
        DigitalEmployee currentEmployee = digitalEmployeeService.findById(id);

        currentEmployee.setName(digitalEmployee.getName());
        digitalEmployeeService.update(currentEmployee);
        return new ResponseEntity<DigitalEmployee>(currentEmployee, HttpStatus.OK);
    }

    // ------------------- Delete a User-----------------------------------------

    @RequestMapping(value = "/digitalEmployee/{id}", method = RequestMethod.DELETE)
    public ResponseEntity<?> deleteEmployee(@PathVariable("id") long id) {
        DigitalEmployee digitalEmployee = digitalEmployeeService.findById(id);
        digitalEmployeeService.deleteById(id);
        return new ResponseEntity<DigitalEmployee>(HttpStatus.NO_CONTENT);
    }

    // ------------------- Delete All Users-----------------------------

    @RequestMapping(value = "/DigitalEmployee/", method = RequestMethod.DELETE)
    public ResponseEntity<DigitalEmployee> deleteAll() {

        digitalEmployeeService.deleteAll();
        return new ResponseEntity<DigitalEmployee>(HttpStatus.NO_CONTENT);
    }

}
package com.eg.demo.model;

import javax.persistence.*;

@Entity
@Table(name = "DigitalEmployee")
public class DigitalEmployee {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column
    private String name;

    public DigitalEmployee() {
    }

    public DigitalEmployee(Long id, String name) {
        this.id = id;
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
package com.eg.demo.repository;

import com.eg.demo.model.DigitalEmployee;
import org.springframework.data.repository.CrudRepository;

public interface DigitalEmployeeRepo extends CrudRepository<DigitalEmployee, Long> {
}
package com.eg.demo.service;

import com.eg.demo.model.DigitalEmployee;

import java.util.List;
import java.util.Optional;

public interface DigitalEmployeeService {
    void save(DigitalEmployee digitalEmployee);
    void update(DigitalEmployee digitalEmployee);
    void deleteAll();
    void deleteById(Long id);
    DigitalEmployee findById(Long id);
    List<DigitalEmployee> allEmployee();

}
package com.eg.demo.service;

import com.eg.demo.model.DigitalEmployee;
import com.eg.demo.repository.DigitalEmployeeRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DigitalEmployeeServiceImpl implements DigitalEmployeeService {

    @Autowired
    DigitalEmployeeRepo digitalEmployeeRepo;

    public void save(DigitalEmployee digitalEmployee) {
        digitalEmployeeRepo.save(digitalEmployee);
    }

    public void update(DigitalEmployee digitalEmployee) {
        save(digitalEmployee);
    }

    public void deleteAll() {
         digitalEmployeeRepo.deleteAll();
    }

    public void deleteById(Long id) {
        digitalEmployeeRepo.deleteById(id);
    }

    public DigitalEmployee findById(Long id) {
        return digitalEmployeeRepo.findById(id).get();
    }

    public List<DigitalEmployee> allEmployee() {
        return (List<DigitalEmployee>) digitalEmployeeRepo.findAll();
    }
}
package com.eg.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


//@Configuration
@SpringBootApplication(scanBasePackages = "com.*")
@EnableSwagger2
//@EnableAutoConfiguration
//@ComponentScan("com.eg.demo")

public class DemoApplication {

    public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
    }
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }
}
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql=true
spring.datasource.url=jdbc:mysql://localhost:3306/digital
spring.datasource.username=root
spring.datasource.password=
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.format_sql=true
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.eg</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>

        <!--<dependency>-->
            <!--<groupId>io.springfox</groupId>-->
            <!--<artifactId>springfox-swagger2</artifactId>-->
            <!--<version>2.9.2</version>-->
        <!--</dependency>-->



        <!--<dependency>-->
            <!--<groupId>io.springfox</groupId>-->
            <!--<artifactId>springfox-swagger2</artifactId>-->
            <!--<version>2.9.2</version>-->
        <!--</dependency>-->

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-spring-web</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-oas</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-hateoas</artifactId>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>io.springfox</groupId>-->
            <!--<artifactId>springfox-swagger-ui</artifactId>-->
            <!--<version>2.9.2</version>-->
        <!--</dependency>-->
        <!---->
        <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>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>6.0.3</version>
        </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>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
。。。。。。。。。。。。。。。。 应用性能

package com.eg.demo.controller;

import com.eg.demo.model.DigitalEmployee;
import com.eg.demo.service.DigitalEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.List;

public class DigitalController {
    @Autowired
    DigitalEmployeeService digitalEmployeeService;


    @RequestMapping(value = "/DigitalEmployee/", method = RequestMethod.GET)
    public ResponseEntity<List<DigitalEmployee>> listAllUsers() {
        List<DigitalEmployee> digitalEmployees = digitalEmployeeService.allEmployee();
        if (digitalEmployees.isEmpty()) {
            return new ResponseEntity(HttpStatus.NO_CONTENT);

        }
        return new ResponseEntity<List<DigitalEmployee>>(digitalEmployees, HttpStatus.OK);
    }

    // -------------------Retrieve Single User------------------------------------------

    @RequestMapping(value = "/digitalEmployee/{id}", method = RequestMethod.GET)
    public ResponseEntity<?> getEmployee(@PathVariable("id") long id) {

        DigitalEmployee digitalEmployee = digitalEmployeeService.findById(id);

        return new ResponseEntity<DigitalEmployee>(digitalEmployee, HttpStatus.OK);
    }

    // -------------------Create a User-------------------------------------------

    @RequestMapping(value = "/digitalEmployee/", method = RequestMethod.POST)
    public ResponseEntity<?> createEmployee(@RequestBody DigitalEmployee digitalEmployee) {
        digitalEmployeeService.save(digitalEmployee);
        return new ResponseEntity<DigitalEmployee>(HttpStatus.CREATED);
    }

    // ------------------- Update a User ------------------------------------------------

    @RequestMapping(value = "/digitalEmployee/{id}", method = RequestMethod.PUT)
    public ResponseEntity<?> updateEmployee(@PathVariable("id") long id, @RequestBody DigitalEmployee digitalEmployee) {
        DigitalEmployee currentEmployee = digitalEmployeeService.findById(id);

        currentEmployee.setName(digitalEmployee.getName());
        digitalEmployeeService.update(currentEmployee);
        return new ResponseEntity<DigitalEmployee>(currentEmployee, HttpStatus.OK);
    }

    // ------------------- Delete a User-----------------------------------------

    @RequestMapping(value = "/digitalEmployee/{id}", method = RequestMethod.DELETE)
    public ResponseEntity<?> deleteEmployee(@PathVariable("id") long id) {
        DigitalEmployee digitalEmployee = digitalEmployeeService.findById(id);
        digitalEmployeeService.deleteById(id);
        return new ResponseEntity<DigitalEmployee>(HttpStatus.NO_CONTENT);
    }

    // ------------------- Delete All Users-----------------------------

    @RequestMapping(value = "/DigitalEmployee/", method = RequestMethod.DELETE)
    public ResponseEntity<DigitalEmployee> deleteAll() {

        digitalEmployeeService.deleteAll();
        return new ResponseEntity<DigitalEmployee>(HttpStatus.NO_CONTENT);
    }

}
package com.eg.demo.model;

import javax.persistence.*;

@Entity
@Table(name = "DigitalEmployee")
public class DigitalEmployee {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column
    private String name;

    public DigitalEmployee() {
    }

    public DigitalEmployee(Long id, String name) {
        this.id = id;
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
package com.eg.demo.repository;

import com.eg.demo.model.DigitalEmployee;
import org.springframework.data.repository.CrudRepository;

public interface DigitalEmployeeRepo extends CrudRepository<DigitalEmployee, Long> {
}
package com.eg.demo.service;

import com.eg.demo.model.DigitalEmployee;

import java.util.List;
import java.util.Optional;

public interface DigitalEmployeeService {
    void save(DigitalEmployee digitalEmployee);
    void update(DigitalEmployee digitalEmployee);
    void deleteAll();
    void deleteById(Long id);
    DigitalEmployee findById(Long id);
    List<DigitalEmployee> allEmployee();

}
package com.eg.demo.service;

import com.eg.demo.model.DigitalEmployee;
import com.eg.demo.repository.DigitalEmployeeRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DigitalEmployeeServiceImpl implements DigitalEmployeeService {

    @Autowired
    DigitalEmployeeRepo digitalEmployeeRepo;

    public void save(DigitalEmployee digitalEmployee) {
        digitalEmployeeRepo.save(digitalEmployee);
    }

    public void update(DigitalEmployee digitalEmployee) {
        save(digitalEmployee);
    }

    public void deleteAll() {
         digitalEmployeeRepo.deleteAll();
    }

    public void deleteById(Long id) {
        digitalEmployeeRepo.deleteById(id);
    }

    public DigitalEmployee findById(Long id) {
        return digitalEmployeeRepo.findById(id).get();
    }

    public List<DigitalEmployee> allEmployee() {
        return (List<DigitalEmployee>) digitalEmployeeRepo.findAll();
    }
}
package com.eg.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


//@Configuration
@SpringBootApplication(scanBasePackages = "com.*")
@EnableSwagger2
//@EnableAutoConfiguration
//@ComponentScan("com.eg.demo")

public class DemoApplication {

    public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
    }
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }
}
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql=true
spring.datasource.url=jdbc:mysql://localhost:3306/digital
spring.datasource.username=root
spring.datasource.password=
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.format_sql=true
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.eg</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>

        <!--<dependency>-->
            <!--<groupId>io.springfox</groupId>-->
            <!--<artifactId>springfox-swagger2</artifactId>-->
            <!--<version>2.9.2</version>-->
        <!--</dependency>-->



        <!--<dependency>-->
            <!--<groupId>io.springfox</groupId>-->
            <!--<artifactId>springfox-swagger2</artifactId>-->
            <!--<version>2.9.2</version>-->
        <!--</dependency>-->

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-spring-web</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-oas</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-hateoas</artifactId>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>io.springfox</groupId>-->
            <!--<artifactId>springfox-swagger-ui</artifactId>-->
            <!--<version>2.9.2</version>-->
        <!--</dependency>-->
        <!---->
        <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>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>6.0.3</version>
        </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>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
。。。。。。。。。。。。。。。。。。。。。。。 聚甲醛

package com.eg.demo.controller;

import com.eg.demo.model.DigitalEmployee;
import com.eg.demo.service.DigitalEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.List;

public class DigitalController {
    @Autowired
    DigitalEmployeeService digitalEmployeeService;


    @RequestMapping(value = "/DigitalEmployee/", method = RequestMethod.GET)
    public ResponseEntity<List<DigitalEmployee>> listAllUsers() {
        List<DigitalEmployee> digitalEmployees = digitalEmployeeService.allEmployee();
        if (digitalEmployees.isEmpty()) {
            return new ResponseEntity(HttpStatus.NO_CONTENT);

        }
        return new ResponseEntity<List<DigitalEmployee>>(digitalEmployees, HttpStatus.OK);
    }

    // -------------------Retrieve Single User------------------------------------------

    @RequestMapping(value = "/digitalEmployee/{id}", method = RequestMethod.GET)
    public ResponseEntity<?> getEmployee(@PathVariable("id") long id) {

        DigitalEmployee digitalEmployee = digitalEmployeeService.findById(id);

        return new ResponseEntity<DigitalEmployee>(digitalEmployee, HttpStatus.OK);
    }

    // -------------------Create a User-------------------------------------------

    @RequestMapping(value = "/digitalEmployee/", method = RequestMethod.POST)
    public ResponseEntity<?> createEmployee(@RequestBody DigitalEmployee digitalEmployee) {
        digitalEmployeeService.save(digitalEmployee);
        return new ResponseEntity<DigitalEmployee>(HttpStatus.CREATED);
    }

    // ------------------- Update a User ------------------------------------------------

    @RequestMapping(value = "/digitalEmployee/{id}", method = RequestMethod.PUT)
    public ResponseEntity<?> updateEmployee(@PathVariable("id") long id, @RequestBody DigitalEmployee digitalEmployee) {
        DigitalEmployee currentEmployee = digitalEmployeeService.findById(id);

        currentEmployee.setName(digitalEmployee.getName());
        digitalEmployeeService.update(currentEmployee);
        return new ResponseEntity<DigitalEmployee>(currentEmployee, HttpStatus.OK);
    }

    // ------------------- Delete a User-----------------------------------------

    @RequestMapping(value = "/digitalEmployee/{id}", method = RequestMethod.DELETE)
    public ResponseEntity<?> deleteEmployee(@PathVariable("id") long id) {
        DigitalEmployee digitalEmployee = digitalEmployeeService.findById(id);
        digitalEmployeeService.deleteById(id);
        return new ResponseEntity<DigitalEmployee>(HttpStatus.NO_CONTENT);
    }

    // ------------------- Delete All Users-----------------------------

    @RequestMapping(value = "/DigitalEmployee/", method = RequestMethod.DELETE)
    public ResponseEntity<DigitalEmployee> deleteAll() {

        digitalEmployeeService.deleteAll();
        return new ResponseEntity<DigitalEmployee>(HttpStatus.NO_CONTENT);
    }

}
package com.eg.demo.model;

import javax.persistence.*;

@Entity
@Table(name = "DigitalEmployee")
public class DigitalEmployee {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column
    private String name;

    public DigitalEmployee() {
    }

    public DigitalEmployee(Long id, String name) {
        this.id = id;
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
package com.eg.demo.repository;

import com.eg.demo.model.DigitalEmployee;
import org.springframework.data.repository.CrudRepository;

public interface DigitalEmployeeRepo extends CrudRepository<DigitalEmployee, Long> {
}
package com.eg.demo.service;

import com.eg.demo.model.DigitalEmployee;

import java.util.List;
import java.util.Optional;

public interface DigitalEmployeeService {
    void save(DigitalEmployee digitalEmployee);
    void update(DigitalEmployee digitalEmployee);
    void deleteAll();
    void deleteById(Long id);
    DigitalEmployee findById(Long id);
    List<DigitalEmployee> allEmployee();

}
package com.eg.demo.service;

import com.eg.demo.model.DigitalEmployee;
import com.eg.demo.repository.DigitalEmployeeRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DigitalEmployeeServiceImpl implements DigitalEmployeeService {

    @Autowired
    DigitalEmployeeRepo digitalEmployeeRepo;

    public void save(DigitalEmployee digitalEmployee) {
        digitalEmployeeRepo.save(digitalEmployee);
    }

    public void update(DigitalEmployee digitalEmployee) {
        save(digitalEmployee);
    }

    public void deleteAll() {
         digitalEmployeeRepo.deleteAll();
    }

    public void deleteById(Long id) {
        digitalEmployeeRepo.deleteById(id);
    }

    public DigitalEmployee findById(Long id) {
        return digitalEmployeeRepo.findById(id).get();
    }

    public List<DigitalEmployee> allEmployee() {
        return (List<DigitalEmployee>) digitalEmployeeRepo.findAll();
    }
}
package com.eg.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


//@Configuration
@SpringBootApplication(scanBasePackages = "com.*")
@EnableSwagger2
//@EnableAutoConfiguration
//@ComponentScan("com.eg.demo")

public class DemoApplication {

    public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
    }
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }
}
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql=true
spring.datasource.url=jdbc:mysql://localhost:3306/digital
spring.datasource.username=root
spring.datasource.password=
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.format_sql=true
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.eg</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>

        <!--<dependency>-->
            <!--<groupId>io.springfox</groupId>-->
            <!--<artifactId>springfox-swagger2</artifactId>-->
            <!--<version>2.9.2</version>-->
        <!--</dependency>-->



        <!--<dependency>-->
            <!--<groupId>io.springfox</groupId>-->
            <!--<artifactId>springfox-swagger2</artifactId>-->
            <!--<version>2.9.2</version>-->
        <!--</dependency>-->

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-spring-web</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-oas</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-hateoas</artifactId>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>io.springfox</groupId>-->
            <!--<artifactId>springfox-swagger-ui</artifactId>-->
            <!--<version>2.9.2</version>-->
        <!--</dependency>-->
        <!---->
        <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>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>6.0.3</version>
        </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>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

4.0.0
org.springframework.boot
spring启动程序父级
2.3.4.1发布
com.eg
演示
0.0.1-快照
演示
SpringBoot的演示项目
11
伊奥·斯普林福克斯
springfox-Swagger 2
3.0.0
伊奥·斯普林福克斯
springfox招摇过市用户界面
3.0.0
伊奥·斯普林福克斯
SpringfoxSpringWeb
3.0.0
伊奥·斯普林福克斯
斯普林福克斯绿洲酒店
3.0.0
伊奥·斯普林福克斯
springfox启动程序
3.0.0
org.springframework.boot
弹簧靴启动器hateoas
org.springframework.boot
spring引导启动器数据jpa
org.springframework.boot
SpringBootStarterWeb
mysql
mysql连接器java
6.0.3
org.springframework.boot
弹簧起动试验
测试
org.junit.vintage
朱尼特老式发动机
org.springframework.boot
springbootmaven插件
org.apache.maven.plugins
maven编译器插件
1.8
1.8

使用datasource url属性配置时区,如下所示
url:jdbc:mysql://127.0.0.1:3306/test?&serverTimezone=Asia/Shanghaispring.datasource.url=jdbc:mysql://localhost:3306/digital?serverTimezone=UTC

我更推荐在这里使用UTC,否则最终会出现难以调试的问题。我认为驱动程序类名应该是
com.mysql.cj.jdbc.driver