小编Raj*_*wal的帖子

如何使用Postman在Spring Boot中的请求参数中传递时间戳,日期

我想在 Spring Boot 控制器方法中将时间戳作为请求参数传递

//实体类

@Entity
public class EventCalendar {
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE)
    private int id;
    private String eventName;
    private String city;
    private String address;
    @Temporal(TemporalType.TIMESTAMP)
    private Date createRecord;
    
    @Temporal(TemporalType.TIMESTAMP)
    private Date startTime;
    
    @Temporal(TemporalType.TIMESTAMP) 
    private Date endTime;
Run Code Online (Sandbox Code Playgroud)

//控制器

@RestController
@RequestMapping("/events")
public class controller{
    @GetMapping("/getevents8")
    public List<EventCalendar> getEvents8(@RequestParam int page,@RequestParam Date d1,@RequestParam Date d2 ){
        Sort sort=new Sort(Sort.Direction.DESC,"createRecord");
        Pageable pageRequest =PageRequest.of(page, 3,sort);
        List<EventCalendar> events;
        
            events=eventRepository.findByCreateRecordBetween(d1, d2, pageRequest);
        
        return events;
        }
}
Run Code Online (Sandbox Code Playgroud)

//我使用json插入的时间戳示例

{

        "id":10,
        "eventName":"Kabbadi pro kidz",
        "city":"Noida",
        "address":"sector 63",
        "createRecord":"2020-03-31T15:45:01Z",
        "startTime":"2020-04-08T07:30:10Z", …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-data-jpa spring-boot

6
推荐指数
1
解决办法
2万
查看次数

JPA hibernate 保存 spring/JPA/Java 上的 ConcurrentModificationException

有两个实体

1.Locker(子)(@OneToMany(mappedBy))

2.主题(父/所有者)(@ManyToOne)

通过邮递员,我传递了储物柜实体ID,通过这个我正在访问主题并尝试更新特定的东西,但我收到错误,我什至没有创建新的我只是更新它,一切都在工作插入和删除除了这个案例

@Entity
public class Locker {

    @Id
    @GeneratedValue
    private int id;
    private String lockerno;

    @OneToMany(mappedBy="lockey",cascade= {CascadeType.ALL})
    private List<Subjects> subjects;

    //getters andsetter and constructors

Run Code Online (Sandbox Code Playgroud)

第二实体

@Entity
public class Subjects {

    @Id
    @GeneratedValue
    private int id;
    private String subname;
    private String marks;

    @ManyToOne(cascade= {CascadeType.MERGE,CascadeType.REMOVE,CascadeType.REFRESH})
    private Locker lockey;

    //getters and setter constructors
Run Code Online (Sandbox Code Playgroud)

现在是存储库接口

public interface LockerRepo extends CrudRepository<Locker,Integer>{
}

public interface SubjectsRepo2 extends CrudRepository<Subjects,Integer>{
}
Run Code Online (Sandbox Code Playgroud)

现在是控制器方法

public String m25(@RequestParam("id") int id) throws Exception {

    Optional<Locker> lock=lockerrepo.findById(id);
    Locker ll=lock.get();
    ArrayList<Subjects> sub=new …
Run Code Online (Sandbox Code Playgroud)

hibernate jpa spring-data-jpa spring-boot

1
推荐指数
1
解决办法
5679
查看次数