我的表单参数没有将数据加载到控制器中,我在控制台中收到此消息:
INSERT INTO Products (code, cateogyr_code, product_category, product_name, description, price) VALUES ('0','0','null','null','null')'0.0')
表格如下:
<form action="controller" method="POST">
<input type="hidden" name="action" value="add">
<table>
<tr><td>Code</td><td><input name="code"></td></tr>
<tr><td>Name</td><td><input name="product_name"></td></tr>
<tr><td>Category Code</td><td><input name="category_code"></td></tr>
<tr><td>Category</td><td><input name="product_category"></td></tr>
<tr><td>Description</td><td><input name="description"></td></tr>
<tr><td>Price</td><td><input name="price" ></td></tr>
<tr><td colspan="2"><input type="submit" value="Save"></td></tr> </table> </form>
这是我的控制器方法:
else if (action.equals("add")) {
Product newProduct= new Product();
dao.addProduct(newProduct);
List<Product> products = dao.findAll();
address = "listproduct.jsp";
request.setAttribute("products", products);;
这是我的 sql 方法
public void addProduct(Product product) {
String sql = "INSERT INTO Products " +
"(code, category_code, product_category, product_name, description, price)" +
" VALUES (" +
"'" + product.getCode() + "'," +
"'" + product.getCategory_code() + "'," +
"'" + product.getCategory() + "'," +
"'" + product.getName() + "'," +
"'" + product.getDescription() + "')"+
"'" + product.getPrice() + "')";
System.out.println(sql);
}
有人可以帮助我吗?