本文简单介绍一下spring boot+JPA实现简单的增删改查功能
一、项目结构简述
二、搭建spring boot+jap环境
三、代码示例
四、spring boot的启动方式
一、项目结构简述
1、项目的目录结构注意点
问题说明:
①使用内置服务器启动springboot
项目时,会从@SpringBootApplication
修饰类所在的包开始,加载当前包和所有子包下的类,将由@Component
@Repository
@Service
@Controller
修饰的类交由spring
进行管理;
②如上图,项目中的启动类为ApplacationController,他与其他层代码的处于同一个包下面,项目启动时会扫描到其他层的代码,就不会报如下错误(如果启动类所在的包与其它层代码所在的包处于平级目录中,即使启动类使用了@ComponentScan注解一样会报下面的错误):
Action: Consider defining a bean of type 'cn.oschina.dao.PersonRespority' in your configuration.
二、搭建spring boot+jap环境
1、pom.xml文件
<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>cn.oschaina</groupId> <artifactId>simple-spring-boot</artifactId> <version>0.0.1-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starte