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>
很多注解我也不是很深入的理解,目前只能说是能够运用,大家多多谅解不能详细给大家解释