创建第一个Spring-boot

Eclipse创建第一个Spring-boot项目

进入Eclipse软件中选择 File->new->other或者快捷键Ctrl+N
选择Maven project
Next->Next 到这里选择蓝色这个Webapp选项在点next
在这里插入图片描述
我创建一个项目,我一般会将GroupId设置为Demo,,ArtifactId设置为tes,表示你这个项目的名称是testProj,依照这个设置,在你创建Maven工程后,新建包的时候,包结构最好是Demo.tes打头的,如果有个controller,它的全路径就是Demo.tes.controller
在这里插入图片描述
项目创建完成的目录结构,需要pom.xml文件,在最后面!

在这里插入图片描述
StartSpringBootApplication是项目的启动代码,Spring-boot是内置tomcat 的且这个类要在目录最顶层否则你注解的其他类它扫描不到

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

DemoController 类 中@RestController=@ResponseBody+@Controller返回Json字符串 @RequestMapping("/") 则是请求路径详情参考

@RestController
public class DemoController {
	@RequestMapping("/")
	String getHelloWord(){
		return "Hello Word";
	}
}

http://localhost:8080/加上你在@RequestMapping("/")写的路径出现这个页面就证明成功了!在这里插入图片描述
附带上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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Demo</groupId>
  <artifactId>tes</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>tes Maven Webapp</name>
  <url>http://maven.apache.org</url>
   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
	<properties>
	   <!--HTTP jar  -->
    <version.httpmime>4.3.1</version.httpmime>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
		<resources>
			<resource>
				<directory>src/main/java</directory>
				<includes>
					<include>**/*.xml</include>
				</includes>
			</resource>
		</resources>
		<finalName>xiaowei</finalName>
	</build>
</project>

第一次写博客大家多多包涵,多多交流谢谢!有什么问题留言呀

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值