springBoot 入门(一)—— 使用idea创建第一个springBoot项目

版本使用说明
idea 为 Idea 2017
jdk 采用1.8
maven 采用 3.5.3 (记得先安装,此处不做介绍)

创建项目
在这里插入图片描述
然后写好包名,项目名直接一路回车到这一步:
在这里插入图片描述
然后我们需要在其中建立一些包以及添加一些文件:
如下图:
在这里插入图片描述
现在来说一下每个包和文件的作用是什么
DemoApplication.java 是SpringBoot的入口文件
HelloController.java 是Spring Mvc的控制周期
static目录下面的是静态资源文件 比如css js 等
templates下面放置的是html文件
application.properties是SpringBoot的配置信息
pom.xml是maven的依赖

DemoApplication.java

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

HelloController.java

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

csstest.css

body {
    padding: 0px;
    margin: auto;
    font-family: "黑体", "仿宋", Arial, "Arial Unicode MS", System;
    background-color: #00F;
    font-size: 20px;
    text-align: left;
}

welcome.html

<html>
<head>
    <title>Title</title>
</head>
<link href="css/csstest.css" rel="stylesheet"/>
<body>
<p>welcome page is login.........</p>
</body>
</html>

application.properties

#修改tomcat的默认的端口号,将8080改为8888
server.port=8888 

在这里插入图片描述
现在我们看到整个程序是报错的。现在我们右键项目reimport一下
在这里插入图片描述
然后程序错误便消失了。
在这里插入图片描述
最后我们右键运行DemoApplication.java
在这里插入图片描述

项目打包上传到了Github

https://github.com/jingxian99/edunusoft.git
喜欢的就给个Start吧

发布了84 篇原创文章 · 获赞 68 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/qq_40985788/article/details/104520891