• SpringBoot 入门


    一、简介

    SpringBoot是由Pivotal团队提供的全新框架,其设计目的是用来简化Spring应用的初始搭建以及开发过程。

    与Spring对比:

    SpringBoot特色:

     

    二、入门程序开发

    大致分三步:

    • 创建SpringBoot项目
    • 编写Controller类
    • 运行Application类

    具体步骤:

    1、创建新模块,选择Spring Initializr,并配置模块相关基础信息:

    2、选择当前模块需要使用的技术集:

    Finish后即搭建完成。

    3、入门程序的基础文件

    pom.xml:

    1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    3. <modelVersion>4.0.0modelVersion>
    4. <groupId>com.examplegroupId>
    5. <artifactId>springboot_01artifactId>
    6. <version>0.0.1-SNAPSHOTversion>
    7. <name>springboot_01name>
    8. <description>Demo project for Spring Bootdescription>
    9. <properties>
    10. <java.version>1.8java.version>
    11. <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
    12. <project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
    13. <spring-boot.version>2.6.7spring-boot.version>
    14. properties>
    15. <dependencies>
    16. <dependency>
    17. <groupId>org.springframework.bootgroupId>
    18. <artifactId>spring-boot-starter-webartifactId>
    19. dependency>
    20. <dependency>
    21. <groupId>org.springframework.bootgroupId>
    22. <artifactId>spring-boot-starter-testartifactId>
    23. <scope>testscope>
    24. dependency>
    25. dependencies>
    26. <dependencyManagement>
    27. <dependencies>
    28. <dependency>
    29. <groupId>org.springframework.bootgroupId>
    30. <artifactId>spring-boot-dependenciesartifactId>
    31. <version>${spring-boot.version}version>
    32. <type>pomtype>
    33. <scope>importscope>
    34. dependency>
    35. dependencies>
    36. dependencyManagement>
    37. <build>
    38. <plugins>
    39. <plugin>
    40. <groupId>org.apache.maven.pluginsgroupId>
    41. <artifactId>maven-compiler-pluginartifactId>
    42. <version>3.8.1version>
    43. <configuration>
    44. <source>1.8source>
    45. <target>1.8target>
    46. <encoding>UTF-8encoding>
    47. configuration>
    48. plugin>
    49. <plugin>
    50. <groupId>org.springframework.bootgroupId>
    51. <artifactId>spring-boot-maven-pluginartifactId>
    52. <version>2.6.7version>
    53. <configuration>
    54. <mainClass>com.kvno.Springboot01ApplicationmainClass>
    55. configuration>
    56. <executions>
    57. <execution>
    58. <id>repackageid>
    59. <goals>
    60. <goal>repackagegoal>
    61. goals>
    62. execution>
    63. executions>
    64. plugin>
    65. plugins>
    66. build>
    67. project>

    Application类:

    1. @SpringBootApplication
    2. public class Springboot01Application {
    3. public static void main(String[] args) {
    4. SpringApplication.run(Springboot01Application.class, args);
    5. }
    6. }

    4、编写Controller类:

    1. //Rest模式 (Restful风格)
    2. @RestController //@Controller + @ResponseBody
    3. @RequestMapping("/books")
    4. public class BookController {
    5. @GetMapping
    6. public String getById() {
    7. System.out.println("springboot is running...");
    8. return "springboot is running...";
    9. }
    10. }

    5、运行Application类

    运行成功:

     

  • 相关阅读:
    .Net Maui 开发之路(1): APP基本设置(图标、应用名称)
    招投标系统简介 企业电子招投标采购系统源码之电子招投标系统 —降低企业采购成本
    给EmEditor添加自定义外部工具DuilibPreviewer
    一文搞懂MySQL表字段类型长度的含义
    日常开发小汇总(5)元素跟随鼠标移动(在视口下移动)
    PHP7-MySQLi在分页中的应用
    java计算机毕业设计微服务在线考试源码+系统+数据库+lw文档
    firewall 命令简单操作
    贯头山酒——中华酒文化的源头之一
    21天学习挑战赛—Python学习记录第一篇
  • 原文地址:https://blog.csdn.net/qq_57389269/article/details/126104926