Erlo

SpringBoot简单入门

2019-04-20 13:01:42 发布   500 浏览  
页面报错/反馈
收藏 点赞

一、创建SpringBoot项目

1.创建maven项目,pom引入springboot父级启动器(starter)依赖:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.example</groupId>
	<artifactId>myproject</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<#gth# Inherit defaults from Spring Boot -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.4.RELEASE</version>
	</parent>

	<#gth# Add typical dependencies for a web application -->
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
	</dependencies>

	<#gth# Package as an executable jar -->
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

2.使用STSIDEA快速创建(推荐)
2.1创建一个Spring-Starter-project,勾选需要的模块

2.2编写业务代码,如我们常见的controller、service、dao和entity等,需要注意的是:这些包的路径需要与主程序XXXapplication同级或一下,因为主程序只扫描同级包以及子包。

如放在其它位置,则需要在主程序上加上注解:@ComponentScan(basePackages="包名")

3.运行

3.1主程序右键运行  run as 。。。

3.2打jar包运行  java -jar 包名(注意打包jdk版本与运行环境jdk版本一致)

4.访问

 

 

登录查看全部

参与评论

评论留言

还没有评论留言,赶紧来抢楼吧~~

手机查看

返回顶部

给这篇文章打个标签吧~

棒极了 糟糕透顶 好文章 PHP JAVA JS 小程序 Python SEO MySql 确认