Revert "Removing HTML media type"

This reverts commit a243105b01a2ac9e26189da8078d4c2c44200868.
This commit is contained in:
Roshan Thomas 2016-03-13 20:26:59 -04:00
parent a243105b01
commit 12ce3ee247
4 changed files with 52 additions and 32 deletions

View File

@ -23,13 +23,14 @@ public class ContentManagementWebConfig extends WebMvcConfigurerAdapter {
@Override @Override
public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) { public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false). configurer.favorPathExtension(true).
favorParameter(true). favorParameter(false).
parameterName("mediaType"). parameterName("mediaType").
ignoreAcceptHeader(true). ignoreAcceptHeader(true).
useJaf(false). useJaf(false).
defaultContentType(MediaType.APPLICATION_JSON). defaultContentType(MediaType.TEXT_HTML).
mediaType("xml", MediaType.APPLICATION_XML). mediaType("xml", MediaType.APPLICATION_XML).
mediaType("html", MediaType.TEXT_HTML).
mediaType("json", MediaType.APPLICATION_JSON); mediaType("json", MediaType.APPLICATION_JSON);
} }

View File

@ -29,6 +29,15 @@ public class EmployeeController {
return employeeMap.get(Id); return employeeMap.get(Id);
} }
@RequestMapping(value = "/employee/{Id}", method = RequestMethod.GET)
public String getEmployeeByIdHtmlView(@PathVariable final long Id, final ModelMap model) {
model.addAttribute("name", employeeMap.get(Id).getName());
model.addAttribute("contactNumber", employeeMap.get(Id).getContactNumber());
model.addAttribute("id", employeeMap.get(Id).getId());
return "employeeView";
}
@RequestMapping(value = "/addEmployee", method = RequestMethod.POST) @RequestMapping(value = "/addEmployee", method = RequestMethod.POST)
public String submit(@ModelAttribute("employee") final Employee employee, final BindingResult result, final ModelMap model) { public String submit(@ModelAttribute("employee") final Employee employee, final BindingResult result, final ModelMap model) {
if (result.hasErrors()) { if (result.hasErrors()) {

View File

@ -30,6 +30,15 @@ public class EmployeeController {
return employeeMap.get(Id); return employeeMap.get(Id);
} }
@RequestMapping(value = "/employee/{Id}", method = RequestMethod.GET)
public String getEmployeeByIdHtmlView(@PathVariable final long Id, final ModelMap model) {
model.addAttribute("name", employeeMap.get(Id).getName());
model.addAttribute("contactNumber", employeeMap.get(Id).getContactNumber());
model.addAttribute("id", employeeMap.get(Id).getId());
return "employeeView";
}
@RequestMapping(value = "/addEmployee", method = RequestMethod.POST) @RequestMapping(value = "/addEmployee", method = RequestMethod.POST)
public String submit(@ModelAttribute("employee") final Employee employee, final BindingResult result, final ModelMap model) { public String submit(@ModelAttribute("employee") final Employee employee, final BindingResult result, final ModelMap model) {
if (result.hasErrors()) { if (result.hasErrors()) {

View File

@ -23,15 +23,16 @@
<!-- Content strategy using path extension --> <!-- Content strategy using path extension -->
<bean id="contentNegotiationManager" <bean id="contentNegotiationManager"
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"> class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="false" /> <property name="favorPathExtension" value="true" />
<property name="favorParameter" value="true"/> <property name="favorParameter" value="false"/>
<property name="parameterName" value="mediaType"/> <property name="parameterName" value="mediaType"/>
<property name="ignoreAcceptHeader" value="true" /> <property name="ignoreAcceptHeader" value="true" />
<property name="defaultContentType" value="application/json" /> <property name="defaultContentType" value="text/html" />
<property name="useJaf" value="false" /> <property name="useJaf" value="false" />
<property name="mediaTypes"> <property name="mediaTypes">
<map> <map>
<entry key="html" value="text/html" />
<entry key="json" value="application/json" /> <entry key="json" value="application/json" />
<entry key="xml" value="application/xml" /> <entry key="xml" value="application/xml" />
</map> </map>