當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringBoot从入门到实战只需一篇文章
生活随笔
收集整理的這篇文章主要介紹了
SpringBoot从入门到实战只需一篇文章
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Spring Boot框架從入門到實踐
SpringBoot初相識
一、SpringBoot框架簡介
二、SpringBoot的特性
三、SpringBoot四大核心
SpringBoot初體驗
一、第一個Spring Boot程序
創建一個Spring Boot項目
加入Spring Boot父級和起步依賴
-
父級依賴
加入Spring父級依賴可以簡化項目的Maven配置
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.9.RELEASE</version><relativePath></relativePath></parent> -
起步依賴
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies>
創建Spring Boot的入口Main方法
package springboot;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication public class Application {public static void main(String[] args) {//Spring Boot程序->Spring容器->內嵌的tomcatSpringApplication.run(Application.class,args);} }創建一個SpringMCVC的Controller
package springboot.controller;import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;@RestController public class HelloController {@RequestMapping("/hello")public String hello(){return "Hello,Spring Boot";} }運行SpringBoot的入口Main方法
二、SpringBoot程序解析
SpringBoot核心配置文件
一、多環境配置文件
- spring.profiles.active=dev
- application-dev.properties
- spring.profiles.active=product
- application-product.properties
二、自定義配置文件讀取
采用注釋讀取屬性值
SpringBoot下SpringMVC開發
返回字符串或json數據
SpringBoot使用JSP
在Application.properties文件中配置springMVC的視圖展示為JSP
spring.mvc.view.prefix=/ #前綴 spring.mvc.view.suffix=.jsp #后綴在src/main目錄下創建一個webapp目錄,在該目錄下新建jsp頁面
在Spring Boot中集成MyBatis
在pom.xml中配置相關jar依賴
<!-- 加載Mybatis整合Springboot--><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.3.2</version></dependency> <!-- MySQL的JDBC驅動包--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency>在SpringBoot的核心配置文件application.properties中配置MyBatis的Mapper.xml文件所在的位置。
mybatis.mapper-location=classpath:edu/sust/springboot/mapper/*.xml在springboot的核心配置文件application.properties中配置數據源
spring.datasource.username=root spring.datasource.password=123456 spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/springdb?useUnicode=true&characterEncoding=utf8&useSSL=false4.在MyBatis的Mapper接口中添加@Mapper注解
總結
以上是生活随笔為你收集整理的SpringBoot从入门到实战只需一篇文章的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 卡片游戏 数学期望
- 下一篇: 计算一个尽可能大的素数