springboot第一个项目【创建】
1.new project,不勾选create from archetype,直接选择

2.next下一步
在Maven依赖管理中,唯一标识一个依赖项是由该依赖项的三个属性构成的,分别是groupId、artifactId以及version。这三个属性可以唯一确定一个组件(Jar包或者War包)。groupId和artifactId是为了保证项目唯一性提出的。
参照maven中的groupId和artifactId到底指的是什么?
groupId:一般分为多段,第一段为域(org: 非营利组织,com:商业组织,cn:中国)。第二段为公司名称,第三段为公司内部的部门,如qa等。
artifactId:项目名称
version: snapshot和正式版本。快照版本和正式版本的主要区别在于:本地获取这些依赖的机制不同。
- 正式版本:如果依赖一个库的正式版本,那构建时会先在仓库中查找是否已经有,如果没有才会去远程拉
- snapshot:依赖snapshot库,每次构建项目时就会去远程拉它所依赖的版本。在配置Maven的Repository的时候中有个配置项,可以配置对于SNAPSHOT版本向远程仓库中查找的频率。频率共有四种,分别是always、daily、interval、never。 
3.pom.xml配置
- 在properties中配置版本信息,接下来可以用${java-version}来使用该版本号
<properties>
<java.version>1.8</java.version>
</properties> - 配置依赖的jar包,以<dependency></dependency>放在<dependencies></dependencies>中
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies> - 在distributionManagement段中配置的是snapshot快照库和release发布库的地址,主要是id和url的配置,配置后就可以通过mvn deploy进行发布了
<distributionManagement>
<repository>
<id>deployment</id>
<name>internal repository for releases</name>
<url>http://repo.caimi-inc.com/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement> - parent:配置被继承的父项目的具体信息,可以继承父项目的配置信息,如dependencies等
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.0</version>
</parent> - 构建中依赖的插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> - 资源配置:也是在build中配置的。无需编译,是一些properties或XML配置文件,构建过程中会往往会将资源文件从源路径复制到指定的目标路径
<build>
<resources>
<resource>
<targetPath>META-INF/plexus</targetPath>
<filtering>false</filtering>
<directory>${basedir}/src/main/plexus</directory>
<includes>
<include>configuration.xml</include>
</includes>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
</build>

4.项目结构
- src—main下创建java目录,且右键选择mark directory as sources root
- 在java目录下创建包,包名应该全为小写,包名前缀为groupId.artifactId.XXX
- 在包下创建类 Main,作为程序入口
- target是存放编译后的文件

5.添加代码
- 在Main类中添加一个main函数
package cn.zll.testproject.controller; //这个要改成自己的包名
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//添加注解SpringBootApplication,是一个复合注解,包含下面三个:
//@Configuration:表示将该类作用springboot配置文件类。
//@EnableAutoConfiguration:表示程序启动时,自动加载springboot默认的配置
//@ComponentScan:表示程序启动是,自动扫描当前包及子包下所有类
@SpringBootApplication public class Main {
public static void main(String[] args){
//创建一个SpringApplication
SpringApplication app = new SpringApplication(Main.class);
app.run(args);
}
}
- 在包名下创建一个controller包,并添加一个类IndexController
package cn.zll.springboottest.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; //用Controller注解为控制器
@Controller
public class IndexController {
//拦截/路径的get请求,返回index.html中的内容
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(){
return "index";
}
}
- 在resources下添加templates,并添加index.html文档
注:需要在pom.xml中添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
6.执行
右键Main类,直接Run —> 打开浏览器,输入localhost:8080,就可以访问
springboot第一个项目【创建】的更多相关文章
- springboot 多模块项目创建
1.File>new>project 直接点击next 2.输入groupId .artifactId 3.选择项目保存路劲 finish 4.成功创建多模块项目的根模块 5.创建子 ...
- springboot第一个项目【mybatis】
1.resources下添加spring 添加spring-context.xml,设置controller的路径,以及引入数据库配置 <beans xmlns="http://www ...
- SpringBoot项目创建与第一个SSM项目示例
本节介绍SpringBoot创建第一个示例SSM项目的完整过程,使用工具STS,与IDEA操作基本类似. 示例代码在:https://github.com/laolunsi/spring-boot-e ...
- springboot web项目创建及自动配置分析(thymeleaf+flyway)
@ 目录 源码分析 webjars thymeleaf thymeleaf语法 springmvc 启动配置原理 集成flyway插件 springboot 创建web项目只需要引入对应的web-st ...
- Django 创建第一个项目(转)
转自(http://www.runoob.com/django/django-first-app.html) 前面写了不少python程序,由于之前都是作为工具用,所以命令行就足够了,最近写的测试用例 ...
- Angular安装及创建第一个项目
Angular简介 AngularJS 诞生于2009年,由Misko Hevery 等人创建,后为Google所收购.是一款优秀的前端JS框架,已经被用于Google的多款产品当中.AngularJ ...
- 利用IntelliJ IDEA 创建第一个项目
1.创建项目 打开后点击第一个按钮
- django创建第一个项目helloworld
环境:centos 7,已安装python 3.6环境 1.安装django并创建django第一个项目 1.1.使用pip安装django# pip install Django或指定安装版本# p ...
- python+Django创建第一个项目
1.首先搭建好环境 1.1 安装pyhton,Linux系统中,python是系统自带的所以就不用安装 1.2 安装Django框架 使用pip安装: pip install django 1.3 检 ...
随机推荐
- Idea运行web项目时,提示java.lang.ClassNotFoundException: com.mysql.jdbc.Driver解决方法
今天用 idea写了个工程.结果最后报错,错误信息如下: java.lang.ClassNotFoundException: com.mysql.jdbc.Driverat org.apache.ca ...
- thymeleaf 传参到js的onclick事件中
html: <img th:onclick="'javascript:imgClick(\''+${card.id}+'\',\''+${card.name}+'\');'" ...
- Array.apply(null,{length:6}).map()
map定义和方法 map()方法返回一个新数组,数组中的元素为原始数组元素调用函数处理的后值. map()方法按照原始数组元素顺序依次处理元素. 注意: map不会对空数组进行检测 map不会改变原始 ...
- struts2简单入门-Action的三种配置方式
普通的配置方式 优点:可读性高 缺点:重复的配置太多. 使用情况 一个actian只有一个方法,只需要处理一种请求. 代码演示 <action name="voteResult&quo ...
- Django学习手册 - 自定义分页函数
前端代码: <div class="xianshi"> {% for i in info %} <ul> <li>{{ i }}</li& ...
- Nginx系列6:对称加密与非对称加密各自的应用场景
强推:推荐一篇通俗易懂的对称加密和非对称加密的文章:https://segmentfault.com/a/1190000004461428 推荐一篇文章:对称加密算法与非对称加密算法的优缺点:http ...
- ActiveMQ中Broker的应用与启动方式
Broker:英语有代理的意思,在activemq中,Broker就相当于一个Activemq实例. 1. 命令行启动实例: 1.activemq start使用默认的activemq.xml启动 E ...
- SLAM数据集整理
New College Dataset :: Main / Downloads Autonomous Space Robotics Lab: Devon Island Rover Navigation ...
- MySql DDL语言(数据库和数据表的管理)
数据定义语言,负责数据库和数据表的管理 ⒈数据库的管理 1.创建数据库 create database if not exists DatabaseName; #if not exists可以省略 2 ...
- HDOJ 4267 A Simple Problem with Integers (线段树)
题目: Problem Description Let A1, A2, ... , AN be N elements. You need to deal with two kinds of opera ...