【发布时间】:2015-01-06 11:51:11
【问题描述】:
标题说明了一切。现在我的代码将键值添加到数据库中,我认为问题出在我的模型类或 servlet 类中。我想将Map<String, String> 值保存到String customerType 字段中
型号:
@Id
@SequenceGenerator(name = "my_seq", sequenceName = "seq1", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "my_seq")
public long id;
private String firstName;
private String customerType;
@ElementCollection
@Column(name="customerType")
public Map<String, String> customerTypes;
我使用 servlet 类将值放入映射中,如下所示:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
showForm(request, response);
}
private void showForm(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("","");
map.put("customerType.private", "Private");
map.put("customerType.corporate", "Corporate");
Customer customer = new Customer();
customer.setCustomerTypes(map);
request.setAttribute("customer", customer);
request.getRequestDispatcher("/Add.jsp").forward(request, response);
}
注意!我将地图值发送到 Add.jsp 页面中的选择标签(简单的用户添加表单),数据从那里保存到数据库中。当数据被保存时,customerType 的格式为customerType.corporate 或customerType.private,但应为Corporate 或Private。
【问题讨论】:
标签: jpa dictionary