1

Spring MVC を使用して、完全に安静な Web アプリを構築しています。PUT メソッドがある場合、@ModelAttribute フォーム Bean にデータが取り込まれません (すべての値が null)。POST メソッドを使用すると、すべてが正しく入力されます。

Postman ( https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm )でクエリを実行しますImage Requete Postman : http://www.hostingpics.net/viewer.php?id=474577probleme .jpg

@Entity
@Table(name = "positiongps")
public class PositionGPS implements BaseEntity<Long> {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false, columnDefinition = "SERIAL", updatable = false)
private Long id;

@Column(name = "latitude", precision = 11, scale = 7, columnDefinition = "NUMERIC", nullable = false, updatable = true, unique = false)
private BigDecimal latitude;

@Column(name = "longitude", precision = 11, scale = 7, columnDefinition = "NUMERIC", nullable = false, updatable = true, unique = false)
private BigDecimal longitude;

// ** Constructeur **//

public PositionGPS() {
    super();
    latitude = new BigDecimal("0");
    longitude = new BigDecimal("0");
}

// ** Get and Set **//

.

@ResponseBody
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public boolean update(@ModelAttribute("positionGPS") PositionGPS positionGPS, @PathVariable Long id, Model model) {
    LOG.debug("update :: IN, PositionGPS.Id=[" + id + "]");
    PositionGPS positionGPSOld = positionGPSService.getById(id);
    LOG.debug("update :: getId=[" + positionGPS.getId() + "]");
    LOG.debug("update :: getLatitude=[" + positionGPS.getLatitude() + "]");
    LOG.debug("update :: getLongitude=[" + positionGPS.getLongitude() + "]");

    try {
        if (positionGPSOld != null) {
            positionGPSOld.setLatitude(positionGPS.getLatitude());
            positionGPSOld.setLongitude(positionGPS.getLongitude());
            PositionGPS newpositionGPS = positionGPSService.update(positionGPSOld);
        } else {
            LOG.debug("update :: PositionGPS Error test");
        }

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return true;
}

web.xml

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>httpMethodFilter</filter-name>
    <filter-  class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>httpMethodFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

私のコンソール:

DEBUG: PositionGPSController - update :: IN,   PositionGPS.Id=[136]
DEBUG: PositionGPSController - update :: getId=[136]
DEBUG: PositionGPSController - update :: getLatitude=[0]
DEBUG: PositionGPSController - update :: getLongitude=[0]
4

3 に答える 3

2

私は交換します

@ModelAttribute("positionGPS") PositionGPS positionGPS, @PathVariable Long id, Model model

為に

@RequestBody PositionGPS positionGPS, @PathVariable Long id, Model model)

リンクのヘルプ: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-config-enable

Spring MVC: JSON リクエストボディをデシリアライズしない

于 2013-10-26T15:01:34.500 に答える
0

以下のフィルターを WebApplicationInitializer クラスに追加するか、対応する xml コードを web.xml に追加します。

final FilterRegistration.Dynamic httpMethodFilter = servletContext.addFilter("hiddenHttpMethodFilter", new HiddenHttpMethodFilter());
        httpMethodFilter.addMappingForUrlPatterns(null, true, "/*");

        final FilterRegistration.Dynamic putFormFilter = servletContext.addFilter("httpPutFormContentFilter", new HttpPutFormContentFilter());
        putFormFilter.addMappingForUrlPatterns(null, true, "/*");
于 2013-10-26T03:44:56.253 に答える