SpringBoot中文文档
https://qbgbook.gitbooks.io/spring-boot-reference-guide-zh/content/
SpringBoot官方文档:
https://docs.spring.io/spring-boot/docs/current/reference/html/
SpringBoot简介
所用工具一:
MyEclipse10 、JDK1.7、MAVEN3.0
第一步、安装MyEclipse开发工具
第二步、给myeclipse配置jdk和maven
1.下载并安装jdk
2.下载并安装maven
第三步、搭建StringBoot
1.File > New >project... >Maven Project
完成后得目录结构如下
2.修改pom.xml文件
修改如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gnab</groupId>
<artifactId>Tmall_SSM</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 1.添加一个父项目 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<!-- 2.修改jdk版本 -->
<properties>
<java.version>1.7</java.version>
</properties>
<!-- 3. 注入SpringBoot的启动器,所谓的SpringBoot启动器其实是一些jar包的集合-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
修改好后右击项目再更新一下
完成后的目录:
3.run起来
目录结构
新建一个controller
编写返回HelloWorld的controller
import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* SpringBoot Hello World
* @author qirang
*
*/
@Controller// 标明这是一个SpringMVC的Controller控制器
public class HelloWorld {
@RequestMapping("/hello")
@ResponseBody
public Map<String, Object> showHelloWorld(){
Map<String, Object> map = new HashMap<>();
map.put("msg", "HelloWorld!");
return map;
}
}
编写一个启动类,需要包含一个Main方法
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* SpringBoot 启动类
* @author qirang
*
*/
@SpringBootApplication// Spring Boot项目的核心注解,主要目的是开启自动配置
public class App {
// 在main方法中启动一个应用,即:这个应用的入口
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
run一下,就可以了
所用工具二:
idea2018 、JDK1.8、MAVEN3.3
第一步、安装idea开发工具
下载地址:https://www.jetbrains.com/idea/download/#section=windows
重启电脑后
之前安装使用过,则可考虑选择第一个选项;未曾安装过选择第二个选项
让激活,不管他,退出软件
第二步、破解idea
1.下载破解补丁JetbrainsCrack-x.x.x.jar 地址: http://idea.lanyus.com/
拷贝到idea安装目录的bin下
打开另两个框里的文件,分别在最下面一行增加:
-javaagent:路径
//路径为本机ideal 目录下bin目录中 JetbrainsCrack.jar 存放的路径
重新启动软件,选择Activation code,再将下段代码复制进去
ThisCrackLicenseId-{
"licenseId":"ThisCrackLicenseId",
"licenseeName":"idea",
"assigneeName":"",
"assigneeEmail":"idea@163.com",
"licenseRestriction":"For This Crack, Only Test! Please support genuine!!!",
"checkConcurrentUse":false,
"products":[
{"code":"II","paidUpTo":"2099-12-31"},
{"code":"DM","paidUpTo":"2099-12-31"},
{"code":"AC","paidUpTo":"2099-12-31"},
{"code":"RS0","paidUpTo":"2099-12-31"},
{"code":"WS","paidUpTo":"2099-12-31"},
{"code":"DPN","paidUpTo":"2099-12-31"},
{"code":"RC","paidUpTo":"2099-12-31"},
{"code":"PS","paidUpTo":"2099-12-31"},
{"code":"DC","paidUpTo":"2099-12-31"},
{"code":"RM","paidUpTo":"2099-12-31"},
{"code":"CL","paidUpTo":"2099-12-31"},
{"code":"PC","paidUpTo":"2099-12-31"}
],
"hash":"2911276/0",
"gracePeriodDays":7,
"autoProlongated":false}
破解成功
安装jdk
安装maven
下载地址:http://maven.apache.org/download.cgi
解压后,到config/setting.xml配置文件里加入以下代码
<localRepository>E:\Program Files\IntelliJ IDEA 2018.3.5\apache-maven-3.6.0\repository</localRepository>
//地址为你想要下载maven插件到哪个地方就填上哪个地方
下载镜像,填上这个,比较不容易下载出错
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
设置默认使用JDK1.8
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
第三步、给idea配上自己安的maven
Configure > Settings > Build, Execution, Deployment > Build Tools > Maven
将框中改为我们自己安的maven地址
改为自己设置的,注意文件不要选错了,否则建项目会出错
第四步、用idea建一个HelloWorld
目录结构:
1.新建一个maven项目
2.导入SpringBoot依赖的相关依赖
<!-- 1.添加一个父项目 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<!-- 2. 注入SpringBoot的启动器,所谓的SpringBoot启动器其实是一些jar包的集合-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3.编写一个主程序,启动SpringBoot应用
/**
* @SpringBootApplication 标明这是一个主程序,说明这是一个SpringBoot应用
*/
@SpringBootApplication
public class HelloWorld {
//快捷键是 psvm
public static void main(String[] args) {
//Spring应用启动起来
SpringApplication.run(HelloWorld.class,args);
}
}
4.编写相关的Controller、Service
public class HelloController {
@RequestMapping("/hello")
@ResponseBody
public Map<String, Object> showHelloWorld(){
Map<String, Object> map = new HashMap<String, Object>();
map.put("msg", "HelloWorld!");
return map;
}
}
5.运行主程序测试
写完后,到主程序里运行Main方法就可以了
6.简化部署
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
将这个应用达成jar包,用java -jar命令执行
快速创建一个SpringBoot项目
博客地址:https://www.cnblogs.com/pengyan-9826/p/8093099.html
参考教程:
https://blog.csdn.net/newabcc/article/details/80601933
https://www.cnblogs.com/pengyan-9826/p/8093099.html
https://www.bilibili.com/video/av38657363/?p=5