- IDEA选择spring initializer
- 项目类型选择Web
- pom依赖添加:web jpa mysql
- 此处url如果写错,比如mysql后冒号缺失,会出现以下错误:
org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Driver:com.mysql.jdbc.Driver@ac20bb4 returned null for URL:jdbc:mysq://localhost:3306/test?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
插入一条数据库纪录: INSERT INTO(大写) user(username,password) VALUES('zc','123')
- @Entity注解需要使用javax.persistance.x;非org.hibernate.anotation;
- setter/getter可使用lombok,需要在pom添加依赖
- @GetMapping("/{username}") @PathVariable("username")配合从RESTful风格URL中 获取username
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
- @Api:修饰整个类,用于描述controller类
- @ApiOperation:描述接口
- @ApiParam:描述参数
- @ApiModel:用对象来接收参数
- @ApiProperty
- @ApiResponse
- @ApiResponses
- @ApiIgnore:忽略该接口
- @ApiError
- @ApiParamImplicit
- @ApiParamsImplicit