Home > Java > javaTutorial > SpringBoot basic web development demo method

SpringBoot basic web development demo method

WBOY
Release: 2023-06-02 10:22:05
forward
688 people have browsed it

1. Import Lombok dependencies in pom.xml in the created springboot project

<dependency>
  <groupid>org.projectlombok</groupid>
  <artifactid>lombok</artifactid>
  <version>1.18.6</version>
</dependency>
Copy after login

2. Install the Lombok plug-in

SpringBoot basic web development demo method

3. Create a package of the entity class at the same level as the main startup class, create the entity class in the package, and use Lombok on the entity class

package com.hxy.bean;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

@Data //替代了getter、setter和toString方法
@AllArgsConstructor //创建所有参数的有参构造函数
@NoArgsConstructor //创建无参构造函数
public class Car {
  private Integer id;
  private String name;
  private double price;

  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  private Date createDate;
}
Copy after login

4. Create a control layer package at the same level as the main startup class, and create a controller class

package com.hxy.controller;
import com.offcn.po.Car;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController //替代了@ResponseBody和@Controller注解
@RequestMapping("/car")
public class CarController {
  @RequestMapping("/findone")
  public Car findOneCar(){
    Car car = new Car(1, "toyo", 1999.99F,new Date(),"13567890001");
    return car;
  }
}
Copy after login

The above is the detailed content of SpringBoot basic web development demo method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template