当前位置: 移动技术网 > IT编程>开发语言>Java > Spring Boot入门-快速搭建web项目

Spring Boot入门-快速搭建web项目

2019年02月15日  | 移动技术网IT编程  | 我要评论

spring boot 概述:

spring boot makes it easy to create stand-alone, production-grade spring based applications that you can "just run".
we take an opinionated view of the spring platform and third-party libraries so you can get started with minimum fuss. most spring boot applications need very little spring configuration.

spring boot可以轻松创建独立的,生产级的基于spring的应用程序,而你需要做的仅仅是run 这个项目。
spring boot 的设计是为了让你尽可能快的跑起来 spring 应用程序并且尽可能减少你的配置文件。

spring boot特性:

  • 创建独立运行的spring应用程序

  • 直接嵌入tomcat,jetty或undertow(无需部署war文件)

  • 提供starter简化maven配置

  • 尽可能自动配置spring和第三方库

  • 提供准生产的应用监控功能,例如指标,运行状况检查

  • 绝对没有代码生成,也不需要xml配置

  • spring boot快速搭建web项目

spring boot项目搭建

  1. 访问:https://start.spring.io/,如下图所示(spring boot版本2.1.2,依赖了web)填写相关的项目信息、依赖等,就会生成一个maven项目的压缩包,下载解压

spring官网截图

  1. 打开idea,找到file-->open-->选择项目的路径,找打pom文件-->以project 形式打开

    idea导入截图

     

    选择open as project截图
  2. 编写hellocontroller,放到包(com.example.hellospringboot.controller)下,hellocontroller代码如下:

package com.example.hellospringboot.controller;

import org.springframework.web.bind.annotation.requestmapping;
import org.springframework.web.bind.annotation.restcontroller;

@restcontroller
public class hellocontroller {
    @requestmapping("/hello")
    public string hellospring (){
        system.out.println("hello spring boot");
        return "hello spring boot";
    }
}
  1. 点击运行按钮,查看运行结果,截图如下:

    运行按钮截图

     

    运行日志截图
  2. 项目启动成功后,浏览器输入 http://www.lhsxpumps.com/_localhost:8080/hello 访问,看到下面成功截图后,说明项目搭建成功

浏览器访问截图


下面的是我的公众号二维码图片,欢迎关注,欢迎留言,一起学习,一起进步。

java碎碎念公众号

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网