zoukankan      html  css  js  c++  java
  • SpringBoot入门小案例

    1、创建一个简单的maven project项目

    2、下面来看一下项目结构:

    3、pom.xml 配置jar包

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.12.RELEASE</version>
            <relativePath />
        </parent>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
        </dependencies>

    4、创建一个SpringBoot项目运行的启动类

    package com.cppdy;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class Application {
        
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    
    }

    5、创建一个controller(@Controller只返回页面;@RestController返回json格式的数据)

    package com.cppdy.controller;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class HelloWordController {
        
        @RequestMapping("hello")
        public String hello() {
            
            return "HelloWord";
        }
    
    }

    6、到这一步项目就配置好了打开浏览器访问 http://localhost:8080/hello,请注意访问不需要加项目名,如果要加需要在application.properties文件中另行配置

     

  • 相关阅读:
    4d
    加载数据
    刘亮给的帮助
    加载数据
    选中并高亮显示
    ArcEngine
    接口编程
    好的参考文献
    在本地安装 wordpress
    C#读取EXCEL数据
  • 原文地址:https://www.cnblogs.com/jiefu/p/10005239.html
Copyright © 2011-2022 走看看