Removed Tomcat Plugin from pom.xml, rename Userdetails to User and moved

the controller to web
This commit is contained in:
vkadapa 2015-12-18 15:51:12 +05:30 committed by David Morley
parent 8306f357b3
commit f553c8f049
4 changed files with 64 additions and 73 deletions

View File

@ -164,14 +164,6 @@
</configuration> </configuration>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
<properties> <properties>

View File

@ -1,32 +1,32 @@
package org.baeldung.model; package org.baeldung.model;
public class UserDetails { public class User {
private String firstname; private String firstname;
private String lastname; private String lastname;
private String emailId; private String emailId;
public String getFirstname() { public String getFirstname() {
return firstname; return firstname;
} }
public void setFirstname(final String firstname) { public void setFirstname(final String firstname) {
this.firstname = firstname; this.firstname = firstname;
} }
public String getLastname() { public String getLastname() {
return lastname; return lastname;
} }
public void setLastname(final String lastname) { public void setLastname(final String lastname) {
this.lastname = lastname; this.lastname = lastname;
} }
public String getEmailId() { public String getEmailId() {
return emailId; return emailId;
} }
public void setEmailId(final String emailId) { public void setEmailId(final String emailId) {
this.emailId = emailId; this.emailId = emailId;
} }
} }

View File

@ -6,7 +6,6 @@ import java.util.Set;
import org.baeldung.dialect.CustomDialect; import org.baeldung.dialect.CustomDialect;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Description; import org.springframework.context.annotation.Description;
import org.springframework.context.support.ResourceBundleMessageSource; import org.springframework.context.support.ResourceBundleMessageSource;
@ -24,7 +23,6 @@ import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
@EnableWebMvc @EnableWebMvc
@Configuration @Configuration
@ComponentScan("org.baeldung.controller")
public class ClientWebConfig extends WebMvcConfigurerAdapter { public class ClientWebConfig extends WebMvcConfigurerAdapter {
public ClientWebConfig() { public ClientWebConfig() {

View File

@ -1,31 +1,32 @@
package org.baeldung.controller; package org.baeldung.web.controller;
import org.baeldung.model.UserDetails; import org.baeldung.model.User;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
@Controller @Controller
@RequestMapping("/") @RequestMapping("/")
public class UserController { public class UserController {
@RequestMapping(value = "/", method = RequestMethod.GET) @RequestMapping(value = "/", method = RequestMethod.GET)
public String showForm(final Model model) { public String showForm(final Model model) {
final UserDetails user = new UserDetails(); final User user = new User();
user.setFirstname("John"); user.setFirstname("John");
user.setLastname("Roy"); user.setLastname("Roy");
user.setEmailId("John.Roy@gmail.com"); user.setEmailId("John.Roy@gmail.com");
model.addAttribute("user", user); model.addAttribute("user", user);
return "index"; return "index";
} }
@RequestMapping(value = "/processForm", method = RequestMethod.POST) @RequestMapping(value = "/processForm", method = RequestMethod.POST)
public String processForm(@ModelAttribute(value = "user") final UserDetails user, final Model model) { public String processForm(@ModelAttribute(value = "user") final User user,
// Insert userDetails into DB final Model model) {
model.addAttribute("name", user.getFirstname() + " " + user.getLastname()); // Insert User into DB
return "hello"; model.addAttribute("name", user.getFirstname() + " " + user.getLastname());
} return "hello";
}
}
}