我有两节课.
"poll.java."
public class Poll {
@Id
@Column(name = "poll_id")
String pollId;
String question;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
String endDateTime;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "poll_id_fk", referencedColumnName = "poll_id")
List<Choice> choices;
}
和
哦, Select .我本来是.
public class Choice {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "choice_id")
Long choiceId;
String text;
Integer votes;
}
当我创建新的投票时,CHOICE_ID从上次创建的CHOICE_ID的数字开始递增.如何在创建新的轮询时使Choose_id重置其值?
我try 更改策略GenerationType,但似乎没有任何影响.我期待着这样的结果:
[
{
"pollId": "MvWRj",
"question": "poll 2?",
"endDateTime": "2023-07-09 19:50",
"choices": [
{
**"choiceId": 1,**
"text": "choice 1",
"votes": 1
},
{
**"choiceId": 2,**
"text": "choice 2",
"votes": 0
}
]
},
{
"pollId": "V838D",
"question": "poll 1?",
"endDateTime": "2023-07-09 19:50",
"choices": [
{
**"choiceId": 1,**
"text": "choice 1",
"votes": 1
},
{
**"choiceId": 2,**
"text": "choice 2",
"votes": 0
}
]
}
]
鉴于我得到的结果如下:
[
{
"pollId": "MvWRj",
"question": "poll 2?",
"endDateTime": "2023-07-09 19:50",
"choices": [
{
**"choiceId": 3,**
"text": "choice 1",
"votes": 1
},
{
**"choiceId": 4,**
"text": "choice 2",
"votes": 0
}
]
},
{
"pollId": "V838D",
"question": "poll 1?",
"endDateTime": "2023-07-09 19:50",
"choices": [
{
**"choiceId": 1,**
"text": "choice 1",
"votes": 1
},
{
**"choiceId": 2,**
"text": "choice 2",
"votes": 0
}
]
}
]