我正在使用休眠(多对一)关系:
@Entity
public class City implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private long id;
private String description;
@ManyToOne
@JoinColumn(name="state_id")
private State state;...
}
城市模型:
@Entity
public class State {
@Id
@GeneratedValue
private long id;
private String description;
@OneToMany(mappedBy="state")
private List<City> city=new ArrayList<>();...
}
客户型号:
@Entity
public class Customer implements Serializable {
/**
*
*/
private static final long serialVersionUID = -5442590361339242648L;
@Id
@GeneratedValue
private long id;
@NotEmpty
private String firstname;
@NotEmpty
private String lastname;
@NotEmpty
private String phone;
@NotEmpty
private String address;
@ManyToOne
@JoinColumn(name="city_id")
private City city;
@ManyToOne
@JoinColumn (name="state_id")
private State state;
@NotEmpty
private String zipcode;
@NotEmpty
@Email
private String email;
private int status;
private Date createdate;
@OneToMany(mappedBy = "customer")
private List<Account> account = new ArrayList<Account>();...
}
in my controller i've a method:
@RequestMapping(value = "/city", method = RequestMethod.GET)
public @ResponseBody
List<City> findCities(
@RequestParam(value = "stateId", required = true) long city,
Model model) {
List<City> myCity = cityDao.getCityState(city);
return myCity;
}
我有一个 jquery 函数:
<script type="text/javascript">
$(document).ready(function() {
$('#state').change(function() {
$.getJSON('${findCitiesURL}',{stateId : $(this).val(),ajax : 'true'},
function(data) {
var html = '<option value="">City</option>';
var len = data.length;
for ( var i = 0; i < len; i++) {
html += '<option value="' + data[i].id + '">'+ data[i].description+ '</option>';
}
html += '</option>';
$('#city').html(html);
});
});
});
</script>
我的问题是如何在 jquery 中替换显示城市的代码,例如 form:select path ...
我无法在我的数据库中保存数据