2019獨角獸企業重金招聘Python工程師標準>>>
我前面的帖子有介紹spring boot的簡單搭建,現在我再講講spring boot的簡單配置
首先,項目結構
啟動類
@RestController? ? 注解相當于@ResponseBody + @Controller合在一起的作用。
@SpringBootApplication? ? ?項目創建默認的注解,解釋的話有點多直接貼網址大家自己進去了解?? https://blog.csdn.net/dyangel2013/article/details/79775122? ??
@EnableAutoConfiguration? ? ?詳細的自己去了解一下? ?https://blog.csdn.net/zxc123e/article/details/80222967
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包下不需要什么注解
我倒是了解到現在可以加入
@Getter
@Setter
@ToString
可以讓你省略掉冗余的get? set 方法和toString方法
?
mapper包下是接口和mapper文件
接口依然不需要什么注解,mapper文件中需要注意的有一點
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>
很多注解我也不是很深入的理解,目前只能說是能夠運用,大家多多諒解不能詳細給大家解釋