J2EE Servlet 명세에서 인코딩된(content type : application/x-www-form-urlencoded) HTTP PUT 메소드는 지원하지 않기 때문에 폼에 값을 담은 후 PUT으로 서버에 전송할 경우 Command Object 바인딩이 자동으로 되지 않는다.
해결책은 아래와 같다.
자료 찾느라 열라 고생함 ㅠㅠ
(아직 spring 기반의 RESTful 서비스가 많지 않아서 그런가? 아님 너무 당연해서 나만 몰랐던 건가?)
16.3.3.11 Working with "application/x-www-form-urlencoded" data
The previous sections covered use of @ModelAttribute to support form submission requests from browser clients. The same annotation is recommended for use with requests from non-browser clients as well. However there is one notable difference when it comes to working with HTTP PUT requests. Browsers can submit form data via HTTP GET or HTTP POST. Non-browser clients can also submit forms viaHTTP PUT. This presents a challenge because the Servlet specification requires the ServletRequest.getParameter*() family of methods to support form field access only for HTTP POST, not for HTTP PUT.
To support HTTP PUT requests, the spring-web module provides the filter HttpPutFormContentFilter, which can be configured in web.xml:
The above filter intercepts HTTP PUT requests with content type application/x-www-form-urlencoded, reads the form data from the body of the request, and wraps the ServletRequest in order to make the form data available through the ServletRequest.getParameter*() family of methods.
// 1번 트랜잭션 (Spring bean) someDao.transactionTest01();
// 2번 트랜잭션 (Not spring bean) new OtherDao().transactionTest02( someDao.getConnection() );
// 3번 트랜잭션 (Spring bean) someDao.transactionTest03();
SomeDao.java 에서 ....
public Connection getConnection() throws SQLException { // DataSourceUtils는 발생하는 SQLException에 대해 CannotGetJdbcConnectionException으로 받아 상위처리를 담당한다. // 글로벌 트랜잰션을 통해 제어하지 않아야 할 경우 이런식으로 Connection을 얻어 처리하면 된다. return DataSourceUtils.getConnection( getSqlMapClientTemplate().getDataSource() ); }
public void transactionTest01() throws Exception {
Map parameterMap = new HashMap(2); parameterMap.put("sampleCd", "1001"); parameterMap.put("sampleNm", "테스트_01");
int affected = getSqlMapClientTemplate().update("sample.otherUpdate", parameterMap); }
public void transactionTest03() throws Exception {
Map parameterMap = new HashMap(2); parameterMap.put("sampleCd", "1001"); parameterMap.put("sampleNm", "테스트_03");
int affected = getSqlMapClientTemplate().update("sample.otherUpdate", parameterMap);
if (affected == 1) { throw new Exception("TEST ERROR"); // 1번, 2번 모두 rollback 됨 } }
OtherDao.java 에서 .....
public class OtherDao {
final String SQL = "UPDATE TB_SAMPLE " + " SET SAMPLE_NM = ? " + " WHERE SAMPLE_CD = ? ";
public void transactionTest02(Connection conn) throws Exception {
Map parameterMap = new HashMap(2); parameterMap.put("sampleCd", "1001"); parameterMap.put("sampleNm", "테스트_02");