springboot 可以快速的和其他任何框架结合
web 有了这个就可从页面上接受数据和springmvc类似 关联引入所有的spring ,springmvc的功能
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
springboot父级jar包,只有有了这个 才能是一个springboot项目
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.2.1.RELEASEversion>
<relativePath/>
parent>
mybatis 相关jar包 关联引入mybatis mybatis-spring等等
<dependency>
<groupId>org.mybatis.spring.bootgroupId>
<artifactId>mybatis-spring-boot-starterartifactId>
<version>2.1.3version>
dependency>
使用转发功能
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-thymeleafartifactId>
dependency>
热部署工具 自动重启应用
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-devtoolsartifactId>
<scope>runtimescope>
<optional>trueoptional>
dependency>
Oracle
<dependency>
<groupId>com.oracle.ojdbcgroupId>
<artifactId>ojdbc8artifactId>
<scope>runtimescope>
dependency>
MySQL
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<scope>runtimescope>
dependency>
Lombok插件 可以简化实体类的书写 可以通过对应的注解完成
<dependency>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
<optional>trueoptional>
dependency>
测试用的jar包
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
<exclusions>
<exclusion>
<groupId>org.junit.vintagegroupId>
<artifactId>junit-vintage-engineartifactId>
exclusion>
exclusions>
dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<configuration>
<fork>truefork>
configuration>
plugin>
plugins>
build>
//注解是lombok插件提供的
@Getter
@Setter
@ToString
@EqualsAndHashCode
public class Users {
private Integer id;
private String name;
private String imgpath;
}
@Component
@Mapper
public interface UsersService {
public List<Users> findAll();
}
<mapper namespace="com.xpc.springboot_orcale.mapper.UsersMapper">
<select id="findAll" resultType="Users">
select * from users
select>
mapper>
//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();
}
}
@RestController
@RequestMapping("/users")
@MultipartConfig
public class UsersController {
@Autowired
private UsersService usersService;
/* public List findAll();*/
@RequestMapping("/find")
public List<Users> findAll(){
return usersService.findAll();
}
}
@SpringBootApplication
//扫描的包
@MapperScan(basePackages = {"com.xpc.springboot_orcale.mapper"})
public class SpringbootOrcaleApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootOrcaleApplication.class, args);
}
}
##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