springboot 可以快速的和其他任何框架结合
1.jar包
spring-boot-starter-web
web 有了这个就可从页面上接受数据和springmvc类似 关联引入所有的spring ,springmvc的功能
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
spring-boot-starter-parent
springboot父级jar包,只有有了这个 才能是一个springboot项目
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
mybatis-spring-boot-starter
mybatis 相关jar包 关联引入mybatis mybatis-spring等等
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
spring-boot-starter-thymeleaf
使用转发功能
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
spring-boot-devtools
热部署工具 自动重启应用
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
ojdbc8
Oracle
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
mysql-connector-java
MySQL
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
lombok
Lombok插件 可以简化实体类的书写 可以通过对应的注解完成
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
spring-boot-starter-test
测试用的jar包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
自带插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--开启热部署工具-->
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
2.创建基本包结构
3.填充内容
pojo实体类
//注解是lombok插件提供的
@Getter
@Setter
@ToString
@EqualsAndHashCode
public class Users {
private Integer id;
private String name;
private String imgpath;
}
mapper接口,持久层
@Component
@Mapper
public interface UsersService {
public List<Users> findAll();
}
sqlMapper文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xpc.springboot_orcale.mapper.UsersMapper">
<!-- public List<Users> findAll();-->
<select id="findAll" resultType="Users">
select * from users
</select>
</mapper>
servcie 业务逻辑层
//service接口
public interface UsersService {
public List<Users> findAll();
}
//service实现类
@Service
public class UsersServiceImpl implements UsersService {
@Autowired
private UsersMapper usersMapper;
@Override
public List<Users> findAll() {
return usersMapper.findAll();
}
}
controller控制层
@RestController
@RequestMapping("/users")
@MultipartConfig
public class UsersController {
@Autowired
private UsersService usersService;
/* public List<Users> findAll();*/
@RequestMapping("/find")
public List<Users> findAll(){
return usersService.findAll();
}
}
SpringbootOrcaleApplication配置
@SpringBootApplication
//扫描的包
@MapperScan(basePackages = {"com.xpc.springboot_orcale.mapper"})
public class SpringbootOrcaleApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootOrcaleApplication.class, args);
}
}
application.properties文件配置
##springboot连接数据库 这里链接的是oracle数据库
spring.datasource.platform=oracle
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
spring.datasource.username=xpc
spring.datasource.password=123456
##springboot关联mybatis
##sqMapper映射文件位置
mybatis.mapper-locations=classpath:/sqlMapper/*Mapper.xml
##下划线到驼峰式命名法的映射
mybatis.configuration.map-underscore-to-camel-case=true
##类起别名
mybatis.type-aliases-package=com.xpc.springboot_orcale.pojo
##配置Tomcat相关内容
server.port=8080
server.tomcat.connection-timeout=1000
server.tomcat.uri-encoding=utf-8
##配置支持单个文件大于1MB的 文件上传
spring.servlet.multipart.max-file-size=100MB
##配置一次请求文件上传的最大值
spring.servlet.multipart.max-request-size=100MB
###Thymeleaf配置 转发形式页面模板
spring.thymeleaf.prefix=classpath:/static/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
##2.1.3必须配置,不配置找不到html页面
spring.thymeleaf.mode=HTML5
###过滤中文乱码
spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true