├── README.md ├── springboot-thymeleaf-web-app ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── net │ │ │ └── springboot │ │ │ └── javaguides │ │ │ ├── SpringbootThymeleafWebAppApplication.java │ │ │ ├── controller │ │ │ └── StudentController.java │ │ │ ├── entity │ │ │ └── Student.java │ │ │ └── repository │ │ │ ├── CustomerRepository.java │ │ │ └── StudentRepository.java │ └── resources │ │ ├── application.properties │ │ └── templates │ │ ├── add-student.html │ │ ├── index.html │ │ └── update-student.html │ └── test │ └── java │ └── net │ └── springboot │ └── javaguides │ └── SpringbootThymeleafWebAppApplicationTests.java ├── springmvc-hibernate-crud-web-app ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── net │ │ └── javaguides │ │ └── springmvc │ │ ├── config │ │ ├── AppContext.java │ │ ├── AppInitializer.java │ │ └── WebMvcConfig.java │ │ ├── contoller │ │ └── CustomerController.java │ │ ├── dao │ │ ├── CustomerDAO.java │ │ └── CustomerDAOImpl.java │ │ ├── entity │ │ └── Customer.java │ │ └── service │ │ ├── CustomerService.java │ │ └── CustomerServiceImpl.java │ ├── resources │ └── database.properties │ └── webapp │ ├── WEB-INF │ ├── views │ │ ├── customer-form.jsp │ │ └── list-customers.jsp │ └── web.xml │ ├── index.jsp │ └── resources │ ├── css │ └── bootstrap.min.css │ └── js │ ├── bootstrap.min.js │ └── jquery-1.11.1.min.js ├── springmvc-hibernate-xmlconfig ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── pom.xml ├── springmvc-hibernate5-class-diagram.ucls ├── springmvc-hibernate5-xml-class-diagram.png └── src │ └── main │ ├── java │ └── net │ │ └── javaguides │ │ └── springmvc │ │ ├── controller │ │ ├── CustomerController.java │ │ └── HelloWorldController.java │ │ ├── dao │ │ ├── CustomerDAO.java │ │ └── CustomerDAOImpl.java │ │ ├── entity │ │ └── Customer.java │ │ └── service │ │ ├── CustomerService.java │ │ └── CustomerServiceImpl.java │ ├── resources │ └── database.properties │ └── webapp │ ├── WEB-INF │ ├── spring-mvc-crud-demo-servlet.xml │ ├── views │ │ ├── customer-form.jsp │ │ └── list-customers.jsp │ └── web.xml │ ├── index.jsp │ └── resources │ ├── css │ └── bootstrap.min.css │ └── js │ ├── bootstrap.min.js │ └── jquery-1.11.1.min.js ├── springmvc-java-config-example ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── net │ │ └── javaguides │ │ └── springmvc │ │ ├── config │ │ ├── AppConfig.java │ │ └── SpringMVCFrontController.java │ │ ├── controller │ │ ├── CustomerController.java │ │ ├── HelloWorldController.java │ │ └── SignUpController.java │ │ ├── dao │ │ ├── CustomerDAO.java │ │ └── CustomerDAOImpl.java │ │ ├── model │ │ ├── Customer.java │ │ ├── HelloWorld.java │ │ └── SignUpForm.java │ │ └── service │ │ ├── CustomerService.java │ │ └── CustomerServiceImpl.java │ ├── resources │ └── database.properties │ └── webapp │ ├── WEB-INF │ ├── views │ │ ├── customer-confirmation.jsp │ │ ├── customer-form.jsp │ │ ├── helloworld.jsp │ │ ├── signup-form.jsp │ │ └── signup-success.jsp │ └── web.xml │ ├── index.jsp │ └── resources │ ├── css │ └── bootstrap.min.css │ └── js │ ├── bootstrap.min.js │ └── jquery-1.11.1.min.js ├── springmvc-requestparam-annotation ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ └── java │ └── net │ └── javaguides │ └── springmvc │ └── requestparam │ ├── AppConfig.java │ ├── DemoController.java │ └── MySpringMvcDispatcherServletInitializer.java ├── springmvc5-custom-form-validation ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── net │ │ └── javaguides │ │ └── springmvc │ │ └── form │ │ ├── config │ │ ├── MVCConfig.java │ │ └── SpringMvcDispatcherServletInitializer.java │ │ ├── controller │ │ └── CustomerController.java │ │ ├── model │ │ └── Customer.java │ │ └── validation │ │ ├── CourseCode.java │ │ └── CourseCodeConstraintValidator.java │ └── webapp │ ├── WEB-INF │ └── views │ │ ├── customer-confirmation.jsp │ │ └── customer-form.jsp │ └── index.jsp ├── springmvc5-form-handling ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── net │ │ └── javaguides │ │ └── springmvc │ │ └── form │ │ ├── config │ │ ├── MVCConfig.java │ │ └── SpringMvcDispatcherServletInitializer.java │ │ ├── controller │ │ └── SignUpController.java │ │ └── model │ │ └── SignUpForm.java │ └── webapp │ ├── WEB-INF │ └── views │ │ ├── signup-form.jsp │ │ └── signup-success.jsp │ └── resources │ ├── css │ └── bootstrap.min.css │ └── js │ ├── bootstrap.min.js │ └── jquery-1.11.1.min.js ├── springmvc5-form-tags ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── net │ │ └── javaguides │ │ └── springmvc │ │ └── form │ │ ├── config │ │ ├── MVCConfig.java │ │ └── SpringMvcDispatcherServletInitializer.java │ │ ├── controller │ │ └── UserController.java │ │ └── model │ │ └── User.java │ └── webapp │ ├── WEB-INF │ └── views │ │ ├── user.jsp │ │ └── users.jsp │ └── index.jsp ├── springmvc5-form-validation ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── net │ │ └── javaguides │ │ └── springmvc │ │ └── form │ │ ├── config │ │ ├── MVCConfig.java │ │ └── SpringMvcDispatcherServletInitializer.java │ │ ├── controller │ │ └── CustomerController.java │ │ └── model │ │ └── Customer.java │ └── webapp │ ├── WEB-INF │ └── views │ │ ├── customer-confirmation.jsp │ │ └── customer-form.jsp │ └── index.jsp ├── springmvc5-helloworld-exmaple ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── net │ │ └── javaguides │ │ └── springmvc │ │ └── helloworld │ │ ├── config │ │ ├── AppConfig.java │ │ └── SpringMvcDispatcherServletInitializer.java │ │ ├── controller │ │ └── HelloWorldController.java │ │ └── model │ │ └── HelloWorld.java │ └── webapp │ ├── WEB-INF │ └── views │ │ └── helloworld.jsp │ └── index.jsp ├── springmvc5-hibernate5-jsp-mysql-example ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── bin │ ├── .settings │ │ ├── .jsdtscope │ │ ├── org.eclipse.jdt.core.prefs │ │ ├── org.eclipse.m2e.core.prefs │ │ ├── org.eclipse.wst.common.component │ │ ├── org.eclipse.wst.common.project.facet.core.xml │ │ ├── org.eclipse.wst.jsdt.ui.superType.container │ │ ├── org.eclipse.wst.jsdt.ui.superType.name │ │ └── org.eclipse.wst.validation.prefs │ ├── pom.xml │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── net │ │ │ │ └── javaguides │ │ │ │ └── springmvc │ │ │ │ ├── config │ │ │ │ ├── AppContext.class │ │ │ │ ├── AppInitializer.class │ │ │ │ └── WebMvcConfig.class │ │ │ │ ├── controller │ │ │ │ └── CustomerController.class │ │ │ │ ├── dao │ │ │ │ ├── CustomerDAO.class │ │ │ │ └── CustomerDAOImpl.class │ │ │ │ ├── entity │ │ │ │ └── Customer.class │ │ │ │ └── service │ │ │ │ ├── CustomerService.class │ │ │ │ └── CustomerServiceImpl.class │ │ │ ├── resources │ │ │ └── database.properties │ │ │ └── webapp │ │ │ ├── WEB-INF │ │ │ └── views │ │ │ │ ├── customer-form.jsp │ │ │ │ └── list-customers.jsp │ │ │ ├── index.jsp │ │ │ └── resources │ │ │ ├── css │ │ │ └── bootstrap.min.css │ │ │ └── js │ │ │ ├── bootstrap.min.js │ │ │ └── jquery-1.11.1.min.js │ └── target │ │ ├── classes │ │ └── database.properties │ │ └── m2e-wtp │ │ └── web-resources │ │ └── META-INF │ │ ├── MANIFEST.MF │ │ └── maven │ │ └── net.javaguides.springmvc │ │ └── springmvc5-hibernate5-jsp-mysql-example │ │ ├── pom.properties │ │ └── pom.xml ├── pom.xml ├── springmvc-hibernate5-class-diagram.png ├── springmvc-hibernate5-class-diagram.ucls └── src │ └── main │ ├── java │ └── net │ │ └── javaguides │ │ └── springmvc │ │ ├── config │ │ ├── AppContext.java │ │ ├── AppInitializer.java │ │ └── WebMvcConfig.java │ │ ├── controller │ │ └── CustomerController.java │ │ ├── dao │ │ ├── CustomerDAO.java │ │ └── CustomerDAOImpl.java │ │ ├── entity │ │ └── Customer.java │ │ └── service │ │ ├── CustomerService.java │ │ └── CustomerServiceImpl.java │ ├── resources │ └── database.properties │ └── webapp │ ├── WEB-INF │ └── views │ │ ├── customer-form.jsp │ │ ├── hello.jsp │ │ ├── list-customers.jsp │ │ └── signup-success.jsp │ ├── index.jsp │ └── resources │ ├── css │ └── bootstrap.min.css │ └── js │ ├── bootstrap.min.js │ └── jquery-1.11.1.min.js ├── springmvc5-requestparam-annotation ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── net │ │ └── javaguides │ │ └── springmvc │ │ └── requestparam │ │ ├── config │ │ ├── AppConfig.java │ │ └── MySpringMvcDispatcherServletInitializer.java │ │ └── controller │ │ └── DemoController.java │ └── webapp │ ├── WEB-INF │ ├── views │ │ └── helloworld.jsp │ └── web.xml │ └── index.jsp ├── springmvc5-slf4j-logback-example ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── net │ │ └── javaguides │ │ └── springmvc │ │ ├── config │ │ ├── ServletInitializer.java │ │ └── WebConfig.java │ │ └── controller │ │ └── HelloWorldController.java │ ├── resources │ └── logback.xml │ └── webapp │ ├── WEB-INF │ ├── views │ │ └── logs.jsp │ └── web.xml │ └── index.jsp └── springmvc5-springdatajpa2-jsp-mysql-example ├── .classpath ├── .project ├── .settings ├── .jsdtscope ├── org.eclipse.jdt.core.prefs ├── org.eclipse.m2e.core.prefs ├── org.eclipse.wst.common.component ├── org.eclipse.wst.common.project.facet.core.xml ├── org.eclipse.wst.jsdt.ui.superType.container ├── org.eclipse.wst.jsdt.ui.superType.name └── org.eclipse.wst.validation.prefs ├── bin └── src │ └── main │ └── java │ └── net │ └── javaguides │ └── springmvc │ ├── config │ ├── AppInitializer.class │ ├── PersistenceJPAConfig.class │ └── WebMvcConfig.class │ ├── controller │ └── CustomerController.class │ ├── entity │ └── Customer.class │ ├── exception │ └── ResourceNotFoundException.class │ ├── repository │ └── CustomerRepository.class │ └── service │ ├── CustomerService.class │ └── CustomerServiceImpl.class ├── pom.xml ├── springmvc-springdatajpa-class-diagram.png ├── springmvc-springdatajpa-class-diagram.ucls └── src └── main ├── java └── net │ └── javaguides │ └── springmvc │ ├── config │ ├── AppInitializer.java │ ├── PersistenceJPAConfig.java │ └── WebMvcConfig.java │ ├── controller │ └── CustomerController.java │ ├── entity │ └── Customer.java │ ├── exception │ └── ResourceNotFoundException.java │ ├── repository │ └── CustomerRepository.java │ └── service │ ├── CustomerService.java │ └── CustomerServiceImpl.java ├── resources ├── database.properties └── logback.xml └── webapp ├── WEB-INF └── views │ ├── customer-form.jsp │ └── list-customers.jsp ├── index.jsp └── resources ├── css └── bootstrap.min.css └── js ├── bootstrap.min.js └── jquery-1.11.1.min.js /springboot-thymeleaf-web-app/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /springboot-thymeleaf-web-app/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springboot-thymeleaf-web-app/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /springboot-thymeleaf-web-app/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.2/apache-maven-3.6.2-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar 3 | -------------------------------------------------------------------------------- /springboot-thymeleaf-web-app/src/main/java/net/springboot/javaguides/SpringbootThymeleafWebAppApplication.java: -------------------------------------------------------------------------------- 1 | package net.springboot.javaguides; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootThymeleafWebAppApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootThymeleafWebAppApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springboot-thymeleaf-web-app/src/main/java/net/springboot/javaguides/entity/Student.java: -------------------------------------------------------------------------------- 1 | package net.springboot.javaguides.entity; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.GenerationType; 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | 10 | @Entity 11 | @Table(name = "students") 12 | public class Student { 13 | 14 | @Id 15 | @GeneratedValue(strategy = GenerationType.AUTO) 16 | private long id; 17 | 18 | @Column(name = "name") 19 | private String name; 20 | 21 | @Column(name = "email") 22 | private String email; 23 | 24 | @Column(name = "phone_no") 25 | private long phoneNo; 26 | 27 | 28 | public Student() { 29 | super(); 30 | } 31 | 32 | public Student(String name, String email) { 33 | super(); 34 | this.name = name; 35 | this.email = email; 36 | } 37 | 38 | public long getId() { 39 | return id; 40 | } 41 | public void setId(long id) { 42 | this.id = id; 43 | } 44 | public String getName() { 45 | return name; 46 | } 47 | public void setName(String name) { 48 | this.name = name; 49 | } 50 | public String getEmail() { 51 | return email; 52 | } 53 | public void setEmail(String email) { 54 | this.email = email; 55 | } 56 | public long getPhoneNo() { 57 | return phoneNo; 58 | } 59 | public void setPhoneNo(long phoneNo) { 60 | this.phoneNo = phoneNo; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /springboot-thymeleaf-web-app/src/main/java/net/springboot/javaguides/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package net.springboot.javaguides.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import net.springboot.javaguides.entity.Customer; 6 | 7 | public interface CustomerRepository extends JpaRepository{ 8 | // spring data jpa provides full crud operations for Customer entity 9 | } 10 | -------------------------------------------------------------------------------- /springboot-thymeleaf-web-app/src/main/java/net/springboot/javaguides/repository/StudentRepository.java: -------------------------------------------------------------------------------- 1 | package net.springboot.javaguides.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import net.springboot.javaguides.entity.Student; 9 | 10 | @Repository 11 | public interface StudentRepository extends JpaRepository{ 12 | List findByName(String name); 13 | } 14 | -------------------------------------------------------------------------------- /springboot-thymeleaf-web-app/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url = jdbc:mysql://localhost:3306/demo?useSSL=false 2 | spring.datasource.username = root 3 | spring.datasource.password = root 4 | 5 | 6 | ## Hibernate Properties 7 | # The SQL dialect makes Hibernate generate better SQL for the chosen database 8 | spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect 9 | 10 | # Hibernate ddl auto (create, create-drop, validate, update) 11 | spring.jpa.hibernate.ddl-auto = update 12 | 13 | spring.jpa.show-sql=true 14 | -------------------------------------------------------------------------------- /springboot-thymeleaf-web-app/src/test/java/net/springboot/javaguides/SpringbootThymeleafWebAppApplicationTests.java: -------------------------------------------------------------------------------- 1 | package net.springboot.javaguides; 2 | 3 | import org.junit.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SpringbootThymeleafWebAppApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springmvc-hibernate-crud-web-app 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | org.eclipse.wst.jsdt.core.jsNature 36 | 37 | 38 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.release=disabled 14 | org.eclipse.jdt.core.compiler.source=1.8 15 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/src/main/java/net/javaguides/springmvc/config/AppInitializer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | /** 6 | * @author Ramesh Fadatare 7 | */ 8 | public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 9 | 10 | @Override 11 | protected Class < ? > [] getRootConfigClasses() { 12 | return new Class[] { 13 | AppContext.class 14 | }; 15 | //return null; 16 | } 17 | 18 | @Override 19 | protected Class < ? > [] getServletConfigClasses() { 20 | return new Class[] { 21 | WebMvcConfig.class 22 | }; 23 | } 24 | 25 | @Override 26 | protected String[] getServletMappings() { 27 | return new String[] { "/" }; 28 | } 29 | } -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/src/main/java/net/javaguides/springmvc/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 8 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 9 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 10 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 11 | import org.springframework.web.servlet.view.JstlView; 12 | 13 | /** 14 | * @author Ramesh Fadatare 15 | */ 16 | 17 | @Configuration 18 | @EnableWebMvc 19 | @ComponentScan(basePackages = { 20 | "net.javaguides.springmvc" 21 | }) 22 | public class WebMvcConfig implements WebMvcConfigurer { 23 | 24 | @Bean 25 | public InternalResourceViewResolver resolver() { 26 | InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 27 | resolver.setViewClass(JstlView.class); 28 | resolver.setPrefix("/WEB-INF/views/"); 29 | resolver.setSuffix(".jsp"); 30 | return resolver; 31 | } 32 | 33 | @Override 34 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 35 | registry 36 | .addResourceHandler("/resources/**") 37 | .addResourceLocations("/resources/"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/src/main/java/net/javaguides/springmvc/dao/CustomerDAO.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.dao; 2 | 3 | import java.util.List; 4 | 5 | import net.javaguides.springmvc.entity.Customer; 6 | 7 | public interface CustomerDAO { 8 | 9 | public List < Customer > getCustomers(); 10 | 11 | public void saveCustomer(Customer theCustomer); 12 | 13 | public Customer getCustomer(int theId); 14 | 15 | public void deleteCustomer(int theId); 16 | } 17 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/src/main/java/net/javaguides/springmvc/dao/CustomerDAOImpl.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.dao; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.Query; 6 | import javax.persistence.criteria.CriteriaBuilder; 7 | import javax.persistence.criteria.CriteriaQuery; 8 | import javax.persistence.criteria.Root; 9 | 10 | import org.hibernate.Session; 11 | import org.hibernate.SessionFactory; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Repository; 14 | 15 | import net.javaguides.springmvc.entity.Customer; 16 | 17 | @Repository 18 | public class CustomerDAOImpl implements CustomerDAO { 19 | 20 | @Autowired 21 | private SessionFactory sessionFactory; 22 | 23 | @Override 24 | public List < Customer > getCustomers() { 25 | Session session = sessionFactory.getCurrentSession(); 26 | CriteriaBuilder cb = session.getCriteriaBuilder(); 27 | CriteriaQuery < Customer > cq = cb.createQuery(Customer.class); 28 | Root < Customer > root = cq.from(Customer.class); 29 | cq.select(root); 30 | Query query = session.createQuery(cq); 31 | return query.getResultList(); 32 | } 33 | 34 | @Override 35 | public void deleteCustomer(int id) { 36 | Session session = sessionFactory.getCurrentSession(); 37 | Customer book = session.byId(Customer.class).load(id); 38 | session.delete(book); 39 | } 40 | 41 | @Override 42 | public void saveCustomer(Customer theCustomer) { 43 | Session currentSession = sessionFactory.getCurrentSession(); 44 | currentSession.saveOrUpdate(theCustomer); 45 | } 46 | 47 | @Override 48 | public Customer getCustomer(int theId) { 49 | Session currentSession = sessionFactory.getCurrentSession(); 50 | Customer theCustomer = currentSession.get(Customer.class, theId); 51 | return theCustomer; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/src/main/java/net/javaguides/springmvc/entity/Customer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.entity; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.GenerationType; 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | 10 | @Entity 11 | @Table(name = "customer") 12 | public class Customer { 13 | 14 | @Id 15 | @GeneratedValue(strategy = GenerationType.IDENTITY) 16 | @Column(name = "id") 17 | private int id; 18 | 19 | @Column(name = "first_name") 20 | private String firstName; 21 | 22 | @Column(name = "last_name") 23 | private String lastName; 24 | 25 | @Column(name = "email") 26 | private String email; 27 | 28 | public Customer() { 29 | 30 | } 31 | 32 | public int getId() { 33 | return id; 34 | } 35 | 36 | public void setId(int id) { 37 | this.id = id; 38 | } 39 | 40 | public String getFirstName() { 41 | return firstName; 42 | } 43 | 44 | public void setFirstName(String firstName) { 45 | this.firstName = firstName; 46 | } 47 | 48 | public String getLastName() { 49 | return lastName; 50 | } 51 | 52 | public void setLastName(String lastName) { 53 | this.lastName = lastName; 54 | } 55 | 56 | public String getEmail() { 57 | return email; 58 | } 59 | 60 | public void setEmail(String email) { 61 | this.email = email; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "Customer [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", email=" + email + "]"; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/src/main/java/net/javaguides/springmvc/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.service; 2 | 3 | import java.util.List; 4 | 5 | import net.javaguides.springmvc.entity.Customer; 6 | 7 | public interface CustomerService { 8 | 9 | public List < Customer > getCustomers(); 10 | 11 | public void saveCustomer(Customer theCustomer); 12 | 13 | public Customer getCustomer(int theId); 14 | 15 | public void deleteCustomer(int theId); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/src/main/java/net/javaguides/springmvc/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | import net.javaguides.springmvc.dao.CustomerDAO; 10 | import net.javaguides.springmvc.entity.Customer; 11 | 12 | @Service 13 | public class CustomerServiceImpl implements CustomerService { 14 | 15 | @Autowired 16 | private CustomerDAO customerDAO; 17 | 18 | @Override 19 | @Transactional 20 | public List < Customer > getCustomers() { 21 | return customerDAO.getCustomers(); 22 | } 23 | 24 | @Override 25 | @Transactional 26 | public void saveCustomer(Customer theCustomer) { 27 | customerDAO.saveCustomer(theCustomer); 28 | } 29 | 30 | @Override 31 | @Transactional 32 | public Customer getCustomer(int theId) { 33 | return customerDAO.getCustomer(theId); 34 | } 35 | 36 | @Override 37 | @Transactional 38 | public void deleteCustomer(int theId) { 39 | customerDAO.deleteCustomer(theId); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/src/main/resources/database.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName = com.mysql.jdbc.Driver 2 | jdbc.url = jdbc:mysql://localhost:3306/demo?useSSL=false 3 | jdbc.username = root 4 | jdbc.password = root 5 | hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect 6 | hibernate.show_sql = true 7 | hibernate.format_sql = true 8 | hibernate.hbm2ddl.auto = update -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | Archetype Created Web Application 7 | 8 | -------------------------------------------------------------------------------- /springmvc-hibernate-crud-web-app/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springmvc-hibernate-xmlconfig 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | org.eclipse.wst.jsdt.core.jsNature 36 | 37 | 38 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.release=disabled 9 | org.eclipse.jdt.core.compiler.source=1.5 10 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/springmvc-hibernate5-xml-class-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc-hibernate-xmlconfig/springmvc-hibernate5-xml-class-diagram.png -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/src/main/java/net/javaguides/springmvc/controller/HelloWorldController.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class HelloWorldController { 8 | @GetMapping("/hello") 9 | public String hello() { 10 | return "hello"; 11 | } 12 | } -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/src/main/java/net/javaguides/springmvc/dao/CustomerDAO.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.dao; 2 | 3 | import java.util.List; 4 | 5 | import net.javaguides.springmvc.entity.Customer; 6 | 7 | public interface CustomerDAO { 8 | 9 | public List getCustomers(); 10 | 11 | public void saveCustomer(Customer theCustomer); 12 | 13 | public Customer getCustomer(int theId); 14 | 15 | public void deleteCustomer(int theId); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/src/main/java/net/javaguides/springmvc/dao/CustomerDAOImpl.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.dao; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.Query; 6 | import javax.persistence.criteria.CriteriaBuilder; 7 | import javax.persistence.criteria.CriteriaQuery; 8 | import javax.persistence.criteria.Root; 9 | 10 | import org.hibernate.Session; 11 | import org.hibernate.SessionFactory; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Repository; 14 | 15 | import net.javaguides.springmvc.entity.Customer; 16 | 17 | @Repository 18 | public class CustomerDAOImpl implements CustomerDAO { 19 | 20 | @Autowired 21 | private SessionFactory sessionFactory; 22 | 23 | @Override 24 | public List getCustomers() { 25 | Session session = sessionFactory.getCurrentSession(); 26 | CriteriaBuilder cb = session.getCriteriaBuilder(); 27 | CriteriaQuery cq = cb.createQuery(Customer.class); 28 | Root root = cq.from(Customer.class); 29 | cq.select(root); 30 | Query query = session.createQuery(cq); 31 | return query.getResultList(); 32 | } 33 | 34 | @Override 35 | public void deleteCustomer(int id) { 36 | Session session = sessionFactory.getCurrentSession(); 37 | Customer book = session.byId(Customer.class).load(id); 38 | session.delete(book); 39 | } 40 | 41 | @Override 42 | public void saveCustomer(Customer theCustomer) { 43 | Session currentSession = sessionFactory.getCurrentSession(); 44 | currentSession.saveOrUpdate(theCustomer); 45 | } 46 | 47 | @Override 48 | public Customer getCustomer(int theId) { 49 | Session currentSession = sessionFactory.getCurrentSession(); 50 | Customer theCustomer = currentSession.get(Customer.class, theId); 51 | return theCustomer; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/src/main/java/net/javaguides/springmvc/entity/Customer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.entity; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.GenerationType; 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | 10 | @Entity 11 | @Table(name="customer") 12 | public class Customer { 13 | 14 | @Id 15 | @GeneratedValue(strategy=GenerationType.IDENTITY) 16 | @Column(name="id") 17 | private int id; 18 | 19 | @Column(name="first_name") 20 | private String firstName; 21 | 22 | @Column(name="last_name") 23 | private String lastName; 24 | 25 | @Column(name="email") 26 | private String email; 27 | 28 | public Customer() { 29 | 30 | } 31 | 32 | public int getId() { 33 | return id; 34 | } 35 | 36 | public void setId(int id) { 37 | this.id = id; 38 | } 39 | 40 | public String getFirstName() { 41 | return firstName; 42 | } 43 | 44 | public void setFirstName(String firstName) { 45 | this.firstName = firstName; 46 | } 47 | 48 | public String getLastName() { 49 | return lastName; 50 | } 51 | 52 | public void setLastName(String lastName) { 53 | this.lastName = lastName; 54 | } 55 | 56 | public String getEmail() { 57 | return email; 58 | } 59 | 60 | public void setEmail(String email) { 61 | this.email = email; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "Customer [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", email=" + email + "]"; 67 | } 68 | } 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/src/main/java/net/javaguides/springmvc/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.service; 2 | 3 | import java.util.List; 4 | 5 | import net.javaguides.springmvc.entity.Customer; 6 | 7 | public interface CustomerService { 8 | 9 | public List getCustomers(); 10 | 11 | public void saveCustomer(Customer theCustomer); 12 | 13 | public Customer getCustomer(int theId); 14 | 15 | public void deleteCustomer(int theId); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/src/main/java/net/javaguides/springmvc/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | import net.javaguides.springmvc.dao.CustomerDAO; 10 | import net.javaguides.springmvc.entity.Customer; 11 | 12 | @Service 13 | public class CustomerServiceImpl implements CustomerService { 14 | 15 | @Autowired 16 | private CustomerDAO customerDAO; 17 | 18 | @Override 19 | @Transactional 20 | public List getCustomers() { 21 | return customerDAO.getCustomers(); 22 | } 23 | 24 | @Override 25 | @Transactional 26 | public void saveCustomer(Customer theCustomer) { 27 | customerDAO.saveCustomer(theCustomer); 28 | } 29 | 30 | @Override 31 | @Transactional 32 | public Customer getCustomer(int theId) { 33 | return customerDAO.getCustomer(theId); 34 | } 35 | 36 | @Override 37 | @Transactional 38 | public void deleteCustomer(int theId) { 39 | customerDAO.deleteCustomer(theId); 40 | } 41 | } 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/src/main/resources/database.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName = com.mysql.jdbc.Driver 2 | jdbc.url = jdbc:mysql://localhost:3306/demo?useSSL=false 3 | jdbc.username = root 4 | jdbc.password = root 5 | hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect 6 | hibernate.show_sql = true 7 | hibernate.format_sql = true 8 | hibernate.hbm2ddl.auto = update -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | spring-mvc-crud-demo 4 | 5 | 6 | index.jsp 7 | index.html 8 | 9 | 10 | 11 | dispatcher 12 | org.springframework.web.servlet.DispatcherServlet 13 | 14 | contextConfigLocation 15 | /WEB-INF/spring-mvc-crud-demo-servlet.xml 16 | 17 | 1 18 | 19 | 20 | 21 | dispatcher 22 | / 23 | 24 | -------------------------------------------------------------------------------- /springmvc-hibernate-xmlconfig/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /springmvc-java-config-example/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /springmvc-java-config-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springmvc-java-config-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | org.eclipse.wst.jsdt.core.jsNature 36 | 37 | 38 | -------------------------------------------------------------------------------- /springmvc-java-config-example/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springmvc-java-config-example/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.release=disabled 14 | org.eclipse.jdt.core.compiler.source=1.8 15 | -------------------------------------------------------------------------------- /springmvc-java-config-example/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springmvc-java-config-example/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /springmvc-java-config-example/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /springmvc-java-config-example/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /springmvc-java-config-example/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /springmvc-java-config-example/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/java/net/javaguides/springmvc/config/SpringMVCFrontController.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | public class SpringMVCFrontController extends AbstractAnnotationConfigDispatcherServletInitializer { 6 | 7 | @Override 8 | protected Class[] getRootConfigClasses() { 9 | // TODO Auto-generated method stub 10 | return null; 11 | } 12 | 13 | @Override 14 | protected Class[] getServletConfigClasses() { 15 | // TODO Auto-generated method stub 16 | return new Class[] { 17 | AppConfig.class 18 | }; 19 | } 20 | 21 | @Override 22 | protected String[] getServletMappings() { 23 | return new String[] { "/" }; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/java/net/javaguides/springmvc/controller/CustomerController.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.controller; 2 | 3 | import javax.validation.Valid; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.propertyeditors.StringTrimmerEditor; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.ui.Model; 9 | import org.springframework.validation.BindingResult; 10 | import org.springframework.web.bind.WebDataBinder; 11 | import org.springframework.web.bind.annotation.InitBinder; 12 | import org.springframework.web.bind.annotation.ModelAttribute; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | 15 | import net.javaguides.springmvc.model.Customer; 16 | import net.javaguides.springmvc.service.CustomerService; 17 | 18 | @Controller 19 | @RequestMapping("/customer") 20 | public class CustomerController { 21 | 22 | // add an initbinder ... to convert trim input strings 23 | // remove leading and trailing whitespace 24 | // resolve issue for our validation 25 | 26 | @Autowired 27 | private CustomerService customerService; 28 | 29 | @InitBinder 30 | public void initBinder(WebDataBinder dataBinder) { 31 | 32 | StringTrimmerEditor stringTrimmerEditor = new StringTrimmerEditor(true); 33 | 34 | dataBinder.registerCustomEditor(String.class, stringTrimmerEditor); 35 | } 36 | 37 | 38 | @RequestMapping("/showForm") 39 | public String showForm(Model theModel) { 40 | 41 | theModel.addAttribute("customer", new Customer()); 42 | 43 | return "customer-form"; 44 | } 45 | 46 | @RequestMapping("/processForm") 47 | public String processForm( 48 | @Valid @ModelAttribute("customer") Customer theCustomer, 49 | BindingResult theBindingResult) { 50 | 51 | if (theBindingResult.hasErrors()) { 52 | return "customer-form"; 53 | } else { 54 | customerService.saveCustomer(theCustomer); 55 | return "customer-confirmation"; 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/java/net/javaguides/springmvc/controller/HelloWorldController.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.controller; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | import net.javaguides.springmvc.model.HelloWorld; 10 | 11 | /** 12 | * @author Ramesh Fadatare 13 | */ 14 | @Controller 15 | public class HelloWorldController { 16 | 17 | @RequestMapping("/helloworld") 18 | public String handler(Model model) { 19 | 20 | HelloWorld helloWorld = new HelloWorld(); 21 | helloWorld.setMessage("Hello World Example Using Spring MVC 5!!!"); 22 | helloWorld.setDateTime(LocalDateTime.now().toString()); 23 | model.addAttribute("helloWorld", helloWorld); 24 | return "helloworld"; 25 | } 26 | } -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/java/net/javaguides/springmvc/controller/SignUpController.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.ModelAttribute; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | 9 | import net.javaguides.springmvc.model.SignUpForm; 10 | 11 | /** 12 | * SignUpController class for User sign up form processing 13 | * 14 | * @author Ramesh Fadatare 15 | */ 16 | @Controller 17 | public class SignUpController { 18 | 19 | /** 20 | * Create new signUpForm object for empty from 21 | * 22 | * @return 23 | */ 24 | @ModelAttribute("signUpForm") 25 | public SignUpForm setSignUpForm() { 26 | return new SignUpForm(); 27 | } 28 | 29 | /** 30 | * Method to show the initial HTML form 31 | * 32 | * @return 33 | */ 34 | @GetMapping("/showSignUpForm") 35 | public String showForm() { 36 | return "signup-form"; 37 | } 38 | 39 | /** 40 | * Save User sign up form 41 | * 42 | * @param signUpForm 43 | * @param model 44 | * @return 45 | */ 46 | @PostMapping("/saveSignUpForm") 47 | public String saveUser(@ModelAttribute("signUpForm") SignUpForm signUpForm, Model model) { 48 | 49 | // Implement business logic to save user details into a database 50 | // ..... 51 | 52 | System.out.println("FirstName : " + signUpForm.getFirstName()); 53 | System.out.println("LastName : " + signUpForm.getLastName()); 54 | System.out.println("Username : " + signUpForm.getUserName()); 55 | System.out.println("Password : " + signUpForm.getPassword()); 56 | System.out.println("Email : " + signUpForm.getEmail()); 57 | 58 | model.addAttribute("message", "User SignUp successfully."); 59 | model.addAttribute("user", signUpForm); 60 | 61 | return "signup-success"; 62 | } 63 | } -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/java/net/javaguides/springmvc/dao/CustomerDAO.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.dao; 2 | 3 | import net.javaguides.springmvc.model.Customer; 4 | 5 | public interface CustomerDAO { 6 | void saveCustomer(Customer theCustomer); 7 | } 8 | -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/java/net/javaguides/springmvc/dao/CustomerDAOImpl.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.dao; 2 | 3 | import org.hibernate.Session; 4 | import org.hibernate.SessionFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import net.javaguides.springmvc.model.Customer; 9 | 10 | @Repository 11 | public class CustomerDAOImpl implements CustomerDAO { 12 | 13 | @Autowired 14 | private SessionFactory sessionFactory; 15 | 16 | @Override 17 | public void saveCustomer(Customer theCustomer) { 18 | Session currentSession = sessionFactory.getCurrentSession(); 19 | currentSession.saveOrUpdate(theCustomer); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/java/net/javaguides/springmvc/model/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.model; 2 | 3 | public class HelloWorld { 4 | private String message; 5 | private String dateTime; 6 | 7 | public String getMessage() { 8 | return message; 9 | } 10 | 11 | public void setMessage(String message) { 12 | this.message = message; 13 | } 14 | 15 | public String getDateTime() { 16 | return dateTime; 17 | } 18 | 19 | public void setDateTime(String dateTime) { 20 | this.dateTime = dateTime; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/java/net/javaguides/springmvc/model/SignUpForm.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.model; 2 | 3 | public class SignUpForm { 4 | private String firstName; 5 | private String lastName; 6 | private String email; 7 | private String userName; 8 | private String password; 9 | 10 | public String getFirstName() { 11 | return firstName; 12 | } 13 | 14 | public void setFirstName(String firstName) { 15 | this.firstName = firstName; 16 | } 17 | 18 | public String getLastName() { 19 | return lastName; 20 | } 21 | 22 | public void setLastName(String lastName) { 23 | this.lastName = lastName; 24 | } 25 | 26 | public String getEmail() { 27 | return email; 28 | } 29 | 30 | public void setEmail(String email) { 31 | this.email = email; 32 | } 33 | 34 | public String getUserName() { 35 | return userName; 36 | } 37 | 38 | public void setUserName(String userName) { 39 | this.userName = userName; 40 | } 41 | 42 | public String getPassword() { 43 | return password; 44 | } 45 | 46 | public void setPassword(String password) { 47 | this.password = password; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/java/net/javaguides/springmvc/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.service; 2 | 3 | import net.javaguides.springmvc.model.Customer; 4 | 5 | public interface CustomerService { 6 | public void saveCustomer(Customer theCustomer); 7 | } 8 | -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/java/net/javaguides/springmvc/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | import org.springframework.transaction.annotation.Transactional; 6 | 7 | import net.javaguides.springmvc.dao.CustomerDAO; 8 | import net.javaguides.springmvc.model.Customer; 9 | 10 | @Service 11 | public class CustomerServiceImpl implements CustomerService { 12 | 13 | @Autowired 14 | private CustomerDAO customerDAO; 15 | 16 | @Override 17 | @Transactional 18 | public void saveCustomer(Customer theCustomer) { 19 | customerDAO.saveCustomer(theCustomer); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/resources/database.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName = com.mysql.jdbc.Driver 2 | jdbc.url = jdbc:mysql://localhost:3306/demo?useSSL=false 3 | jdbc.username = root 4 | jdbc.password = root 5 | hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect 6 | hibernate.show_sql = true 7 | hibernate.format_sql = true 8 | hibernate.hbm2ddl.auto = update -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/webapp/WEB-INF/views/customer-confirmation.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | 3 | 4 | 5 | 6 | 7 | <%@ page isELIgnored="false" %> 8 | Customer Confirmation 9 | 10 | 11 | 12 | 13 | The customer is confirmed: ${customer.firstName} ${customer.lastName} 14 | 15 |

Free passes: ${customer.freePasses} 16 | 17 |

Email: ${customer.email} 18 | 19 |

Postal Code: ${customer.postalCode} 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/webapp/WEB-INF/views/customer-form.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 2 | 3 | 4 | 5 | 6 | Customer Registration Form 7 | 8 | 13 | 14 | 15 | 16 |

Spring MVC 5 - Form Validation Example

17 | Fill out the form. Asterisk (*) means required. 18 |

19 | 20 | 21 | 22 | First name: 23 | 24 | 25 |

Last name (*): 26 | 27 | 28 | 29 |

Free passes (*): 30 | 31 | 32 | 33 |

Email (*): 34 | 35 | 36 | 37 |

Postal Code: 38 | 39 | 40 | 41 |

42 | 43 | 44 | 45 |
46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/webapp/WEB-INF/views/helloworld.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 | 5 | 6 | <%@ page isELIgnored="false" %> 7 | 8 | Spring 5 MVC - Hello World Example | javaguides.net 9 | 10 | 11 |

${helloWorld.message}

12 |

Server date time is : ${helloWorld.dateTime}

13 | 14 | -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/webapp/WEB-INF/views/signup-success.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 | 5 | 6 | <%@ page isELIgnored="false" %> 7 | 8 | javaguides.net 9 | " 10 | rel="stylesheet"> 11 | 12 | 13 | 14 | 15 |
16 |
17 |

${message}

18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
First Name : ${user.firstName}
Last Name : ${user.lastName}
UserName : ${user.userName}
Email : ${user.email}
34 |
35 |
36 | 37 | -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | Archetype Created Web Application 7 | 8 | -------------------------------------------------------------------------------- /springmvc-java-config-example/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /springmvc-requestparam-annotation/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /springmvc-requestparam-annotation/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springmvc-requestparam-annotation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.jdt.core.javanature 26 | org.eclipse.m2e.core.maven2Nature 27 | org.eclipse.wst.common.project.facet.core.nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /springmvc-requestparam-annotation/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.release=disabled 14 | org.eclipse.jdt.core.compiler.source=1.8 15 | -------------------------------------------------------------------------------- /springmvc-requestparam-annotation/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springmvc-requestparam-annotation/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | net.javaguides.springmvc 6 | springmvc-requestparam-annotation 7 | 0.0.1-SNAPSHOT 8 | http://maven.apache.org 9 | 10 | 11 | UTF-8 12 | 13 | 14 | 15 | 16 | 17 | org.springframework 18 | spring-webmvc 19 | 5.1.0.RELEASE 20 | 21 | 22 | 23 | 24 | javax.servlet.jsp.jstl 25 | javax.servlet.jsp.jstl-api 26 | 1.2.1 27 | 28 | 29 | taglibs 30 | standard 31 | 1.1.2 32 | 33 | 34 | 35 | 36 | javax.servlet 37 | javax.servlet-api 38 | 3.1.0 39 | provided 40 | 41 | 42 | 43 | 44 | javax.servlet.jsp 45 | javax.servlet.jsp-api 46 | 2.3.1 47 | provided 48 | 49 | 50 | 51 | src/main/java 52 | 53 | 54 | maven-compiler-plugin 55 | 3.5.1 56 | 57 | 1.8 58 | 1.8 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /springmvc-requestparam-annotation/src/main/java/net/javaguides/springmvc/requestparam/AppConfig.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.requestparam; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 8 | import org.springframework.web.servlet.view.JstlView; 9 | 10 | @Configuration 11 | @EnableWebMvc 12 | @ComponentScan(basePackages = { "net.javaguides.springmvc.requestparam" }) 13 | public class AppConfig { 14 | 15 | @Bean 16 | public InternalResourceViewResolver resolver() { 17 | InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 18 | resolver.setViewClass(JstlView.class); 19 | resolver.setPrefix("/WEB-INF/views/"); 20 | resolver.setSuffix(".jsp"); 21 | return resolver; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /springmvc-requestparam-annotation/src/main/java/net/javaguides/springmvc/requestparam/MySpringMvcDispatcherServletInitializer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.requestparam; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | public class MySpringMvcDispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 6 | 7 | @Override 8 | protected Class[] getRootConfigClasses() { 9 | // TODO Auto-generated method stub 10 | return null; 11 | } 12 | 13 | @Override 14 | protected Class[] getServletConfigClasses() { 15 | return new Class[] { AppConfig.class }; 16 | } 17 | 18 | @Override 19 | protected String[] getServletMappings() { 20 | return new String[] { "/" }; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springmvc5-custom-form-validation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | org.eclipse.wst.jsdt.core.jsNature 36 | 37 | 38 | -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.release=disabled 14 | org.eclipse.jdt.core.compiler.source=1.8 15 | -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/src/main/java/net/javaguides/springmvc/form/config/MVCConfig.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 8 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 9 | import org.springframework.web.servlet.view.JstlView; 10 | 11 | /** 12 | * @author Ramesh Fadatare 13 | */ 14 | 15 | @Configuration 16 | @EnableWebMvc 17 | @ComponentScan(basePackages = { "net.javaguides.springmvc.form" }) 18 | public class MVCConfig implements WebMvcConfigurer{ 19 | 20 | @Bean 21 | public InternalResourceViewResolver resolver() { 22 | InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 23 | resolver.setViewClass(JstlView.class); 24 | resolver.setPrefix("/WEB-INF/views/"); 25 | resolver.setSuffix(".jsp"); 26 | return resolver; 27 | } 28 | } -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/src/main/java/net/javaguides/springmvc/form/config/SpringMvcDispatcherServletInitializer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | /** 6 | * @author Ramesh Fadatare 7 | */ 8 | public class SpringMvcDispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 9 | 10 | @Override 11 | protected Class[] getRootConfigClasses() { 12 | // TODO Auto-generated method stub 13 | return null; 14 | } 15 | 16 | @Override 17 | protected Class[] getServletConfigClasses() { 18 | return new Class[] { MVCConfig.class }; 19 | } 20 | 21 | @Override 22 | protected String[] getServletMappings() { 23 | return new String[] { "/" }; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/src/main/java/net/javaguides/springmvc/form/controller/CustomerController.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.controller; 2 | 3 | import javax.validation.Valid; 4 | 5 | import org.springframework.beans.propertyeditors.StringTrimmerEditor; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.Model; 8 | import org.springframework.validation.BindingResult; 9 | import org.springframework.web.bind.WebDataBinder; 10 | import org.springframework.web.bind.annotation.InitBinder; 11 | import org.springframework.web.bind.annotation.ModelAttribute; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | 14 | import net.javaguides.springmvc.form.model.Customer; 15 | 16 | @Controller 17 | @RequestMapping("/customer") 18 | public class CustomerController { 19 | 20 | // add an initbinder ... to convert trim input strings 21 | // remove leading and trailing whitespace 22 | // resolve issue for our validation 23 | 24 | @InitBinder 25 | public void initBinder(WebDataBinder dataBinder) { 26 | 27 | StringTrimmerEditor stringTrimmerEditor = new StringTrimmerEditor(true); 28 | 29 | dataBinder.registerCustomEditor(String.class, stringTrimmerEditor); 30 | } 31 | 32 | @RequestMapping("/showForm") 33 | public String showForm(Model theModel) { 34 | 35 | theModel.addAttribute("customer", new Customer()); 36 | 37 | return "customer-form"; 38 | } 39 | 40 | @RequestMapping("/processForm") 41 | public String processForm(@Valid @ModelAttribute("customer") Customer theCustomer, BindingResult theBindingResult) { 42 | if (theBindingResult.hasErrors()) { 43 | return "customer-form"; 44 | } else { 45 | return "customer-confirmation"; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/src/main/java/net/javaguides/springmvc/form/model/Customer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.model; 2 | 3 | import javax.validation.constraints.Max; 4 | import javax.validation.constraints.Min; 5 | import javax.validation.constraints.NotNull; 6 | import javax.validation.constraints.Pattern; 7 | import javax.validation.constraints.Size; 8 | 9 | import net.javaguides.springmvc.form.validation.CourseCode; 10 | 11 | public class Customer { 12 | 13 | private String firstName; 14 | 15 | @NotNull(message = "is required") 16 | @Size(min = 1, message = "is required") 17 | private String lastName; 18 | 19 | @NotNull(message = "is required") 20 | @Min(value = 0, message = "must be greater than or equal to zero") 21 | @Max(value = 10, message = "must be less than or equal to 10") 22 | private Integer freePasses; 23 | 24 | @Pattern(regexp = "^[a-zA-Z0-9]{5}", message = "only 5 chars/digits") 25 | private String postalCode; 26 | 27 | @CourseCode(value="CUST", message="must start with CUST") 28 | private String courseCode; 29 | 30 | public String getCourseCode() { 31 | return courseCode; 32 | } 33 | 34 | public void setCourseCode(String courseCode) { 35 | this.courseCode = courseCode; 36 | } 37 | 38 | public String getPostalCode() { 39 | return postalCode; 40 | } 41 | 42 | public void setPostalCode(String postalCode) { 43 | this.postalCode = postalCode; 44 | } 45 | 46 | public Integer getFreePasses() { 47 | return freePasses; 48 | } 49 | 50 | public void setFreePasses(Integer freePasses) { 51 | this.freePasses = freePasses; 52 | } 53 | 54 | public String getFirstName() { 55 | return firstName; 56 | } 57 | 58 | public void setFirstName(String firstName) { 59 | this.firstName = firstName; 60 | } 61 | 62 | public String getLastName() { 63 | return lastName; 64 | } 65 | 66 | public void setLastName(String lastName) { 67 | this.lastName = lastName; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/src/main/java/net/javaguides/springmvc/form/validation/CourseCode.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.validation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | import javax.validation.Constraint; 9 | import javax.validation.Payload; 10 | 11 | @Constraint(validatedBy = CourseCodeConstraintValidator.class) 12 | @Target({ ElementType.METHOD, ElementType.FIELD }) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface CourseCode { 15 | 16 | // define default course code 17 | public String value() default "CUST"; 18 | 19 | // define default error message 20 | public String message() default "must start with CUST"; 21 | 22 | // define default groups 23 | public Class[] groups() default {}; 24 | 25 | // define default payloads 26 | public Class[] payload() default {}; 27 | } 28 | -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/src/main/java/net/javaguides/springmvc/form/validation/CourseCodeConstraintValidator.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.validation; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | 6 | public class CourseCodeConstraintValidator implements ConstraintValidator { 7 | 8 | private String coursePrefix; 9 | 10 | @Override 11 | public void initialize(CourseCode theCourseCode) { 12 | coursePrefix = theCourseCode.value(); 13 | } 14 | 15 | @Override 16 | public boolean isValid(String theCode, ConstraintValidatorContext theConstraintValidatorContext) { 17 | 18 | boolean result; 19 | 20 | if (theCode != null) { 21 | result = theCode.startsWith(coursePrefix); 22 | } else { 23 | result = true; 24 | } 25 | 26 | return result; 27 | } 28 | } -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/src/main/webapp/WEB-INF/views/customer-confirmation.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 2 | 3 | 4 | 5 | 6 | 7 | 8 | Customer Confirmation 9 | 10 | 17 | 18 | 19 | 20 |

Customer Confirmation Page

21 |
22 | The customer is confirmed: ${customer.firstName} ${customer.lastName}
23 |
Free passes: ${customer.freePasses}
24 |
Postal Code: ${customer.postalCode}
25 |
Course code: ${customer.courseCode} 26 |
27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/src/main/webapp/WEB-INF/views/customer-form.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> 2 | 3 | 4 | 5 | 6 | Customer Registration Form 7 | 8 | 19 | 20 | 21 |

Spring MVC 5 - Custom Validation Rules Example

22 | Fill out the form. Asterisk (*) means required. 23 |
24 |
25 |
26 | 27 | 28 | First name: 29 | 30 |
31 |
32 | 33 | Last name (*): 34 | 35 | 36 |
37 |
38 | 39 | Free passes (*): 40 | 41 | 42 |
43 |
44 | 45 | Postal Code: 46 | 47 | 48 |
49 |
50 | 51 | Course Code: 52 | 53 | 54 |
55 |
56 | 57 | 58 | 59 |
60 |
61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /springmvc5-custom-form-validation/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /springmvc5-form-handling/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /springmvc5-form-handling/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springmvc5-form-handling 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | org.eclipse.wst.jsdt.core.jsNature 36 | 37 | 38 | -------------------------------------------------------------------------------- /springmvc5-form-handling/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springmvc5-form-handling/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.release=disabled 14 | org.eclipse.jdt.core.compiler.source=1.8 15 | -------------------------------------------------------------------------------- /springmvc5-form-handling/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springmvc5-form-handling/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /springmvc5-form-handling/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /springmvc5-form-handling/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /springmvc5-form-handling/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /springmvc5-form-handling/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /springmvc5-form-handling/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | net.javaguides.springmvc 5 | springmvc5-form-handling 6 | war 7 | 0.0.1-SNAPSHOT 8 | springmvc5-form-handling Maven Webapp 9 | http://maven.apache.org 10 | 11 | false 12 | 13 | 14 | 15 | 16 | org.springframework 17 | spring-webmvc 18 | 5.1.0.RELEASE 19 | 20 | 21 | 22 | 23 | javax.servlet.jsp.jstl 24 | javax.servlet.jsp.jstl-api 25 | 1.2.1 26 | 27 | 28 | taglibs 29 | standard 30 | 1.1.2 31 | 32 | 33 | 34 | 35 | javax.servlet 36 | javax.servlet-api 37 | 3.1.0 38 | provided 39 | 40 | 41 | 42 | 43 | javax.servlet.jsp 44 | javax.servlet.jsp-api 45 | 2.3.1 46 | provided 47 | 48 | 49 | 50 | src/main/java 51 | 52 | 53 | maven-compiler-plugin 54 | 3.5.1 55 | 56 | 1.8 57 | 1.8 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /springmvc5-form-handling/src/main/java/net/javaguides/springmvc/form/config/MVCConfig.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 9 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 10 | import org.springframework.web.servlet.view.JstlView; 11 | 12 | /** 13 | * @author Ramesh Fadatare 14 | */ 15 | 16 | @Configuration 17 | @EnableWebMvc 18 | @ComponentScan(basePackages = { "net.javaguides.springmvc.form" }) 19 | public class MVCConfig implements WebMvcConfigurer{ 20 | 21 | @Bean 22 | public InternalResourceViewResolver resolver() { 23 | InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 24 | resolver.setViewClass(JstlView.class); 25 | resolver.setPrefix("/WEB-INF/views/"); 26 | resolver.setSuffix(".jsp"); 27 | return resolver; 28 | } 29 | 30 | @Override 31 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 32 | registry 33 | .addResourceHandler("/resources/**") 34 | .addResourceLocations("/resources/"); 35 | } 36 | } -------------------------------------------------------------------------------- /springmvc5-form-handling/src/main/java/net/javaguides/springmvc/form/config/SpringMvcDispatcherServletInitializer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | /** 6 | * @author Ramesh Fadatare 7 | */ 8 | public class SpringMvcDispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 9 | 10 | @Override 11 | protected Class[] getRootConfigClasses() { 12 | // TODO Auto-generated method stub 13 | return null; 14 | } 15 | 16 | @Override 17 | protected Class[] getServletConfigClasses() { 18 | return new Class[] { MVCConfig.class }; 19 | } 20 | 21 | @Override 22 | protected String[] getServletMappings() { 23 | return new String[] { "/" }; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /springmvc5-form-handling/src/main/java/net/javaguides/springmvc/form/controller/SignUpController.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.ModelAttribute; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | 9 | import net.javaguides.springmvc.form.model.SignUpForm; 10 | 11 | /** 12 | * SignUpController class for User sign up form processing 13 | * 14 | * @author Ramesh Fadatare 15 | */ 16 | @Controller 17 | public class SignUpController { 18 | 19 | /** 20 | * Create new signUpForm object for empty from 21 | * 22 | * @return 23 | */ 24 | @ModelAttribute("signUpForm") 25 | public SignUpForm setSignUpForm() { 26 | return new SignUpForm(); 27 | } 28 | 29 | /** 30 | * Method to show the initial HTML form 31 | * 32 | * @return 33 | */ 34 | @GetMapping("/showSignUpForm") 35 | public String showForm() { 36 | return "signup-form"; 37 | } 38 | 39 | /** 40 | * Save User sign up form 41 | * 42 | * @param signUpForm 43 | * @param model 44 | * @return 45 | */ 46 | @PostMapping("/saveSignUpForm") 47 | public String saveUser(@ModelAttribute("signUpForm") SignUpForm signUpForm, Model model) { 48 | 49 | // Implement business logic to save user details into a database 50 | // ..... 51 | 52 | System.out.println("FirstName : " + signUpForm.getFirstName()); 53 | System.out.println("LastName : " + signUpForm.getLastName()); 54 | System.out.println("Username : " + signUpForm.getUserName()); 55 | System.out.println("Password : " + signUpForm.getPassword()); 56 | System.out.println("Email : " + signUpForm.getEmail()); 57 | 58 | model.addAttribute("message", "User SignUp successfully."); 59 | model.addAttribute("user", signUpForm); 60 | 61 | return "signup-success"; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /springmvc5-form-handling/src/main/java/net/javaguides/springmvc/form/model/SignUpForm.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.model; 2 | 3 | public class SignUpForm { 4 | private String firstName; 5 | private String lastName; 6 | private String email; 7 | private String userName; 8 | private String password; 9 | public String getFirstName() { 10 | return firstName; 11 | } 12 | public void setFirstName(String firstName) { 13 | this.firstName = firstName; 14 | } 15 | public String getLastName() { 16 | return lastName; 17 | } 18 | public void setLastName(String lastName) { 19 | this.lastName = lastName; 20 | } 21 | public String getEmail() { 22 | return email; 23 | } 24 | public void setEmail(String email) { 25 | this.email = email; 26 | } 27 | public String getUserName() { 28 | return userName; 29 | } 30 | public void setUserName(String userName) { 31 | this.userName = userName; 32 | } 33 | public String getPassword() { 34 | return password; 35 | } 36 | public void setPassword(String password) { 37 | this.password = password; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /springmvc5-form-handling/src/main/webapp/WEB-INF/views/signup-success.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 | 5 | 6 | 7 | 8 | javaguides.net 9 | " 10 | rel="stylesheet"> 11 | 12 | 13 | 14 | 15 |
16 |
17 |

${message}

18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
First Name : ${user.firstName}
Last Name : ${user.lastName}
UserName : ${user.userName}
Email : ${user.email}
34 |
35 |
36 | 37 | -------------------------------------------------------------------------------- /springmvc5-form-tags/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /springmvc5-form-tags/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springmvc5-form-tags 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | org.eclipse.wst.jsdt.core.jsNature 36 | 37 | 38 | -------------------------------------------------------------------------------- /springmvc5-form-tags/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springmvc5-form-tags/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.release=disabled 14 | org.eclipse.jdt.core.compiler.source=1.8 15 | -------------------------------------------------------------------------------- /springmvc5-form-tags/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springmvc5-form-tags/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /springmvc5-form-tags/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /springmvc5-form-tags/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /springmvc5-form-tags/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /springmvc5-form-tags/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /springmvc5-form-tags/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | net.javaguides.springmvc 6 | springmvc5-form-tags 7 | war 8 | 0.0.1-SNAPSHOT 9 | springmvc5-form-tags Maven Webapp 10 | http://maven.apache.org 11 | 12 | false 13 | 14 | 15 | 16 | 17 | org.springframework 18 | spring-webmvc 19 | 5.1.0.RELEASE 20 | 21 | 22 | 23 | 24 | javax.servlet.jsp.jstl 25 | javax.servlet.jsp.jstl-api 26 | 1.2.1 27 | 28 | 29 | taglibs 30 | standard 31 | 1.1.2 32 | 33 | 34 | 35 | 36 | javax.servlet 37 | javax.servlet-api 38 | 3.1.0 39 | provided 40 | 41 | 42 | 43 | 44 | javax.servlet.jsp 45 | javax.servlet.jsp-api 46 | 2.3.1 47 | provided 48 | 49 | 50 | 51 | src/main/java 52 | 53 | 54 | maven-compiler-plugin 55 | 3.5.1 56 | 57 | 1.8 58 | 1.8 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /springmvc5-form-tags/src/main/java/net/javaguides/springmvc/form/config/MVCConfig.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 8 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 9 | import org.springframework.web.servlet.view.JstlView; 10 | 11 | /** 12 | * @author Ramesh Fadatare 13 | */ 14 | 15 | @Configuration 16 | @EnableWebMvc 17 | @ComponentScan(basePackages = { "net.javaguides.springmvc.form" }) 18 | public class MVCConfig implements WebMvcConfigurer{ 19 | 20 | @Bean 21 | public InternalResourceViewResolver resolver() { 22 | InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 23 | resolver.setViewClass(JstlView.class); 24 | resolver.setPrefix("/WEB-INF/views/"); 25 | resolver.setSuffix(".jsp"); 26 | return resolver; 27 | } 28 | } -------------------------------------------------------------------------------- /springmvc5-form-tags/src/main/java/net/javaguides/springmvc/form/config/SpringMvcDispatcherServletInitializer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | /** 6 | * @author Ramesh Fadatare 7 | */ 8 | public class SpringMvcDispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 9 | 10 | @Override 11 | protected Class[] getRootConfigClasses() { 12 | // TODO Auto-generated method stub 13 | return null; 14 | } 15 | 16 | @Override 17 | protected Class[] getServletConfigClasses() { 18 | return new Class[] { MVCConfig.class }; 19 | } 20 | 21 | @Override 22 | protected String[] getServletMappings() { 23 | return new String[] { "/" }; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /springmvc5-form-tags/src/main/java/net/javaguides/springmvc/form/model/User.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.model; 2 | 3 | public class User { 4 | private String username; 5 | private String password; 6 | private String address; 7 | private boolean receivePaper; 8 | private String[] favoriteFrameworks; 9 | private String gender; 10 | private String favoriteNumber; 11 | private String country; 12 | 13 | public String getUsername() { 14 | return username; 15 | } 16 | 17 | public void setUsername(String username) { 18 | this.username = username; 19 | } 20 | 21 | public String getPassword() { 22 | return password; 23 | } 24 | 25 | public void setPassword(String password) { 26 | this.password = password; 27 | } 28 | 29 | public String getAddress() { 30 | return address; 31 | } 32 | 33 | public void setAddress(String address) { 34 | this.address = address; 35 | } 36 | 37 | public boolean isReceivePaper() { 38 | return receivePaper; 39 | } 40 | 41 | public void setReceivePaper(boolean receivePaper) { 42 | this.receivePaper = receivePaper; 43 | } 44 | 45 | public String[] getFavoriteFrameworks() { 46 | return favoriteFrameworks; 47 | } 48 | 49 | public void setFavoriteFrameworks(String[] favoriteFrameworks) { 50 | this.favoriteFrameworks = favoriteFrameworks; 51 | } 52 | 53 | public String getGender() { 54 | return gender; 55 | } 56 | 57 | public void setGender(String gender) { 58 | this.gender = gender; 59 | } 60 | 61 | public String getFavoriteNumber() { 62 | return favoriteNumber; 63 | } 64 | 65 | public void setFavoriteNumber(String favoriteNumber) { 66 | this.favoriteNumber = favoriteNumber; 67 | } 68 | 69 | public String getCountry() { 70 | return country; 71 | } 72 | 73 | public void setCountry(String country) { 74 | this.country = country; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /springmvc5-form-tags/src/main/webapp/WEB-INF/views/users.jsp: -------------------------------------------------------------------------------- 1 | <%@taglib uri = "http://www.springframework.org/tags/form" prefix = "form"%> 2 | 3 | 4 | Spring MVC Form Handling 5 | <%@ page isELIgnored="false" %> 6 | 7 | 8 |

Submitted User Information

9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
Username${username}
Password${password}
Address${address}
Subscribed to Newsletter${receivePaper}
Favorite Web Frameworks <% String[] favoriteFrameworks = (String[])request.getAttribute("favoriteFrameworks"); 29 | for(String framework: favoriteFrameworks) { 30 | out.println(framework); 31 | } 32 | %>
Gender${(gender=="M"? "Male" : "Female")}
Favourite Number${favoriteNumber}
Country${country}
47 | 48 | -------------------------------------------------------------------------------- /springmvc5-form-tags/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /springmvc5-form-validation/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /springmvc5-form-validation/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springmvc5-form-validation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | org.eclipse.wst.jsdt.core.jsNature 36 | 37 | 38 | -------------------------------------------------------------------------------- /springmvc5-form-validation/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springmvc5-form-validation/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.release=disabled 14 | org.eclipse.jdt.core.compiler.source=1.8 15 | -------------------------------------------------------------------------------- /springmvc5-form-validation/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springmvc5-form-validation/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /springmvc5-form-validation/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /springmvc5-form-validation/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /springmvc5-form-validation/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /springmvc5-form-validation/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /springmvc5-form-validation/src/main/java/net/javaguides/springmvc/form/config/MVCConfig.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 8 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 9 | import org.springframework.web.servlet.view.JstlView; 10 | 11 | /** 12 | * @author Ramesh Fadatare 13 | */ 14 | 15 | @Configuration 16 | @EnableWebMvc 17 | @ComponentScan(basePackages = { "net.javaguides.springmvc.form" }) 18 | public class MVCConfig implements WebMvcConfigurer{ 19 | 20 | @Bean 21 | public InternalResourceViewResolver resolver() { 22 | InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 23 | resolver.setViewClass(JstlView.class); 24 | resolver.setPrefix("/WEB-INF/views/"); 25 | resolver.setSuffix(".jsp"); 26 | return resolver; 27 | } 28 | } -------------------------------------------------------------------------------- /springmvc5-form-validation/src/main/java/net/javaguides/springmvc/form/config/SpringMvcDispatcherServletInitializer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | /** 6 | * @author Ramesh Fadatare 7 | */ 8 | public class SpringMvcDispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 9 | 10 | @Override 11 | protected Class[] getRootConfigClasses() { 12 | // TODO Auto-generated method stub 13 | return null; 14 | } 15 | 16 | @Override 17 | protected Class[] getServletConfigClasses() { 18 | return new Class[] { MVCConfig.class }; 19 | } 20 | 21 | @Override 22 | protected String[] getServletMappings() { 23 | return new String[] { "/" }; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /springmvc5-form-validation/src/main/java/net/javaguides/springmvc/form/controller/CustomerController.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.controller; 2 | 3 | import javax.validation.Valid; 4 | 5 | import org.springframework.beans.propertyeditors.StringTrimmerEditor; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.Model; 8 | import org.springframework.validation.BindingResult; 9 | import org.springframework.web.bind.WebDataBinder; 10 | import org.springframework.web.bind.annotation.InitBinder; 11 | import org.springframework.web.bind.annotation.ModelAttribute; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | 14 | import net.javaguides.springmvc.form.model.Customer; 15 | 16 | @Controller 17 | @RequestMapping("/customer") 18 | public class CustomerController { 19 | 20 | // add an initbinder ... to convert trim input strings 21 | // remove leading and trailing whitespace 22 | // resolve issue for our validation 23 | 24 | @InitBinder 25 | public void initBinder(WebDataBinder dataBinder) { 26 | 27 | StringTrimmerEditor stringTrimmerEditor = new StringTrimmerEditor(true); 28 | 29 | dataBinder.registerCustomEditor(String.class, stringTrimmerEditor); 30 | } 31 | 32 | 33 | @RequestMapping("/showForm") 34 | public String showForm(Model theModel) { 35 | 36 | theModel.addAttribute("customer", new Customer()); 37 | 38 | return "customer-form"; 39 | } 40 | 41 | @RequestMapping("/processForm") 42 | public String processForm( 43 | @Valid @ModelAttribute("customer") Customer theCustomer, 44 | BindingResult theBindingResult) { 45 | 46 | if (theBindingResult.hasErrors()) { 47 | return "customer-form"; 48 | } 49 | else { 50 | return "customer-confirmation"; 51 | } 52 | } 53 | } 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /springmvc5-form-validation/src/main/java/net/javaguides/springmvc/form/model/Customer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.form.model; 2 | 3 | import javax.validation.constraints.Max; 4 | import javax.validation.constraints.Min; 5 | import javax.validation.constraints.NotNull; 6 | import javax.validation.constraints.Pattern; 7 | import javax.validation.constraints.Size; 8 | 9 | import org.hibernate.validator.constraints.Email; 10 | 11 | public class Customer { 12 | 13 | private String firstName; 14 | 15 | @NotNull(message = "is required") 16 | @Size(min = 1, message = "is required") 17 | private String lastName; 18 | 19 | @NotNull(message = "is required") 20 | @Min(value = 0, message = "must be greater than or equal to zero") 21 | @Max(value = 10, message = "must be less than or equal to 10") 22 | private Integer freePasses; 23 | 24 | @Pattern(regexp = "^[a-zA-Z0-9]{5}", message = "only 5 chars/digits") 25 | private String postalCode; 26 | 27 | @NotNull(message = "is required") 28 | @Email(message = "Invalid email! Please enter valid email") 29 | private String email; 30 | 31 | public String getPostalCode() { 32 | return postalCode; 33 | } 34 | 35 | public void setPostalCode(String postalCode) { 36 | this.postalCode = postalCode; 37 | } 38 | 39 | public Integer getFreePasses() { 40 | return freePasses; 41 | } 42 | 43 | public void setFreePasses(Integer freePasses) { 44 | this.freePasses = freePasses; 45 | } 46 | 47 | public String getFirstName() { 48 | return firstName; 49 | } 50 | 51 | public void setFirstName(String firstName) { 52 | this.firstName = firstName; 53 | } 54 | 55 | public String getLastName() { 56 | return lastName; 57 | } 58 | 59 | public void setLastName(String lastName) { 60 | this.lastName = lastName; 61 | } 62 | 63 | public String getEmail() { 64 | return email; 65 | } 66 | 67 | public void setEmail(String email) { 68 | this.email = email; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /springmvc5-form-validation/src/main/webapp/WEB-INF/views/customer-confirmation.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | 3 | 4 | 5 | 6 | 7 | 8 | Customer Confirmation 9 | 10 | 11 | 12 | 13 | The customer is confirmed: ${customer.firstName} ${customer.lastName} 14 | 15 |

16 | 17 | Free passes: ${customer.freePasses} 18 | 19 |

20 | 21 | Email: ${customer.email} 22 | 23 |

24 | 25 | Postal Code: ${customer.postalCode} 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /springmvc5-form-validation/src/main/webapp/WEB-INF/views/customer-form.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 2 | 3 | 4 | 5 | 6 | Customer Registration Form 7 | 8 | 11 | 12 | 13 |

Spring MVC 5 - Form Validation Example

14 | Fill out the form. Asterisk (*) means required. 15 |

16 | 17 | 18 | 19 | First name: 20 | 21 |

22 | 23 | Last name (*): 24 | 25 | 26 |

27 | 28 | Free passes (*): 29 | 30 | 31 |

32 | 33 | 34 | Email (*): 35 | 36 | 37 |

38 | 39 | Postal Code: 40 | 41 | 42 |

43 | 44 | 45 | 46 |
47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /springmvc5-form-validation/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springmvc5-helloworld-exmaple 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | org.eclipse.wst.jsdt.core.jsNature 36 | 37 | 38 | -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.release=disabled 9 | org.eclipse.jdt.core.compiler.source=1.5 10 | -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/src/main/java/net/javaguides/springmvc/helloworld/config/AppConfig.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.helloworld.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 8 | import org.springframework.web.servlet.view.JstlView; 9 | 10 | /** 11 | * @author Ramesh Fadatare 12 | */ 13 | 14 | @Configuration 15 | @EnableWebMvc 16 | @ComponentScan(basePackages = { "net.javaguides.springmvc.helloworld" }) 17 | public class AppConfig { 18 | 19 | @Bean 20 | public InternalResourceViewResolver resolver() { 21 | InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 22 | resolver.setViewClass(JstlView.class); 23 | resolver.setPrefix("/WEB-INF/views/"); 24 | resolver.setSuffix(".jsp"); 25 | return resolver; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/src/main/java/net/javaguides/springmvc/helloworld/config/SpringMvcDispatcherServletInitializer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.helloworld.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | /** 6 | * @author Ramesh Fadatare 7 | */ 8 | public class SpringMvcDispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 9 | 10 | @Override 11 | protected Class[] getRootConfigClasses() { 12 | // TODO Auto-generated method stub 13 | return null; 14 | } 15 | 16 | @Override 17 | protected Class[] getServletConfigClasses() { 18 | return new Class[] { AppConfig.class }; 19 | } 20 | 21 | @Override 22 | protected String[] getServletMappings() { 23 | return new String[] { "/" }; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/src/main/java/net/javaguides/springmvc/helloworld/controller/HelloWorldController.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.helloworld.controller; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | import net.javaguides.springmvc.helloworld.model.HelloWorld; 10 | 11 | /** 12 | * @author Ramesh Fadatare 13 | */ 14 | @Controller 15 | public class HelloWorldController { 16 | 17 | @RequestMapping("/helloworld") 18 | public String handler(Model model) { 19 | 20 | HelloWorld helloWorld = new HelloWorld(); 21 | helloWorld.setMessage("Hello World Example Using Spring MVC 5!!!"); 22 | helloWorld.setDateTime(LocalDateTime.now().toString()); 23 | model.addAttribute("helloWorld", helloWorld); 24 | return "helloworld"; 25 | } 26 | } -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/src/main/java/net/javaguides/springmvc/helloworld/model/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.helloworld.model; 2 | 3 | public class HelloWorld { 4 | private String message; 5 | private String dateTime; 6 | public String getMessage() { 7 | return message; 8 | } 9 | public void setMessage(String message) { 10 | this.message = message; 11 | } 12 | public String getDateTime() { 13 | return dateTime; 14 | } 15 | public void setDateTime(String dateTime) { 16 | this.dateTime = dateTime; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/src/main/webapp/WEB-INF/views/helloworld.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 | 5 | 6 | 7 | 8 | Spring 5 MVC - Hello World Example | javaguides.net 9 | 10 | 11 |

${helloWorld.message}

12 |

Server date time is : ${helloWorld.dateTime}

13 | 14 | -------------------------------------------------------------------------------- /springmvc5-helloworld-exmaple/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springmvc5-hibernate5-jsp-mysql-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | org.eclipse.wst.jsdt.core.jsNature 36 | 37 | 38 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.release=disabled 14 | org.eclipse.jdt.core.compiler.source=1.8 15 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.release=disabled 14 | org.eclipse.jdt.core.compiler.source=1.8 15 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/config/AppContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/config/AppContext.class -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/config/AppInitializer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/config/AppInitializer.class -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/config/WebMvcConfig.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/config/WebMvcConfig.class -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/controller/CustomerController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/controller/CustomerController.class -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/dao/CustomerDAO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/dao/CustomerDAO.class -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/dao/CustomerDAOImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/dao/CustomerDAOImpl.class -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/entity/Customer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/entity/Customer.class -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/service/CustomerService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/service/CustomerService.class -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/service/CustomerServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-hibernate5-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/service/CustomerServiceImpl.class -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/src/main/resources/database.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName = com.mysql.jdbc.Driver 2 | jdbc.url = jdbc:mysql://localhost:3306/demo?useSSL=false 3 | jdbc.username = root 4 | jdbc.password = root 5 | hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect 6 | hibernate.show_sql = true 7 | hibernate.format_sql = true 8 | hibernate.hbm2ddl.auto = update -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/target/classes/database.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName = com.mysql.jdbc.Driver 2 | jdbc.url = jdbc:mysql://localhost:3306/demo?useSSL=false 3 | jdbc.username = root 4 | jdbc.password = root 5 | hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect 6 | hibernate.show_sql = true 7 | hibernate.format_sql = true 8 | hibernate.hbm2ddl.auto = update -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: GS-1787 3 | Build-Jdk: 1.8.0_172 4 | Created-By: Maven Integration for Eclipse 5 | 6 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/bin/target/m2e-wtp/web-resources/META-INF/maven/net.javaguides.springmvc/springmvc5-hibernate5-jsp-mysql-example/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Sat Nov 17 12:26:40 IST 2018 3 | version=0.0.1-SNAPSHOT 4 | groupId=net.javaguides.springmvc 5 | m2e.projectName=springmvc5-hibernate5-jsp-mysql-example 6 | m2e.projectLocation=C\:\\Ramesh_Study\\spring framework\\spring-articles\\springmvc5-hibernate5-jsp-mysql-example 7 | artifactId=springmvc5-hibernate5-jsp-mysql-example 8 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/springmvc-hibernate5-class-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-hibernate5-jsp-mysql-example/springmvc-hibernate5-class-diagram.png -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/src/main/java/net/javaguides/springmvc/config/AppInitializer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | /** 6 | * @author Ramesh Fadatare 7 | */ 8 | public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 9 | 10 | @Override 11 | protected Class[] getRootConfigClasses() { 12 | return new Class[] { AppContext.class }; 13 | //return null; 14 | } 15 | 16 | @Override 17 | protected Class[] getServletConfigClasses() { 18 | return new Class[] { WebMvcConfig.class }; 19 | } 20 | 21 | @Override 22 | protected String[] getServletMappings() { 23 | return new String[] { "/" }; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/src/main/java/net/javaguides/springmvc/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 8 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 9 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 10 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 11 | import org.springframework.web.servlet.view.JstlView; 12 | 13 | /** 14 | * @author Ramesh Fadatare 15 | */ 16 | 17 | @Configuration 18 | @EnableWebMvc 19 | @ComponentScan(basePackages = { "net.javaguides.springmvc" }) 20 | public class WebMvcConfig implements WebMvcConfigurer{ 21 | 22 | @Bean 23 | public InternalResourceViewResolver resolver() { 24 | InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 25 | resolver.setViewClass(JstlView.class); 26 | resolver.setPrefix("/WEB-INF/views/"); 27 | resolver.setSuffix(".jsp"); 28 | return resolver; 29 | } 30 | 31 | @Override 32 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 33 | registry 34 | .addResourceHandler("/resources/**") 35 | .addResourceLocations("/resources/"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/src/main/java/net/javaguides/springmvc/dao/CustomerDAO.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.dao; 2 | 3 | import java.util.List; 4 | 5 | import net.javaguides.springmvc.entity.Customer; 6 | 7 | public interface CustomerDAO { 8 | 9 | public List getCustomers(); 10 | 11 | public void saveCustomer(Customer theCustomer); 12 | 13 | public Customer getCustomer(int theId); 14 | 15 | public void deleteCustomer(int theId); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/src/main/java/net/javaguides/springmvc/dao/CustomerDAOImpl.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.dao; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.Query; 6 | import javax.persistence.criteria.CriteriaBuilder; 7 | import javax.persistence.criteria.CriteriaQuery; 8 | import javax.persistence.criteria.Root; 9 | 10 | import org.hibernate.Session; 11 | import org.hibernate.SessionFactory; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Repository; 14 | 15 | import net.javaguides.springmvc.entity.Customer; 16 | 17 | @Repository 18 | public class CustomerDAOImpl implements CustomerDAO { 19 | 20 | @Autowired 21 | private SessionFactory sessionFactory; 22 | 23 | @Override 24 | public List getCustomers() { 25 | Session session = sessionFactory.getCurrentSession(); 26 | CriteriaBuilder cb = session.getCriteriaBuilder(); 27 | CriteriaQuery cq = cb.createQuery(Customer.class); 28 | Root root = cq.from(Customer.class); 29 | cq.select(root); 30 | Query query = session.createQuery(cq); 31 | return query.getResultList(); 32 | } 33 | 34 | @Override 35 | public void deleteCustomer(int id) { 36 | Session session = sessionFactory.getCurrentSession(); 37 | Customer book = session.byId(Customer.class).load(id); 38 | session.delete(book); 39 | } 40 | 41 | @Override 42 | public void saveCustomer(Customer theCustomer) { 43 | Session currentSession = sessionFactory.getCurrentSession(); 44 | currentSession.saveOrUpdate(theCustomer); 45 | } 46 | 47 | @Override 48 | public Customer getCustomer(int theId) { 49 | Session currentSession = sessionFactory.getCurrentSession(); 50 | Customer theCustomer = currentSession.get(Customer.class, theId); 51 | return theCustomer; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/src/main/java/net/javaguides/springmvc/entity/Customer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.entity; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.GenerationType; 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | 10 | @Entity 11 | @Table(name="customer") 12 | public class Customer { 13 | 14 | @Id 15 | @GeneratedValue(strategy=GenerationType.IDENTITY) 16 | @Column(name="id") 17 | private int id; 18 | 19 | @Column(name="first_name") 20 | private String firstName; 21 | 22 | @Column(name="last_name") 23 | private String lastName; 24 | 25 | @Column(name="email") 26 | private String email; 27 | 28 | public Customer() { 29 | 30 | } 31 | 32 | public int getId() { 33 | return id; 34 | } 35 | 36 | public void setId(int id) { 37 | this.id = id; 38 | } 39 | 40 | public String getFirstName() { 41 | return firstName; 42 | } 43 | 44 | public void setFirstName(String firstName) { 45 | this.firstName = firstName; 46 | } 47 | 48 | public String getLastName() { 49 | return lastName; 50 | } 51 | 52 | public void setLastName(String lastName) { 53 | this.lastName = lastName; 54 | } 55 | 56 | public String getEmail() { 57 | return email; 58 | } 59 | 60 | public void setEmail(String email) { 61 | this.email = email; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "Customer [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", email=" + email + "]"; 67 | } 68 | } 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/src/main/java/net/javaguides/springmvc/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.service; 2 | 3 | import java.util.List; 4 | 5 | import net.javaguides.springmvc.entity.Customer; 6 | 7 | public interface CustomerService { 8 | 9 | public List getCustomers(); 10 | 11 | public void saveCustomer(Customer theCustomer); 12 | 13 | public Customer getCustomer(int theId); 14 | 15 | public void deleteCustomer(int theId); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/src/main/java/net/javaguides/springmvc/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | import net.javaguides.springmvc.dao.CustomerDAO; 10 | import net.javaguides.springmvc.entity.Customer; 11 | 12 | @Service 13 | public class CustomerServiceImpl implements CustomerService { 14 | 15 | @Autowired 16 | private CustomerDAO customerDAO; 17 | 18 | @Override 19 | @Transactional 20 | public List getCustomers() { 21 | return customerDAO.getCustomers(); 22 | } 23 | 24 | @Override 25 | @Transactional 26 | public void saveCustomer(Customer theCustomer) { 27 | customerDAO.saveCustomer(theCustomer); 28 | } 29 | 30 | @Override 31 | @Transactional 32 | public Customer getCustomer(int theId) { 33 | return customerDAO.getCustomer(theId); 34 | } 35 | 36 | @Override 37 | @Transactional 38 | public void deleteCustomer(int theId) { 39 | customerDAO.deleteCustomer(theId); 40 | } 41 | } 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/src/main/resources/database.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName = com.mysql.jdbc.Driver 2 | jdbc.url = jdbc:mysql://localhost:3306/demo?useSSL=false 3 | jdbc.username = root 4 | jdbc.password = root 5 | hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect 6 | hibernate.show_sql = true 7 | hibernate.format_sql = true 8 | hibernate.hbm2ddl.auto = update -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/src/main/webapp/WEB-INF/views/hello.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |

hello

11 | 12 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/src/main/webapp/WEB-INF/views/signup-success.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 | 5 | 6 | 7 | 8 | javaguides.net 9 | " 10 | rel="stylesheet"> 11 | 12 | 13 | 14 | 15 |
16 |
17 |

${message}

18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
First Name : ${user.firstName}
Last Name : ${user.lastName}
UserName : ${user.userName}
Email : ${user.email}
34 |
35 |
36 | 37 | -------------------------------------------------------------------------------- /springmvc5-hibernate5-jsp-mysql-example/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springmvc5-requestparam-annotation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | org.eclipse.wst.jsdt.core.jsNature 36 | 37 | 38 | -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.release=disabled 9 | org.eclipse.jdt.core.compiler.source=1.5 10 | -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | net.javaguides.springmvc 5 | springmvc5-requestparam-annotation 6 | war 7 | 0.0.1-SNAPSHOT 8 | springmvc5-requestparam-annotation Maven Webapp 9 | http://maven.apache.org 10 | 11 | 12 | 13 | 14 | org.springframework 15 | spring-webmvc 16 | 5.1.0.RELEASE 17 | 18 | 19 | 20 | 21 | javax.servlet.jsp.jstl 22 | javax.servlet.jsp.jstl-api 23 | 1.2.1 24 | 25 | 26 | taglibs 27 | standard 28 | 1.1.2 29 | 30 | 31 | 32 | 33 | javax.servlet 34 | javax.servlet-api 35 | 3.1.0 36 | provided 37 | 38 | 39 | 40 | 41 | javax.servlet.jsp 42 | javax.servlet.jsp-api 43 | 2.3.1 44 | provided 45 | 46 | 47 | 48 | src/main/java 49 | 50 | 51 | maven-compiler-plugin 52 | 3.5.1 53 | 54 | 1.8 55 | 1.8 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/src/main/java/net/javaguides/springmvc/requestparam/config/AppConfig.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.requestparam.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 8 | import org.springframework.web.servlet.view.JstlView; 9 | 10 | @Configuration 11 | @EnableWebMvc 12 | @ComponentScan(basePackages = { "net.javaguides.springmvc.requestparam" }) 13 | public class AppConfig { 14 | 15 | @Bean 16 | public InternalResourceViewResolver resolver() { 17 | InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 18 | resolver.setViewClass(JstlView.class); 19 | resolver.setPrefix("/WEB-INF/views/"); 20 | resolver.setSuffix(".jsp"); 21 | return resolver; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/src/main/java/net/javaguides/springmvc/requestparam/config/MySpringMvcDispatcherServletInitializer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.requestparam.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | public class MySpringMvcDispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 6 | 7 | @Override 8 | protected Class[] getRootConfigClasses() { 9 | // TODO Auto-generated method stub 10 | return null; 11 | } 12 | 13 | @Override 14 | protected Class[] getServletConfigClasses() { 15 | return new Class[] { AppConfig.class }; 16 | } 17 | 18 | @Override 19 | protected String[] getServletMappings() { 20 | return new String[] { "/" }; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/src/main/webapp/WEB-INF/views/helloworld.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Hello World of Spring! 7 | 8 |

9 | 10 | Student name: ${param.studentName} 11 | 12 |

13 | 14 | The message: ${message} 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | Archetype Created Web Application 7 | 8 | -------------------------------------------------------------------------------- /springmvc5-requestparam-annotation/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springmvc5-slf4j-logback-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | org.eclipse.wst.jsdt.core.jsNature 36 | 37 | 38 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.release=disabled 14 | org.eclipse.jdt.core.compiler.source=1.8 15 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | net.javaguides.springmvc 6 | springmvc5-slf4j-logback-example 7 | war 8 | 0.0.1-SNAPSHOT 9 | springmvc5-slf4j-logback-example Maven Webapp 10 | http://maven.apache.org 11 | 12 | false 13 | 5.1.0.RELEASE 14 | 3.1.0 15 | 16 | 17 | 18 | 19 | 20 | org.springframework 21 | spring-webmvc 22 | ${spring.version} 23 | 24 | 25 | commons-logging 26 | commons-logging 27 | 28 | 29 | 30 | 31 | 32 | 33 | javax.servlet 34 | javax.servlet-api 35 | ${servlets.version} 36 | provided 37 | 38 | 39 | 40 | 41 | org.slf4j 42 | jcl-over-slf4j 43 | 1.7.20 44 | 45 | 46 | ch.qos.logback 47 | logback-classic 48 | 1.1.7 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | maven-compiler-plugin 57 | 3.5.1 58 | 59 | 1.8 60 | 1.8 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/src/main/java/net/javaguides/springmvc/config/ServletInitializer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | public class ServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 6 | 7 | @Override 8 | protected Class[] getServletConfigClasses() { 9 | return new Class[] { WebConfig.class }; 10 | } 11 | 12 | @Override 13 | protected String[] getServletMappings() { 14 | return new String[] { "/" }; 15 | } 16 | 17 | @Override 18 | protected Class[] getRootConfigClasses() { 19 | return null; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/src/main/java/net/javaguides/springmvc/config/WebConfig.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 8 | import org.springframework.web.servlet.view.JstlView; 9 | 10 | @EnableWebMvc 11 | @Configuration 12 | @ComponentScan({"com.javaguides.springmvc.controller"}) 13 | public class WebConfig { 14 | 15 | @Bean 16 | public InternalResourceViewResolver viewResolver(){ 17 | InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); 18 | viewResolver.setViewClass(JstlView.class); 19 | viewResolver.setPrefix("/WEB-INF/views/"); 20 | viewResolver.setSuffix(".jsp"); 21 | return viewResolver; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/src/main/java/net/javaguides/springmvc/controller/HelloWorldController.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | @Controller 10 | @RequestMapping("/logging") 11 | public class HelloWorldController { 12 | 13 | private static final Logger LOGGER = LoggerFactory.getLogger(HelloWorldController.class); 14 | 15 | @GetMapping("/logs") 16 | public String index() { 17 | 18 | LOGGER.trace("trace logging"); 19 | LOGGER.debug("debug logging"); 20 | LOGGER.info("info logging"); 21 | LOGGER.warn("warning logging"); 22 | LOGGER.error("error logging", new RuntimeException("help")); 23 | return "logs"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | %d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/src/main/webapp/WEB-INF/views/logs.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Spring MVC 5 + Slf4j + Logback integrated successfully - Check Logs at console

4 | 5 | 6 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | Archetype Created Web Application 7 | 8 | -------------------------------------------------------------------------------- /springmvc5-slf4j-logback-example/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | springmvc5-springdatajpa2-jsp-mysql-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | org.eclipse.wst.jsdt.core.jsNature 36 | 37 | 38 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.release=disabled 14 | org.eclipse.jdt.core.compiler.source=1.8 15 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/config/AppInitializer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/config/AppInitializer.class -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/config/PersistenceJPAConfig.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/config/PersistenceJPAConfig.class -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/config/WebMvcConfig.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/config/WebMvcConfig.class -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/controller/CustomerController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/controller/CustomerController.class -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/entity/Customer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/entity/Customer.class -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/exception/ResourceNotFoundException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/exception/ResourceNotFoundException.class -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/repository/CustomerRepository.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/repository/CustomerRepository.class -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/service/CustomerService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/service/CustomerService.class -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/service/CustomerServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-springdatajpa2-jsp-mysql-example/bin/src/main/java/net/javaguides/springmvc/service/CustomerServiceImpl.class -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/springmvc-springdatajpa-class-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RameshMF/spring-mvc-tutorial/78f0d57688502f1205ab4c00b8ea4ebe2ff8f7d2/springmvc5-springdatajpa2-jsp-mysql-example/springmvc-springdatajpa-class-diagram.png -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/src/main/java/net/javaguides/springmvc/config/AppInitializer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | /** 6 | * @author Ramesh Fadatare 7 | */ 8 | public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 9 | 10 | @Override 11 | protected Class[] getRootConfigClasses() { 12 | return new Class[] { PersistenceJPAConfig.class }; 13 | //return null; 14 | } 15 | 16 | @Override 17 | protected Class[] getServletConfigClasses() { 18 | return new Class[] { WebMvcConfig.class }; 19 | } 20 | 21 | @Override 22 | protected String[] getServletMappings() { 23 | return new String[] { "/" }; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/src/main/java/net/javaguides/springmvc/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 8 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 9 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 10 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 11 | import org.springframework.web.servlet.view.JstlView; 12 | 13 | /** 14 | * @author Ramesh Fadatare 15 | */ 16 | 17 | @Configuration 18 | @EnableWebMvc 19 | @ComponentScan(basePackages = { "net.javaguides.springmvc.controller" }) 20 | public class WebMvcConfig implements WebMvcConfigurer{ 21 | 22 | @Bean 23 | public InternalResourceViewResolver resolver() { 24 | InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 25 | resolver.setViewClass(JstlView.class); 26 | resolver.setPrefix("/WEB-INF/views/"); 27 | resolver.setSuffix(".jsp"); 28 | return resolver; 29 | } 30 | 31 | @Override 32 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 33 | registry 34 | .addResourceHandler("/resources/**") 35 | .addResourceLocations("/resources/"); 36 | } 37 | } -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/src/main/java/net/javaguides/springmvc/entity/Customer.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.entity; 2 | 3 | import javax.persistence.Column; 4 | 5 | import javax.persistence.Entity; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.GenerationType; 8 | import javax.persistence.Id; 9 | import javax.persistence.Table; 10 | 11 | @Entity 12 | @Table(name="customer") 13 | public class Customer { 14 | 15 | @Id 16 | @GeneratedValue(strategy=GenerationType.IDENTITY) 17 | @Column(name="id") 18 | private int id; 19 | 20 | @Column(name="first_name") 21 | private String firstName; 22 | 23 | @Column(name="last_name") 24 | private String lastName; 25 | 26 | @Column(name="email") 27 | private String email; 28 | 29 | public Customer() { 30 | 31 | } 32 | 33 | public int getId() { 34 | return id; 35 | } 36 | 37 | public void setId(int id) { 38 | this.id = id; 39 | } 40 | 41 | public String getFirstName() { 42 | return firstName; 43 | } 44 | 45 | public void setFirstName(String firstName) { 46 | this.firstName = firstName; 47 | } 48 | 49 | public String getLastName() { 50 | return lastName; 51 | } 52 | 53 | public void setLastName(String lastName) { 54 | this.lastName = lastName; 55 | } 56 | 57 | public String getEmail() { 58 | return email; 59 | } 60 | 61 | public void setEmail(String email) { 62 | this.email = email; 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return "Customer [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", email=" + email + "]"; 68 | } 69 | } 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/src/main/java/net/javaguides/springmvc/exception/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.exception; 2 | 3 | public class ResourceNotFoundException extends Exception { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public ResourceNotFoundException(Object resourId) { 7 | super(resourId != null ? resourId.toString() : null); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/src/main/java/net/javaguides/springmvc/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import net.javaguides.springmvc.entity.Customer; 7 | 8 | @Repository("customerRepository") 9 | public interface CustomerRepository extends JpaRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/src/main/java/net/javaguides/springmvc/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.service; 2 | 3 | import java.util.List; 4 | 5 | import net.javaguides.springmvc.entity.Customer; 6 | import net.javaguides.springmvc.exception.ResourceNotFoundException; 7 | 8 | public interface CustomerService { 9 | 10 | public List getCustomers(); 11 | 12 | public void saveCustomer(Customer theCustomer); 13 | 14 | public Customer getCustomer(int theId) throws ResourceNotFoundException; 15 | 16 | public void deleteCustomer(int theId) throws ResourceNotFoundException; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/src/main/java/net/javaguides/springmvc/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.javaguides.springmvc.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | import net.javaguides.springmvc.entity.Customer; 10 | import net.javaguides.springmvc.exception.ResourceNotFoundException; 11 | import net.javaguides.springmvc.repository.CustomerRepository; 12 | 13 | @Service 14 | public class CustomerServiceImpl implements CustomerService { 15 | 16 | @Autowired 17 | private CustomerRepository customerRepository; 18 | 19 | @Override 20 | @Transactional 21 | public List getCustomers() { 22 | return customerRepository.findAll(); 23 | } 24 | 25 | @Override 26 | @Transactional 27 | public void saveCustomer(Customer theCustomer) { 28 | customerRepository.save(theCustomer); 29 | } 30 | 31 | @Override 32 | @Transactional 33 | public Customer getCustomer(int id) throws ResourceNotFoundException { 34 | return customerRepository.findById(id).orElseThrow( 35 | () -> new ResourceNotFoundException(id)); 36 | } 37 | 38 | @Override 39 | @Transactional 40 | public void deleteCustomer(int theId) { 41 | customerRepository.deleteById(theId); 42 | } 43 | } 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/src/main/resources/database.properties: -------------------------------------------------------------------------------- 1 | # jdbc.X 2 | jdbc.driverClassName=com.mysql.jdbc.Driver 3 | jdbc.url=jdbc:mysql://localhost:3306/demo?useSSL=false 4 | jdbc.user=root 5 | jdbc.pass=root 6 | 7 | # hibernate.X 8 | hibernate.dialect=org.hibernate.dialect.MySQL5Dialect 9 | hibernate.show_sql=false 10 | hibernate.hbm2ddl.auto=create-drop 11 | hibernate.cache.use_second_level_cache=false 12 | hibernate.cache.use_query_cache=false -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | %d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /springmvc5-springdatajpa2-jsp-mysql-example/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | --------------------------------------------------------------------------------