springboot后台管理系统|springboot在线商城购物系统

浏览:509 发布日期:2022/01/15 分类:系统代码 关键字: springboot
在本文中,我们将讨论使用spring开发一个功能完善的商城购物系统。我们将讨论使用Spring Boot创建商城购物系统的的两种方法。
  springboot后台管理系统在构建在线商城购物系统时,由于其快速的生产就绪环境,使得开发人员可以直接专注于逻辑,而不是纠结于配置和设置,因此它现在正成为开发人员的最爱。Spring Boot是一个基于微服务的框架,在其中创建一个生产就绪的应用程序只需要很短的时间。在本文中,我们将讨论使用spring开发一个功能完善的商城购物系统。我们将讨论使用Spring Boot创建商城购物系统的的两种方法。
  
  源码:s.ymzan.top
  
  ●借助SpringBoot的CommandRunner界面
  
  ●使用SpringBoot中的控制器类
  
  首先,在我们的机器上初始化项目。Spring Initializr是一个基于web的工具,使用它我们可以很容易地生成Spring Boot项目的结构。它还为元数据模型中表示的项目提供了各种不同的特性。这个模型允许我们配置JVM支持的依赖项列表。在这里,我们将使用spring初始化器创建应用程序的结构,然后使用IDE创建示例GET路由。因此,要做到这一点,需要按如下顺序执行以下步骤。
  
  逐步实施
  
  步骤1:转到Spring Initializr
  
  请按要求填写详细信息。对于这个应用程序:
  
  Project: Maven
  
  Language: Java
  
  Spring Boot: 2.2.8
  
  Packaging: JAR
  
  Java: 8
  
  Dependencies: Spring shopping
  
  步骤2:单击Generate,它将下载启动器项目。
  
  步骤3:解压缩压缩文件。现在打开一个合适的IDE,然后转到文件>,从现有的资源> Spring-boot-app中新建>项目,并选择pom.xml。点击导入更改提示符,等待项目同步如下图所示:
  
  注意:在Import Project for Maven窗口中,确保您选择了与创建项目时选择的JDK版本相同的JDK。
  
  方法一:借助SpringBoot的CommandRunner界面
  
  步骤4:进入src > main > java > com.gfg.Spring.boot。下面是SpringBootAppApplication.java文件的代码。
  
  @SpringBootApplication
  
  // Main class
  
  // Implementing CommandLineRunner interface
  
  public class SpringBootAppApplication implements CommandLineRunner
  
  {
  
  // Method 1
  
  // run() method for springBootApplication to execute
  
  @Override
  
  public void run(String args[]) throws Exception
  
  {
  
  // Print statement when method is called
  
  System.out.println("HEllo world");
  
  }
  
  // Method 2
  
  // Main driver method
  
  public static void main(String[] args)
  
  {
  
  // Calling run() method to execute
  
  // SpringBootApplication by
  
  // invoking run() inside main() method
  
  SpringApplication.run(SpringBootAppApplication.class, args);
  
  }
  
  }
  
  这个应用程序现在可以运行了。
  
  步骤5:运行SpringBootAppApplication类,并等待Tomcat服务器在已经设置了默认端口的地方启动。
  
  Tip: The default port of the Tomcat server is 8080 and can be changed in the application.properties file.
  
  输出:在终端/CMD中生成
  
  方法2:使用SpringBoot中的控制器类
  
  进入src > main > java > com.gfg.Spring.boot.app,创建一个控制器类。下面是controller.java文件的代码。
  
  @RestController
  
  public class controller {
  
  @GetMapping("/")
  
  String return1(){
  
  return "Hello World";
  
  }
  
  }
  
  这个控制器帮助处理来自客户端的所有传入请求。现在我们将使用PostMan并调用Spring引导应用程序的get API。
评论( 相关
后面还有条评论,点击查看>>