为什么就只有description出不来

为什么就只有description出不来

		public void save(Product product) {
			// TODO Auto-generated method stub
			Connection connection=null;
			PreparedStatement preparedStatement=null;
			try {
				//获得连接
				connection=JDBCUtils.getConnection();
				//编写sql
				String sql="insert into product values (null,?,?,?,?,?,?,?)";
				//预编译sql
				preparedStatement=connection.prepareStatement(sql);
				//设置参数
				preparedStatement.setString(1,product.getPname());
				preparedStatement.setString(2,product.getAuthor());
				preparedStatement.setDouble(3, product.getPrice());
				preparedStatement.setString(4,product.getDescription());
				preparedStatement.setString(5,product.getFilename());
				preparedStatement.setString(6, product.getPath());
				preparedStatement.setInt(7, product.getCategory().getCid());
				//执行sql
			    preparedStatement.executeUpdate();
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}finally {
				JDBCUtils.release(preparedStatement, connection);
			}
		}
private void save(HttpServletRequest request, HttpServletResponse response) throws IOException {
		//文件上传
		Map<String,String> map=UploadUtils.uploadFile(request);
		//将数据完成封装
		Product product=new Product();
		product.setPname(map.get("pname"));
		product.setAuthor(map.get("author"));
		product.setPrice(Double.parseDouble(map.get("price")));
		product.setDescription(map.get("description"));
		product.setFilename(map.get("filename"));
		product.setPath(map.get("path"));
		product.getCategory().setCid(Integer.parseInt(map.get("cid")));;
		//处理数据
		ProductService productService=new ProductServiceImpl();
		productService.save(product);
		//跳转页面
		response.sendRedirect(request.getContextPath()+"/ProductServlet?method=findAll");
	}

http://img1.sycdn.imooc.com//climg/5f114b4a09a7941406130023.jpg

正在回答

登陆购买课程后可参与讨论,去登陆

2回答

同学你好,1. 建议同学查看前端页面中是否存在name值为description的input标签,查看通过map.get("description")是否接收到数据。

2. 同学可查看数据库中是否添加成功,或查看数据库中的description字段是否与Product 类中设置的description属性一致,如果不一致,则建议同学修改为一致。

3. 建议同学清除缓存后,再进行测试。

祝学习愉快!

好帮手慕小尤 2020-07-17 15:54:10

同学你好,1. 建议同学查看map.get("description")是否存在数据。

2. 同学可查看setDescription()是否有设置成功。

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

  • 提问者 慕标0359786 #1
    都设置成功了,我问问题之前看过了 public class Product { private Integer pid; private String pname; private String author; private Double price; private String description; private String path; private String filename; //表中分类的ID,面向对象语言,如何表示商品所属的分类 private Category category=new Category(); public Integer getPid() { return pid; } public void setPid(Integer pid) { this.pid = pid; } public String getPname() { return pname; } public void setPname(String pname) { this.pname = pname; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public Double getPrice() { return price; } public void setPrice(Double price) { this.price = price; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } public String getFilename() { return filename; } public void setFilename(String filename) { this.filename = filename; } public Category getCategory() { return category; } public void setCategory(Category category) { this.category = category; }
    2020-07-17 15:59:34
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师