标签:jackson manage rgs dep orm const data get for
1.在创建的springboot项目中的pom.xml中导入Lombok的依赖
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
</dependency>
2.安装Lombok插件
3.在主启动类的同级创建实体类的包,在包中创建实体类,并在实体类上使用Lombok
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;
}
4.在在主启动类的同级创建控制层的包,并创建controller类
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;
}
}
标签:jackson manage rgs dep orm const data get for
原文地址:https://www.cnblogs.com/hxy-programmer/p/11801622.html