Content Negotiation Strategy
This commit is contained in:
parent
aea2aafe06
commit
800285f30c
|
@ -98,6 +98,18 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Json conversion -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -2,46 +2,48 @@ package com.baeldung.spring.form;
|
|||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement
|
||||
public class Employee {
|
||||
|
||||
private long id;
|
||||
private long id;
|
||||
|
||||
@NotNull
|
||||
@Size(min = 1)
|
||||
private String name;
|
||||
@NotNull
|
||||
@Size(min = 1)
|
||||
private String contactNumber;
|
||||
@NotNull
|
||||
@Size(min = 1)
|
||||
private String name;
|
||||
@NotNull
|
||||
@Size(min = 1)
|
||||
private String contactNumber;
|
||||
|
||||
public Employee() {
|
||||
super();
|
||||
}
|
||||
public Employee() {
|
||||
super();
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(final long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContactNumber() {
|
||||
return contactNumber;
|
||||
}
|
||||
public String getContactNumber() {
|
||||
return contactNumber;
|
||||
}
|
||||
|
||||
public void setContactNumber(final String contactNumber) {
|
||||
this.contactNumber = contactNumber;
|
||||
}
|
||||
public void setContactNumber(final String contactNumber) {
|
||||
this.contactNumber = contactNumber;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-4.2.xsd
|
||||
http://www.springframework.org/schema/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
|
||||
|
||||
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" />
|
||||
<context:component-scan base-package="org.baeldung.spring.controller" />
|
||||
<bean id="viewResolver"
|
||||
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<property name="prefix" value="/WEB-INF/view/" />
|
||||
<property name="suffix" value=".jsp" />
|
||||
</bean>
|
||||
|
||||
<mvc:view-controller path="/sample.html" view-name="sample" />
|
||||
|
||||
<!-- Content strategy using path extension -->
|
||||
<bean id="contentNegotiationManager"
|
||||
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
|
||||
<property name="favorPathExtension" value="true" />
|
||||
<property name="favorParameter" value="false"/>
|
||||
<property name="parameterName" value="mediaType"/>
|
||||
<property name="ignoreAcceptHeader" value="true" />
|
||||
<property name="defaultContentType" value="text/html" />
|
||||
<property name="useJaf" value="false" />
|
||||
|
||||
<property name="mediaTypes">
|
||||
<map>
|
||||
<entry key="html" value="text/html" />
|
||||
<entry key="json" value="application/json" />
|
||||
<entry key="xml" value="application/xml" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
</beans>
|
Loading…
Reference in New Issue