javascript
SpringBoot————快速搭建springboot项目
完成項(xiàng)目的創(chuàng)建信息
瀏覽器打開SPRING INITIALIZR網(wǎng)址:
http://start.spring.io/? 如下圖所示完成配置:
1.完成基礎(chǔ)項(xiàng)目配置
2.相關(guān)名稱
3.依賴jar包,如果是web項(xiàng)目,那么這里選擇的Web依賴已經(jīng)包含了開發(fā)web項(xiàng)目所必須的服務(wù)器以及Spring MVC框架;JPA是持久層API,其中包含HIbernate,但是如果使用MyBatis需要另行添加,不過(guò)JdbcTemplate也是不錯(cuò)的。
4.生成項(xiàng)目zip壓縮包
(Switch to full version是切換到完整的配置表單,如果你是認(rèn)真的,可以切換到完整版)
最終的壓縮包是這個(gè)樣子:
IDE項(xiàng)目導(dǎo)入
1.將壓縮包直接當(dāng)前目錄解壓
2.導(dǎo)入項(xiàng)目
3.完成
測(cè)試項(xiàng)目
1.設(shè)置項(xiàng)目端口
打開application.properties文件,并添加端口號(hào):
server.port=8080 #these 3 words are Chinese characters encoded by the file default encoding = "ISO-8859-1" visitor.name=\u5B59\u609F\u7A7A2.編寫controller
package com.alibaba.controller;import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController;import com.alibaba.fastjson.JSONObject;@RestController @RequestMapping("/demo") public class DemoController {// 配置文件中以ISO-8859-1編碼的漢字是:孫悟空。// 雖然配置文件中并不是以u(píng)tf-8編碼的漢字,但是這里并不影響@Value取得正確的漢字@Value("${visitor.name}")private String visitorName;@RequestMapping(value = "/say/{name}", method = RequestMethod.GET)public JSONObject sayHello(@PathVariable String name) {JSONObject result = new JSONObject();if (!visitorName.equals(name)) {result.put("data", "對(duì)不起,你不是孫悟空!");return result;} else {result.put("data", "你好啊," + name + "先生");}return result;} }3.瀏覽器驗(yàn)證
注意:在pom中引入jpa的時(shí)候,由于是數(shù)據(jù)源組件,因此會(huì)去配置文件中加載數(shù)據(jù)庫(kù)相關(guān)的配置信息,如果暫時(shí)還沒(méi)有填寫這部分的信息,那么會(huì)導(dǎo)致項(xiàng)目啟動(dòng)失敗,并提示一個(gè)datasource相關(guān)的信息,可以暫時(shí)在pom中注掉數(shù)據(jù)源相關(guān)組件的依賴。
總結(jié)
以上是生活随笔為你收集整理的SpringBoot————快速搭建springboot项目的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 用php实现一个简易的web表单生成器,
- 下一篇: linux下tomcat部署java w