我想按出生日期创建搜索。这是我在Java中的课程:
@Entity
@Table(name="child")
public class Child implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="ID")
private int id;
@Column(name="FirstName")
private String firstName;
@Column(name="SecondName")
private String secondName;
@Column(name="PESEL")
private String PESEL;
@Column(name="BirthDate")
@Temporal(TemporalType.DATE)
private Date birthDate;
@Column(name="Sex")
private String sex;
@JsonBackReference
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name="familyid",referencedColumnName = "id")
private Family family;
}
并查询:
@Transactional
public List<Family> getFamilyByBirthDateChild(String string) {
HibernateUtil.initManager();
TypedQuery<Family> query = HibernateUtil.getEntityManager().createQuery("SELECT family FROM Family family INNER JOIN family.childList ef WHERE ef.birthDate = :birthdate ",Family.class);
query.setParameter("birthdate",string);
List<Family> result = query.getResultList();
HibernateUtil.shutdown();
return result;
}
我在Angular 6中具有正面:
<div style="width: 300px;">
<form (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="id">Search</label>
<input type="text" class="form-control" id="id" required [(ngModel)]="val" name="pesel">
</div>
<div class="form-group">
<label for="department">Sex</label>
<select id="department" name="department"
[(ngModel)]= "choice" class="form-control">
<option value="Pesel">Pesel</option>
<option value="Name">Imię</option>
<option value="Sourname">Nazwisko</option>
<option value="Sex">Płeć</option>
<option value="BirthDate">Data</option>
</select>
</div>
<div class="btn-group">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</form>
</div>
以及组件中的代码:
case 'BirthDate': {
const dateB = new Date(this.val);
this.dataService.getFamilyByBirthDateChild(dateB)
.subscribe(families => this.families = families);
break;
}
当我写日期时,例如“ 2018年7月2日”我得到了错误“ 讯息:
"Http failure response for (unknown url): 0 Unknown Error"
。
我不知道这是什么问题,因为当我从文本区域获取字符串时,我将其解析为对象日期,但是它不起作用...谢谢您的帮助。
@编辑
生成的链接:http://localhost:8080/api/getFamilyByBirthDateChild/Mon%20Jul%2002%202001%2000:00:00%20GMT+0200%20(CEST)