zoukankan      html  css  js  c++  java
  • springboot搭建过程

      为什么要学习springboot呢起初是这样的,我想加入一些开源项目来增强自己简历的竞争性,我在Github上找了一些项目,都是需要搭建springboot所以我才进行这样的一个学习,言归正传:

    强烈建议大家使用付费版的,免费版的已经不好去搭建了,破解过程可以看一下蓝宇,使用idea自带的spring Initializr(实际调用的是springboot的官网上的initializr),快速新建springboot项目。

      首先新建Springboot

      (1)file->new->project

     (2)

    创建springboot项目(因为连接的国外的网站,next有时会几秒的延迟),将两个值改成自己的配置,Group:com.laowang ,Artifact:sptest,其他可以不用动,点击ok

    (3)选择web->spring web starter,这里是不一定的  后期自己需要什么构建什么

    (4)点击完成

    2. springboot默认生成三个文件 pom.xml   application.properties   SptestApplication.java

    pom.xml中重点就一个gav:spring-boot-starter-web,其他可以删除

    application.properties 该文件默认为空,springboot的默认启动端口号:8080,可以在改文件修改。

     SptestApplication.java 启动类文件

    3. 验证springboot

    在com.laowang.sptest报下新建ctroller包,并新建类:HelloController

    package com.laowang.sptest.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import java.util.HashMap;
    
    @Controller
    public class HelloController {
    
    @RequestMapping("/")
    @ResponseBody
    public String getHello() {
    return "hello";
    }
    }
    

      验证后的样子:

    4.

    需要说明两点:

    (1)类文件要放在跟启动类同级或者下一目录下,本项目为:com.laowang.sptest包下面。因为springboot默认扫描加载启动类同级或者下级目录的标签类(@RestController,@Service ,@Configuraion,@Component等),假如真需要加载其他目录的标签类,可以通过在启动上配置标签@ComponentScan(具体包)来进行扫描加载。

    (2)资源文件默认放到resources下面,templates默认放的是动态文件,比如:html文件,不过要搭配thymeleaf 使用(pom文件中需新加gav)。

    其他也没什么了,springboot主要是通过spring提供的多个starter和一些默认约定,实现项目的快速搭建。

  • 相关阅读:
    leetcode Convert Sorted List to Binary Search Tree
    leetcode Convert Sorted Array to Binary Search Tree
    leetcode Binary Tree Level Order Traversal II
    leetcode Construct Binary Tree from Preorder and Inorder Traversal
    leetcode[105] Construct Binary Tree from Inorder and Postorder Traversal
    证明中序遍历O(n)
    leetcode Maximum Depth of Binary Tree
    限制 button 在 3 秒内不可重复点击
    HTML 和 CSS 画三角形和画多边行基本原理及实践
    在线前端 JS 或 HTML 或 CSS 编写 Demo 处 JSbin 与 jsFiddle 比较
  • 原文地址:https://www.cnblogs.com/nenu/p/15061347.html
Copyright © 2011-2022 走看看