从0到1搭建spring boot项目

从0到1搭建spring boot项目

手把手教你如何优雅的使用idea建立属于你的第一个Sring Boot项目。 本次教程使用到的技术栈 String+Mybatis+Swagger+Mysql+Redisphp

1、准备工做

环境安装请你们参考网上教程自行安装,遇到问题可私信 球球html

  1. JDK
  2. Mysql
  3. idea
  4. (maven),不安装的话能够适应idea默认自带的

2、让项目起飞

2.1安装boot插件

打开Settings里面Plugins,勾选String Boot插件而后点击Apply,若是已经安装了可忽略次步骤 java

2.2建立String Boot项目

New Project 选择Spring Initializrgit

2.2.1 点击Next

2.2.2 点击Next

2.2.3 勾选所需插件,点击next

此处不够选的也不要紧能够在pom文件中自行添加依赖就好了github

2.2.4 选择文件建立目录并点击finish

2.2.5 删除无用文件

.gitignore .mvn mvnw mvnw.cmd HELP.mdweb

2.2.6 修改默认mvn配置文件

此时你会发现,项目经过idea默认的maven依赖导入很漫长,这个等待的时间能够说是没法忍受的,因此须要切换maven的源地址spring

settings_ali.xml 配置文件sql

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <localRepository>/myapp/m2/repo</localRepository>
  
  <pluginGroups>
    
  </pluginGroups>

  <proxies>
    
  </proxies>

  <servers>
    
  </servers>

  
  <mirrors>
     <mirror>
      <id>nexus-aliyun</id>
      <mirrorOf>*</mirrorOf>
      <name>Nexus aliyun</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
  </mirrors>

  <profiles>
    
  </profiles>

</settings>

复制代码

此时你会发现你的项目已经在起飞般的下载依赖。。。

2.2.7 设置源文件目录

若是你的项目没有自动设置java目录为源文件目录的话,须要手动设置apache

Java目录下右键->Mark Dicrectory as -> Sources Rootapp

2.2.9 建立测试控制层

package com.qiuqiu.boot.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {

    @RequestMapping("/get")
    public String info(){
        return "this is Spring Boot";
    }

}

复制代码

2.2.10 启动项目

访问地址 http://localhost:8080/test/get

至此你的第一个web项目就启动了。。。

3、给项目建立可视化可调试的API文档

未完待续。。。

结语

  • 每篇都会有github代码做为指引;[github地址:空]
  • 为了让你们学习的更加快速,我还录制了短小精炼的视频;[视频地址:空]
  • 请记住:我是一个热爱生活,乐于分享的仙人球球。
  • 人生格言:圆润的可爱,圆润的分享,圆润的静享生活。。。
相关文章
相关标签/搜索