我前面的帖子有介绍spring boot的简单搭建,如今我再讲讲spring boot的简单配置java
首先,项目结构mysql
启动类web
@RestController 注解至关于@ResponseBody + @Controller合在一块儿的做用。
@SpringBootApplication 项目建立默认的注解,解释的话有点多直接贴网址你们本身进去了解 https://blog.csdn.net/dyangel2013/article/details/79775122
@EnableAutoConfiguration 详细的本身去了解一下 https://blog.csdn.net/zxc123e/article/details/80222967spring
package com.example; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @SpringBootApplication @EnableAutoConfiguration public class BaiduditudemoApplication { public static void main(String[] args) { SpringApplication.run(BaiduditudemoApplication.class, args); } }
pojo包下不须要什么注解sql
我却是了解到如今能够加入apache
@Getter
@Setter
@ToStringmybatis
能够让你省略掉冗余的get set 方法和toString方法app
mapper包下是接口和mapper文件maven
接口依然不须要什么注解,mapper文件中须要注意的有一点spring-boot
1中是对应的接口位置
2中对应pojo实体类
service包下的结构
接口依然没有什么注解,service的实现类须要加入@service注解
也能够加上@Transactional事务处理的注解,事务处理在启动类也能够用另外一个注解加入
这是application.properties里的配置
spring.datasource.url=jdbc:mysql://localhost:3306/mpms spring.datasource.username=root spring.datasource.password=123 spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.jpa.database=mysql
最后就是pom文件了,固然pom文件确定不是最后才配置的,我只是放在最后说
<?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> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.3.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>baiduditudemo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>baiduditudemo</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> <!-- http --> <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcore</artifactId> <version>4.4.10</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.6</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
不少注解我也不是很深刻的理解,目前只能说是可以运用,你们多多谅解不能详细给你们解释