欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

程序员文章站 2022-11-22 12:08:06
springboot的优质开发体验,能够更快速的搭建生产环境的项目。这篇文章就是一个超级简单的入门springboot项目。包含了一些简单的理论和超简单Controller层 【工具】 IDEA 全称IntelliJ IDEA SpringBoot 【创建项目】打开IDEA编辑器,新建项目,然后选择 ......

springboot的优质开发体验,能够更快速的搭建生产环境的项目。这篇文章就是一个超级简单的入门springboot项目。包含了一些简单的理论和超简单controller层

【工具】

idea 全称intellij idea

springboot

【创建项目】打开idea编辑器,新建项目,然后选择spring initializr。

        选择你本地的sdk。 然后选择initializr服务url 建议选择custom 内容填写:https://start.spring.io/. 因为default创建出来不一定管用。 虽然两个填写的都是一样的地址

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

 

然后等待检索spring initializr选项 , 本次我使用的maven。 点击next

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

 

 

选择依赖:(因为是入门web) 我们选择web 点击:next

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

 

 

然后填写项目名称和存放路径。 点击:finish 到这我们就创建好了,一个简单的springboot工程

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

 

 

如图:我们可以看到目录的结构

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

 

 

 打开:demoapplication这个类,直接运行main方法。

注:springboot内置tomcat服务器,所以我们只需要运行main方法就可以。

 

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

 

 右上角选择应用程序配置,然后直接点击绿色三角运行,或者臭屁虫调试。

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

 

 

如图已经运行成功。

第一次启动成功请注意控制台输出信息!!!包含程序路径,端口,servlet引擎,tomcat版本信息等。

打开浏览器,在地址栏输入 localhost:8080,回车,会看到如下报错:

whitelabel error page

this application has no explicit mapping for /error, so you are seeing this as a fallback.

thu mar 12 00:00:50 cst 2020
there was an unexpected error (type=not found, status=404).
no message available

 

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

 

找不到页面很正常 ,我们还没建立自己的controller呢,接着往下走:

【新建第一个controller】:在包上右键,新建java class如图:

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

 

 写控制器名称 aaacontroller,回车:

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

 

 写测试代码如图:

第一个mvc测试,控制器

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

 

 

再次运行,并从浏览器地址栏上加上具体页面路径访问:

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

 

其实到这基本就完成了。

 分割线

 

还有一个端口配置问题。在这介绍项目配置文件的方式:resources的文件夹下application.properties文件

打开输入:server.port=8082 设置为完成。如图:

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

 

 

 

另外再说一个技巧,就是idea工具的窗口比较多,左边,右边,底部都有窗口是不是比较烦?

可以点每个窗口右上角的设置小图标,然后view mode选择undock,中文意思是“松开”,即自动伸缩,有事件触发时自动弹出,平时自动隐藏到边边。

idea创建一个入门Spring Boot项目(controller层)使用Moven代码管理

 

 

【完】