第一步:
第二步:
Group一般分为多个段,这里我只说两段
第一段为域,域又分为org、com、cn等等许多,其中org为非营利组织,com为商业组织
第二段为公司名称。
举个apache公司的tomcat项目例子:这个项目的Group是org.apache,它的域是org(因为tomcat是非营利项目),公司名称是apache,Artifact是tomcat。
比如我现在创建一个项目,我一般会将Group设置为cn.wq,cn表示域为中国,wq是我个人姓名缩写,Artifact设置为testproject,表示你这个项目的名称是testproject,依照这个设置,在你创建Maven工程后,新建包的时候,包结构最好是cn.wq.testproject打头的,如果有个StudentDao[Dao层],它的全路径就是cn.wq.testproject.dao.StudentDao
第三步:
第四步:
第五步:
等待编译完成,并删除三个文件
第六步(最终目录结构):
这里的包名参考第二步说明。
第七步:
打开pom.xml文件,找到
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
将<version>2.1.1.RELEASE</version>版本更改为<version>2.1.0.RELEASE</version>
2.1.1不知道为啥依赖的包下载不了,可能翻墙原因,更改为2.1.0之后下载依赖包非常的快。
第八步:
创建一个包,创建一个类,老规矩,从helloWord开始。。。
package cn.wq.testproject.Controller;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@EnableAutoConfiguration
@ResponseBody
public class HelloController {
@RequestMapping("/hello")
private String index(){
return "Hello World!";
}
}
第九步:
启动项目
刚创建好项目时,项目中自带了一个类,***Application,打开这个类,
里面有一个main方法,右键,运行这个main方法。
启动之后可以看控制台显示的是如下:
spring的图标,包含springboot的版本 2.1.0
端口号是8080
容器使用的是tomcat/9.0.12
最后,我们在浏览器中输入 http://localhost:8080/hello