@Test public void testAddPost() throws Throwable{ Post post = new Post(); post.setUserId(2); ClassPathResource res = new ClassPathResource("temp.jpg"); byte[] mockImg = FileCopyUtils.copyToByteArray(res.getFile()); post.setPostAttach(mockImg); post.setPostText("测试帖子的内容"); postDao.addPost(post); }
public void addPost(final Post post){ String sql = " INSERT INTO t_post(post_id,user_id,post_text,post_attach)" + " VALUES(?,?,?,?)"; jdbcTemplate.execute(sql,new AbstractLobCreatingPreparedStatementCallback(this.lobHandler) { protected void setValues(PreparedStatement ps,LobCreator lobCreator) throws SQLException { ps.setInt(1, incre.nextIntValue()); ps.setInt(2, post.getUserId()); lobCreator.setClobAsString(ps, 3, post.getPostText()); lobCreator.setBlobAsBytes(ps, 4, post.getPostAttach()); } }); }
PostDao { public void addPost(final Post post){ String sql = " INSERT INTO t_post(post_id,user_id,post_text,post_attach)" + " VALUES(?,?,?,?)"; jdbcTemplate.execute(sql,new AbstractLobCreatingPreparedStatementCallback(this.lobHandler) { protected void setValues(PreparedStatement ps,LobCreator lobCreator) throws SQLException { ps.setInt(1, incre.nextIntValue()); ps.setInt(2, post.getUserId()); lobCreator.setClobAsString(ps, 3, post.getPostText()); lobCreator.setBlobAsBytes(ps, 4, post.getPostAttach()); } }); } }
PostDao { public void addPost(final Post post){ String sql = " INSERT INTO t_post(post_id,user_id,post_text,post_attach)" + " VALUES(?,?,?,?)"; jdbcTemplate.execute(sql,new AbstractLobCreatingPreparedStatementCallback(this.lobHandler) { protected void setValues(PreparedStatement ps,LobCreator lobCreator) throws SQLException { ps.setInt(1, incre.nextIntValue()); ps.setInt(2, post.getUserId()); lobCreator.setClobAsString(ps, 3, post.getPostText()); lobCreator.setBlobAsBytes(ps, 4, post.getPostAttach()); } }); }  }
PostDao { public void addPost(final Post post){ String sql = " INSERT INTO t_post(post_id,user_id,post_text,post_attach)" + " VALUES(?,?,?,?)"; jdbcTemplate.execute(sql,new AbstractLobCreatingPreparedStatementCallback(this.lobHandler) { protected void setValues(PreparedStatement ps,LobCreator lobCreator) throws SQLException { ps.setInt(1, incre.nextIntValue()); ps.setInt(2, post.getUserId()); lobCreator.setClobAsString(ps, 3, post.getPostText()); lobCreator.setBlobAsBytes(ps, 4, post.getPostAttach()); } }); }  @Autowired void setJdbcTemplate(JdbcTemplate jdbcTemplate); @Autowired void setLobHandler(LobHandler lobHandler); @Autowired void setIncre(DataFieldMaxValueIncrementer incre); void addPost(final Post post); void getNativeConn(); List<Post> getAttachs(final int userId); void getAttach(final int postId, final OutputStream os); }
PostDao { public void addPost(final Post post){ String sql = " INSERT INTO t_post(post_id,user_id,post_text,post_attach)" + " VALUES(?,?,?,?)"; jdbcTemplate.execute(sql,new AbstractLobCreatingPreparedStatementCallback(this.lobHandler) { protected void setValues(PreparedStatement ps,LobCreator lobCreator) throws SQLException { ps.setInt(1, incre.nextIntValue()); ps.setInt(2, post.getUserId()); lobCreator.setClobAsString(ps, 3, post.getPostText()); lobCreator.setBlobAsBytes(ps, 4, post.getPostAttach()); } }); }  @Autowired void setJdbcTemplate(JdbcTemplate jdbcTemplate); @Autowired void setLobHandler(LobHandler lobHandler); @Autowired void setIncre(DataFieldMaxValueIncrementer incre); void addPost(final Post post); void getNativeConn(); List<Post> getAttachs(final int userId); void getAttach(final int postId, final OutputStream os);  }