zoukankan      html  css  js  c++  java
  • Spring boot的第一个demo

      由于SpringBoot的问世使开发的门槛有降低了不少,就其这一点,早已使其名声大振,如雷贯耳。我之前是使用spring开发的,刚才使用了spring boot试验了一下,果然名不虚传,开发速度贼快。看来以后要多用新技术了,话不多少,我把我的第一个spring boot的程序记录下来。

    一、在 https://start.spring.io 网站创建模板

    注:

    1、这里的spring boot版本不要太高,2.0.0以下就行,听说2.0.0以上的版本与要jdk9以上才能兼容;

    2、由于咱们是开发web项目,所以在dependencies搜索框中搜索web,然后添加spring-boot-starter-web依赖;

    3、配置好之后点击“Generate Project”会自动下载一个压缩包,然后解压后在idea中打开;

    二、配置maven、jdk

    1、maven的配置:file——setting——搜索maven

    2、jdk配置:fie——project stracture-jdk

    三、编写测试用例

    package com.gougou.springbootdemo01;
    
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @RequestMapping("firstdemo")
    public class HelloWorldController {
    
    
        @RequestMapping("hello")
        public String helloworld1(){
            return "Hello world!";
        }
    
        @RequestMapping(value="/{name}",method = RequestMethod.GET)
        public String helloworld2(@PathVariable("name") String name){
            return "Hello "+name;
        }
    
    }

    四、启动spring boot并访问

    1、启动spring boot,就是运行main方法

    2、打开浏览器访问

    大功告成!!

     

     

    在全栈的道路上,积极向上、成熟稳重、谦虚好学、怀着炽热的心向前方的走得更远。
  • 相关阅读:
    PyCharm 2020 激活到 2100 年
    PyTorch-22 学习 PyTorch 的 Examples
    机器视觉的主要研究内容和细分方向(超全超赞)
    CVPR 2020 全部论文 分类汇总和打包下载
    2020年,加油鸭
    SpiningUP 强化学习 中文文档
    大学C语言基础——30天挑战PAT甲级(一)
    明天提交辞职报告
    要开始新的技术之旅了
    记忆是件奇怪的东西
  • 原文地址:https://www.cnblogs.com/DDgougou/p/10237104.html
Copyright © 2011-2022 走看看