大家好,将以下行添加到函数中时,出现错误500:
Ticket ti = ticketRepository.findOneById(idtick);
或者这个:
Ticket ti = ticketRepository.findById(idtick).get();
它们都不起作用,这是我的功能:
@GetMapping(path = "/tickets")
public String tickets(Model model, Long idp,
@RequestParam(name = "page", defaultValue = "0") int page,
@RequestParam(name = "size", defaultValue = "8") int size,
@RequestParam(name = "idtick", defaultValue = "0") Long idtick) {
Ticket t = new Ticket();
if(idtick!=0) {
System.out.println("ID Ticket : "+idtick);
Ticket ti = ticketRepository.findOneById(idtick);
System.out.println(ti);
}
//Projection p = projectionRepository.findOneById(idp);
model.addAttribute("ticket", t);
Projection p = projectionRepository.findOneById(idp);
Page<Ticket> tickets = ticketRepository.findByProjection(p, PageRequest.of(page, size));
model.addAttribute("idprojection", idp);
model.addAttribute("tickets", tickets);
model.addAttribute("page", page);
model.addAttribute("films", tickets.getContent());
model.addAttribute("pages", new int[tickets.getTotalPages()]);
model.addAttribute("currentPage", page);
model.addAttribute("idtick", idtick);
model.addAttribute("size", size);
return "tickets";
}
这是机票类:
@Entity
@Data @NoArgsConstructor @AllArgsConstructor
public class Ticket {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(length=75)
private String nomClient;
private double prix;
//@Column(unique = true, nullable=true)
@Column(unique = false,nullable=true)
private Integer codePayement;
private boolean reserve;
@ManyToOne
private Place place;
@ManyToOne
private Projection projection;
}
和ticketRepository代码:
@RepositoryRestResource
@CrossOrigin("*")
public interface TicketRepository extends JpaRepository<Ticket, Long> {
public Ticket findOneById(Long id);
}
这是堆栈跟踪:
java.lang.StackOverflowError:在java.lang.AbstractStringBuilder.ensureCapacityInternal(未知来源)〜[na:1.8.0_251]为null在java.lang.AbstractStringBuilder.append(未知来源)〜[na:1.8.0_251]在java.lang.StringBuilder.append(未知来源)〜[na:1.8.0_251]在sun.misc.FloatingDecimal $ BinaryToASCIIBuffer.appendTo(未知来源)〜[na:1.8.0_251]在sun.misc.FloatingDecimal.appendTo (未知来源)〜[na:1.8.0_251]在java.lang.AbstractStringBuilder.append(未知来源)〜[na:1.8.0_251]在java.lang.StringBuilder.append(未知来源)〜[na:1.8。 0_251]
有人可以告诉我怎么了吗? 预先感谢。
答案 0 :(得分:1)
这是无限循环的症状。如果Projection
或Place
类包含Ticket
元素,则Lombok在尝试为这些类生成方法时会遇到无限递归循环。检查您的代码是否有其他类似的循环依赖。参见:Lombok - java.lang.StackOverflowError: null on toString method
答案 1 :(得分:0)
您能从实体类中删除@ Data,@ NoArgConstrucor和@AllArgConstructor并显式添加内容吗。您在错误的位置定义了CrossOrigin。您是否在类路径中包含了spring-data-jpa-repository jar?是否正在扫描此Entity类,否则您必须显式使用@EnableJpaReposiry。什么是由于JPA生成的SQL查询。您的数据库启动了吗?在调试模式下运行您的应用程序,这将很有帮助。