Removed Tomcat Plugin from pom.xml, rename Userdetails to User and moved
the controller to web
This commit is contained in:
parent
7fef269169
commit
5aaeb7308a
|
@ -164,14 +164,6 @@
|
|||
</configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.tomcat.maven</groupId>
|
||||
<artifactId>tomcat7-maven-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<path>/</path>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
package org.baeldung.model;
|
||||
|
||||
public class UserDetails {
|
||||
private String firstname;
|
||||
private String lastname;
|
||||
private String emailId;
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(final String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(final String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public String getEmailId() {
|
||||
return emailId;
|
||||
}
|
||||
|
||||
public void setEmailId(final String emailId) {
|
||||
this.emailId = emailId;
|
||||
}
|
||||
|
||||
}
|
||||
package org.baeldung.model;
|
||||
|
||||
public class User {
|
||||
private String firstname;
|
||||
private String lastname;
|
||||
private String emailId;
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(final String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(final String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public String getEmailId() {
|
||||
return emailId;
|
||||
}
|
||||
|
||||
public void setEmailId(final String emailId) {
|
||||
this.emailId = emailId;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,6 @@ import java.util.Set;
|
|||
import org.baeldung.dialect.CustomDialect;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Description;
|
||||
import org.springframework.context.support.ResourceBundleMessageSource;
|
||||
|
@ -24,7 +23,6 @@ import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
|
|||
|
||||
@EnableWebMvc
|
||||
@Configuration
|
||||
@ComponentScan("org.baeldung.controller")
|
||||
public class ClientWebConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
public ClientWebConfig() {
|
||||
|
|
|
@ -1,31 +1,32 @@
|
|||
package org.baeldung.controller;
|
||||
|
||||
import org.baeldung.model.UserDetails;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/")
|
||||
public class UserController {
|
||||
|
||||
@RequestMapping(value = "/", method = RequestMethod.GET)
|
||||
public String showForm(final Model model) {
|
||||
final UserDetails user = new UserDetails();
|
||||
user.setFirstname("John");
|
||||
user.setLastname("Roy");
|
||||
user.setEmailId("John.Roy@gmail.com");
|
||||
model.addAttribute("user", user);
|
||||
return "index";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/processForm", method = RequestMethod.POST)
|
||||
public String processForm(@ModelAttribute(value = "user") final UserDetails user, final Model model) {
|
||||
// Insert userDetails into DB
|
||||
model.addAttribute("name", user.getFirstname() + " " + user.getLastname());
|
||||
return "hello";
|
||||
}
|
||||
|
||||
}
|
||||
package org.baeldung.web.controller;
|
||||
|
||||
import org.baeldung.model.User;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/")
|
||||
public class UserController {
|
||||
|
||||
@RequestMapping(value = "/", method = RequestMethod.GET)
|
||||
public String showForm(final Model model) {
|
||||
final User user = new User();
|
||||
user.setFirstname("John");
|
||||
user.setLastname("Roy");
|
||||
user.setEmailId("John.Roy@gmail.com");
|
||||
model.addAttribute("user", user);
|
||||
return "index";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/processForm", method = RequestMethod.POST)
|
||||
public String processForm(@ModelAttribute(value = "user") final User user,
|
||||
final Model model) {
|
||||
// Insert User into DB
|
||||
model.addAttribute("name", user.getFirstname() + " " + user.getLastname());
|
||||
return "hello";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue