├── .gitignore ├── CustomDataBindingFormatter ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── config │ │ ├── DispatcherServletInit.java │ │ └── WebApplicationContextConfig.java │ │ ├── controller │ │ └── CustomerController.java │ │ ├── formatter │ │ └── PhoneFormatter.java │ │ └── model │ │ ├── Customer.java │ │ └── Phone.java │ └── webapp │ └── WEB-INF │ └── jsp │ ├── customerDetail.jsp │ ├── customerEditForm.jsp │ └── customerForm.jsp ├── CustomerDataBindingFormatterXML ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── controller │ │ └── CustomerController.java │ │ ├── formatter │ │ └── PhoneFormatter.java │ │ └── model │ │ ├── Customer.java │ │ └── Phone.java │ └── webapp │ └── WEB-INF │ ├── config │ └── springmvc-config.xml │ ├── jsp │ ├── customerDetail.jsp │ ├── customerEditForm.jsp │ └── customerForm.jsp │ └── web.xml ├── ModelScopedAttributeXML ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── controller │ │ ├── ApplicationScopeAttributeController.java │ │ ├── RequestScopeAttributeController.java │ │ └── SessionScopeAttributeController.java │ │ └── model │ │ └── Customer.java │ └── webapp │ └── WEB-INF │ ├── config │ └── springmvc-config.xml │ ├── jsp │ ├── appScopeAttribute.jsp │ ├── requestScopeAttribute.jsp │ └── sessionScopeAttribute.jsp │ └── web.xml ├── PRGDemo ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── Order.java │ │ ├── config │ │ ├── DispatcherServletInit.java │ │ └── WebApplicationContextConfig.java │ │ └── controller │ │ └── OrderController.java │ └── webapp │ └── WEB-INF │ └── jsp │ ├── orderForm.jsp │ └── thankyou.jsp ├── README.md ├── SpringFormTagLibrary ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── config │ │ ├── DispatcherServletInit.java │ │ └── WebApplicationContextConfig.java │ │ ├── controller │ │ └── CustomerController.java │ │ ├── formatter │ │ └── PhoneFormatter.java │ │ └── model │ │ ├── Country.java │ │ ├── Customer.java │ │ └── Phone.java │ └── webapp │ └── WEB-INF │ └── jsp │ ├── customerDetail.jsp │ ├── customerEditForm.jsp │ └── customerForm.jsp ├── SpringMVCContentNegotiatingViewResolver ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── config │ │ ├── DispatcherServletInit.java │ │ └── WebApplicationConfig.java │ │ ├── controller │ │ └── ProductController.java │ │ └── domain │ │ └── Product.java │ └── webapp │ └── WEB-INF │ └── jsp │ └── index.jsp ├── SpringMVCContentNegotiatingViewResolverXML ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── controller │ │ └── ProductController.java │ │ └── domain │ │ └── Product.java │ └── webapp │ └── WEB-INF │ ├── config │ └── springmvc-config.xml │ ├── jsp │ └── index.jsp │ └── web.xml ├── SpringMVCStaticResourcesHandlingXML ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── IndexController.java │ │ └── config │ │ └── WebApplicationContextConfig.java │ └── webapp │ ├── WEB-INF │ ├── config │ │ └── springmvc-config.xml │ ├── jsp │ │ └── index.jsp │ └── web.xml │ └── resources │ └── images │ ├── dog.jpg │ └── user │ └── cat.jpg ├── SpringMVCViewResolverXML ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ └── controller │ │ └── ViewResolverDemoController.java │ └── webapp │ └── WEB-INF │ ├── config │ └── springmvc-config.xml │ ├── jsp │ └── index.jsp │ ├── thymeleaf │ └── index.html │ └── web.xml ├── SpringMVCi18nJavaConfig ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── config │ │ ├── DispatcherServletInit.java │ │ └── WebApplicationContextConfig.java │ │ └── controller │ │ └── UserController.java │ ├── resources │ ├── messages.properties │ └── messages_zh_CN.properties │ └── webapp │ └── WEB-INF │ └── jsp │ ├── home.jsp │ └── userForm.jsp ├── SpringMVCi18nXML ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ └── controller │ │ └── UserController.java │ ├── resources │ ├── messages.properties │ └── messages_zh_CN.properties │ └── webapp │ └── WEB-INF │ ├── config │ └── springmvc-config.xml │ ├── jsp │ └── userForm.jsp │ └── web.xml ├── SpringValidationJavaConfig ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── config │ │ ├── DispatcherServletInit.java │ │ └── WebApplicationContextConfig.java │ │ ├── controller │ │ └── UserController.java │ │ └── domain │ │ ├── Address.java │ │ └── User.java │ ├── resources │ ├── errorMessages.properties │ └── messages.properties │ └── webapp │ └── WEB-INF │ └── jsp │ ├── success.jsp │ └── userForm.jsp ├── SpringValidationXML ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── controller │ │ ├── HomeController.java │ │ └── UserController.java │ │ ├── domain │ │ ├── Address.java │ │ └── User.java │ │ ├── exception │ │ ├── GlobalExceptionHandler.java │ │ └── UserNotFoundException.java │ │ ├── interceptor │ │ └── ProcessingTimeInterceptor.java │ │ └── validation │ │ ├── Age.java │ │ └── AgeValidation.java │ ├── resources │ ├── errorMessages.properties │ ├── messages.properties │ └── messages_zh_CN.properties │ └── webapp │ └── WEB-INF │ ├── config │ └── springmvc-config.xml │ ├── jsp │ ├── error.jsp │ ├── success.jsp │ └── userForm.jsp │ └── web.xml ├── employee-management ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── xing │ │ │ └── rujuan │ │ │ └── employeemanagement │ │ │ ├── EmployeeManagementApplication.java │ │ │ ├── controller │ │ │ └── EmployeeController.java │ │ │ └── domain │ │ │ ├── Address.java │ │ │ └── Employee.java │ └── resources │ │ ├── application.properties │ │ └── templates │ │ ├── empDetail.html │ │ └── empForm.html │ └── test │ └── java │ └── xing │ └── rujuan │ └── employeemanagement │ └── EmployeeManagementApplicationTests.java ├── springaop ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ └── aop │ │ ├── advices │ │ ├── AccountService.java │ │ ├── AccountServiceImpl.java │ │ ├── App.java │ │ ├── Config.java │ │ ├── CustomerService.java │ │ ├── CustomerServiceImpl.java │ │ ├── LogAspect.java │ │ └── MyException.java │ │ ├── proxy │ │ ├── App.java │ │ ├── CustomerService.java │ │ ├── CustomerServiceProxy.java │ │ ├── FancyBeanFactory.java │ │ └── LoggerAspect.java │ │ ├── sequence │ │ ├── AccountService.java │ │ ├── AccountServiceImpl.java │ │ ├── App.java │ │ ├── Config.java │ │ ├── LogAspect1.java │ │ └── LogAspect2.java │ │ ├── terms │ │ ├── App.java │ │ ├── Config.java │ │ ├── CustomerService.java │ │ ├── CustomerServiceImpl.java │ │ └── LogAspect.java │ │ └── xml │ │ ├── App.java │ │ ├── CustomerService.java │ │ ├── CustomerServiceImpl.java │ │ └── LogAspect.java │ └── resources │ └── spring.xml ├── springautowiring ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── autowired │ │ ├── AppConfig.java │ │ ├── AppMain.java │ │ ├── CustomerDao.java │ │ ├── CustomerDaoImpl.java │ │ ├── CustomerDaoImpl2.java │ │ └── CustomerService.java │ │ └── fourtypes │ │ ├── CustomerDao.java │ │ ├── CustomerService.java │ │ └── Main.java │ └── resources │ └── spring-fourtypes.xml ├── springbeanlifecycle ├── pom.xml └── src │ └── main │ ├── java │ ├── destruction │ │ ├── Customer.java │ │ └── DestructionMain.java │ ├── javaconfig │ │ ├── AppConfig.java │ │ ├── Customer.java │ │ └── JavaConfigMain.java │ └── xing │ │ └── rujuan │ │ ├── Address.java │ │ ├── CustomBeanPostProcessor.java │ │ ├── Customer.java │ │ └── Main.java │ └── resources │ ├── spring-destruction.xml │ └── spring.xml ├── springbootjspdemo ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── xing │ │ │ └── rujuan │ │ │ └── springbootjspdemo │ │ │ ├── ServletInitializer.java │ │ │ ├── SpringbootjspdemoApplication.java │ │ │ └── controller │ │ │ └── IndexController.java │ ├── resources │ │ └── application.properties │ └── webapp │ │ └── WEB-INF │ │ └── jsp │ │ └── index.jsp │ └── test │ └── java │ └── xing │ └── rujuan │ └── springbootjspdemo │ └── SpringbootjspdemoApplicationTests.java ├── springbootthymeleafdemo ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── xing │ │ │ └── rujuan │ │ │ └── springbootthymeleafdemo │ │ │ ├── SpringbootthymeleafdemoApplication.java │ │ │ └── controller │ │ │ └── IndexController.java │ └── resources │ │ ├── application.properties │ │ └── templates │ │ └── index.html │ └── test │ └── java │ └── xing │ └── rujuan │ └── springbootthymeleafdemo │ └── SpringbootthymeleafdemoApplicationTests.java ├── springcore ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── EmailService.java │ │ ├── Main.java │ │ ├── annotation │ │ ├── MyAppConfig.java │ │ ├── MyMain.java │ │ └── SMSService.java │ │ └── config │ │ └── AppConfig.java │ └── resources │ ├── spring-annotation.xml │ └── spring.xml ├── springmvcjavaconfig ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── config │ │ ├── DispatcherServletInit.java │ │ └── WebApplicationContextConfig.java │ │ ├── controller │ │ ├── ProductController.java │ │ └── WelcomeController.java │ │ └── model │ │ ├── Category.java │ │ └── Product.java │ └── webapp │ └── WEB-INF │ └── jsp │ ├── productForm.jsp │ └── welcome.jsp ├── springmvcxml ├── pom.xml └── src │ └── main │ ├── java │ └── xing │ │ └── rujuan │ │ ├── ProductController.java │ │ ├── SignUpController.java │ │ ├── WelcomeController.java │ │ └── model │ │ ├── Address.java │ │ └── User.java │ └── webapp │ └── WEB-INF │ ├── config │ └── springmvc-config.xml │ ├── jsp │ ├── SignUpForm.jsp │ ├── result.jsp │ └── welcome.jsp │ └── web.xml ├── thymeleaf-layout-hierarchical-style ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── xing │ │ │ └── rujuan │ │ │ └── thymeleaflayouthierarchicalstyle │ │ │ ├── ThymeleafLayoutHierarchicalStyleApplication.java │ │ │ └── controller │ │ │ └── IndexController.java │ └── resources │ │ ├── application.properties │ │ ├── static │ │ └── css │ │ │ ├── bootstrap.min.css │ │ │ └── cover.css │ │ └── templates │ │ ├── admin │ │ └── index.html │ │ ├── index.html │ │ ├── page_layout │ │ ├── footer.html │ │ ├── header.html │ │ └── layout.html │ │ └── user.html │ └── test │ └── java │ └── xing │ └── rujuan │ └── thymeleaflayouthierarchicalstyle │ └── ThymeleafLayoutHierarchicalStyleApplicationTests.java ├── thymeleaf-layout-include-style ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── xing │ │ │ └── rujuan │ │ │ └── thymeleaflayoutincludestyle │ │ │ ├── ThymeleafLayoutIncludeStyleApplication.java │ │ │ └── controller │ │ │ └── IndexController.java │ └── resources │ │ ├── application.properties │ │ ├── static │ │ └── css │ │ │ ├── bootstrap.min.css │ │ │ └── cover.css │ │ └── templates │ │ ├── commoncomponents.html │ │ ├── fragments │ │ ├── footer.html │ │ └── header.html │ │ ├── index.html │ │ └── user.html │ └── test │ └── java │ └── xing │ └── rujuan │ └── thymeleaflayoutincludestyle │ └── ThymeleafLayoutIncludeStyleApplicationTests.java └── thymeleafexpressionsyntax ├── .gitignore ├── pom.xml └── src ├── main ├── java │ └── xing │ │ └── rujuan │ │ └── thymeleafexpressionsyntax │ │ ├── ThymeleafexpressionsyntaxApplication.java │ │ ├── controller │ │ ├── ConditionalExpression.java │ │ ├── IndexController.java │ │ ├── IterationExpressionController.java │ │ └── SimpleExpressionController.java │ │ └── domain │ │ ├── Address.java │ │ └── Person.java └── resources │ ├── application.properties │ ├── messages.properties │ └── templates │ ├── conditionalExpression.html │ ├── index.html │ ├── iterationExpression.html │ └── simpleExpression.html └── test └── java └── xing └── rujuan └── thymeleafexpressionsyntax └── ThymeleafexpressionsyntaxApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | .idea 26 | target 27 | *.iml 28 | .mvn 29 | mvnw 30 | mvnw.cmd -------------------------------------------------------------------------------- /CustomDataBindingFormatter/src/main/java/xing/rujuan/config/DispatcherServletInit.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | public class DispatcherServletInit extends AbstractAnnotationConfigDispatcherServletInitializer { 6 | 7 | @Override 8 | protected Class[] getRootConfigClasses() { 9 | return null; 10 | } 11 | 12 | @Override 13 | protected Class[] getServletConfigClasses() { 14 | return new Class[]{WebApplicationContextConfig.class}; 15 | } 16 | 17 | @Override 18 | protected String[] getServletMappings() { 19 | return new String[]{"/"}; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CustomDataBindingFormatter/src/main/java/xing/rujuan/config/WebApplicationContextConfig.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.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.format.FormatterRegistry; 7 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 9 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 10 | import xing.rujuan.formatter.PhoneFormatter; 11 | import xing.rujuan.model.Phone; 12 | 13 | @Configuration 14 | @EnableWebMvc 15 | @ComponentScan("xing.rujuan") 16 | public class WebApplicationContextConfig implements WebMvcConfigurer { 17 | 18 | @Bean 19 | public InternalResourceViewResolver getInternalResourceViewResolver(){ 20 | InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); 21 | viewResolver.setPrefix("/WEB-INF/jsp/"); 22 | viewResolver.setSuffix(".jsp"); 23 | return viewResolver; 24 | } 25 | 26 | public void addFormatters(FormatterRegistry registry) { 27 | 28 | registry.addFormatter(new PhoneFormatter()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CustomDataBindingFormatter/src/main/java/xing/rujuan/controller/CustomerController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.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.PostMapping; 7 | import xing.rujuan.model.Customer; 8 | import xing.rujuan.model.Phone; 9 | 10 | @Controller 11 | public class CustomerController { 12 | 13 | @GetMapping("/") 14 | public String getCustomerForm(){ 15 | return "customerForm"; 16 | } 17 | 18 | @PostMapping("/saveCustomer") 19 | public String saveCustomer(Customer customer){ 20 | //save to DB 21 | return "customerDetail"; 22 | } 23 | 24 | @GetMapping("/edit") 25 | public String editCustomer(Model model){ 26 | Phone p = new Phone("123", "456", "7890"); 27 | Customer customer = new Customer("Tina", "Xing", p); 28 | model.addAttribute("customer", customer); 29 | return "customerEditForm"; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /CustomDataBindingFormatter/src/main/java/xing/rujuan/formatter/PhoneFormatter.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.formatter; 2 | 3 | import org.springframework.format.Formatter; 4 | import xing.rujuan.model.Phone; 5 | 6 | import java.text.ParseException; 7 | import java.util.Locale; 8 | 9 | public class PhoneFormatter implements Formatter { 10 | 11 | @Override 12 | public Phone parse(String s, Locale locale) throws ParseException { 13 | //s=641-451-1111 14 | String[] temp = s.split("-"); 15 | Phone p = new Phone(); 16 | p.setAreaCode(temp[0]); 17 | p.setPrefix(temp[1]); 18 | p.setNumber(temp[2]); 19 | System.out.println("Inside PhoneFormatter parse method: "); 20 | System.out.println(p); 21 | return p; 22 | } 23 | 24 | @Override 25 | public String print(Phone phone, Locale locale) { 26 | return null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CustomDataBindingFormatter/src/main/java/xing/rujuan/model/Customer.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.model; 2 | 3 | public class Customer { 4 | 5 | private String first; 6 | private String last; 7 | private Phone phone; 8 | 9 | public Customer() { 10 | } 11 | 12 | public Customer(String first, String last, Phone phone) { 13 | this.first = first; 14 | this.last = last; 15 | this.phone = phone; 16 | } 17 | 18 | public String getFirst() { 19 | return first; 20 | } 21 | 22 | public void setFirst(String first) { 23 | this.first = first; 24 | } 25 | 26 | public String getLast() { 27 | return last; 28 | } 29 | 30 | public void setLast(String last) { 31 | this.last = last; 32 | } 33 | 34 | public Phone getPhone() { 35 | return phone; 36 | } 37 | 38 | public void setPhone(Phone phone) { 39 | this.phone = phone; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /CustomDataBindingFormatter/src/main/java/xing/rujuan/model/Phone.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.model; 2 | 3 | public class Phone { 4 | 5 | private String areaCode; 6 | private String prefix; 7 | private String number; 8 | 9 | public Phone() { 10 | } 11 | 12 | public Phone(String areaCode, String prefix, String number) { 13 | this.areaCode = areaCode; 14 | this.prefix = prefix; 15 | this.number = number; 16 | } 17 | 18 | public String getAreaCode() { 19 | return areaCode; 20 | } 21 | 22 | public void setAreaCode(String areaCode) { 23 | this.areaCode = areaCode; 24 | } 25 | 26 | public String getPrefix() { 27 | return prefix; 28 | } 29 | 30 | public void setPrefix(String prefix) { 31 | this.prefix = prefix; 32 | } 33 | 34 | public String getNumber() { 35 | return number; 36 | } 37 | 38 | public void setNumber(String number) { 39 | this.number = number; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "Phone{" + 45 | "areaCode='" + areaCode + '\'' + 46 | ", prefix='" + prefix + '\'' + 47 | ", number='" + number + '\'' + 48 | '}'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /CustomDataBindingFormatter/src/main/webapp/WEB-INF/jsp/customerDetail.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/2/2019 5 | Time: 7:58 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Customer Detail 12 | 13 | 14 |

Name: ${customer.first} ${customer.last}

15 |

Phone Number: ${customer.phone.areaCode} - ${customer.phone.prefix}- ${customer.phone.number}

16 | 17 | 18 | -------------------------------------------------------------------------------- /CustomDataBindingFormatter/src/main/webapp/WEB-INF/jsp/customerEditForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/2/2019 5 | Time: 8:22 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Edit a Customer 12 | 13 | 14 |
15 | 16 |

First Name:

17 |

Last Name:

18 |

Phone Number:

19 | 20 | 21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /CustomDataBindingFormatter/src/main/webapp/WEB-INF/jsp/customerForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/2/2019 5 | Time: 7:55 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Add a new Customer 12 | 13 | 14 | 15 |

Add a new Customer

16 |
17 | 18 |

First Name:

19 |

Last Name:

20 |

Phone Number:

21 | 22 | 23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /CustomerDataBindingFormatterXML/src/main/java/xing/rujuan/controller/CustomerController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.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.PostMapping; 7 | import xing.rujuan.model.Customer; 8 | import xing.rujuan.model.Phone; 9 | 10 | @Controller 11 | public class CustomerController { 12 | 13 | @GetMapping("/") 14 | public String getCustomerForm(){ 15 | return "customerForm"; 16 | } 17 | 18 | @PostMapping("/saveCustomer") 19 | public String saveCustomer(Customer customer){ 20 | //save to DB 21 | return "customerDetail"; 22 | } 23 | 24 | @GetMapping("/edit") 25 | public String editCustomer(Model model){ 26 | Phone p = new Phone("123", "456", "7890"); 27 | Customer customer = new Customer("Tina", "Xing", p); 28 | model.addAttribute("customer", customer); 29 | return "customerEditForm"; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /CustomerDataBindingFormatterXML/src/main/java/xing/rujuan/formatter/PhoneFormatter.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.formatter; 2 | 3 | import org.springframework.format.Formatter; 4 | import xing.rujuan.model.Phone; 5 | 6 | import java.text.ParseException; 7 | import java.util.Locale; 8 | 9 | public class PhoneFormatter implements Formatter { 10 | 11 | @Override 12 | public Phone parse(String s, Locale locale) throws ParseException { 13 | //s=641-451-1111 14 | String[] temp = s.split("-"); 15 | Phone p = new Phone(); 16 | p.setAreaCode(temp[0]); 17 | p.setPrefix(temp[1]); 18 | p.setNumber(temp[2]); 19 | System.out.println("Inside PhoneFormatter parse method: "); 20 | System.out.println(p); 21 | return p; 22 | } 23 | 24 | @Override 25 | public String print(Phone phone, Locale locale) { 26 | return null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CustomerDataBindingFormatterXML/src/main/java/xing/rujuan/model/Customer.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.model; 2 | 3 | public class Customer { 4 | 5 | private String first; 6 | private String last; 7 | private Phone phone; 8 | 9 | public Customer() { 10 | } 11 | 12 | public Customer(String first, String last, Phone phone) { 13 | this.first = first; 14 | this.last = last; 15 | this.phone = phone; 16 | } 17 | 18 | public String getFirst() { 19 | return first; 20 | } 21 | 22 | public void setFirst(String first) { 23 | this.first = first; 24 | } 25 | 26 | public String getLast() { 27 | return last; 28 | } 29 | 30 | public void setLast(String last) { 31 | this.last = last; 32 | } 33 | 34 | public Phone getPhone() { 35 | return phone; 36 | } 37 | 38 | public void setPhone(Phone phone) { 39 | this.phone = phone; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /CustomerDataBindingFormatterXML/src/main/java/xing/rujuan/model/Phone.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.model; 2 | 3 | public class Phone { 4 | 5 | private String areaCode; 6 | private String prefix; 7 | private String number; 8 | 9 | public Phone() { 10 | } 11 | 12 | public Phone(String areaCode, String prefix, String number) { 13 | this.areaCode = areaCode; 14 | this.prefix = prefix; 15 | this.number = number; 16 | } 17 | 18 | public String getAreaCode() { 19 | return areaCode; 20 | } 21 | 22 | public void setAreaCode(String areaCode) { 23 | this.areaCode = areaCode; 24 | } 25 | 26 | public String getPrefix() { 27 | return prefix; 28 | } 29 | 30 | public void setPrefix(String prefix) { 31 | this.prefix = prefix; 32 | } 33 | 34 | public String getNumber() { 35 | return number; 36 | } 37 | 38 | public void setNumber(String number) { 39 | this.number = number; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "Phone{" + 45 | "areaCode='" + areaCode + '\'' + 46 | ", prefix='" + prefix + '\'' + 47 | ", number='" + number + '\'' + 48 | '}'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /CustomerDataBindingFormatterXML/src/main/webapp/WEB-INF/config/springmvc-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /CustomerDataBindingFormatterXML/src/main/webapp/WEB-INF/jsp/customerDetail.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/2/2019 5 | Time: 7:58 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Customer Detail 12 | 13 | 14 |

Name: ${customer.first} ${customer.last}

15 |

Phone Number: ${customer.phone.areaCode} - ${customer.phone.prefix}- ${customer.phone.number}

16 | 17 | 18 | -------------------------------------------------------------------------------- /CustomerDataBindingFormatterXML/src/main/webapp/WEB-INF/jsp/customerEditForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/2/2019 5 | Time: 8:22 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Edit a Customer 12 | 13 | 14 |
15 | 16 |

First Name:

17 |

Last Name:

18 |

Phone Number:

19 | 20 | 21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /CustomerDataBindingFormatterXML/src/main/webapp/WEB-INF/jsp/customerForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/2/2019 5 | Time: 7:55 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Add a new Customer 12 | 13 | 14 | 15 |

Add a new Customer

16 |
17 | 18 |

First Name:

19 |

Last Name:

20 |

Phone Number:

21 | 22 | 23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /CustomerDataBindingFormatterXML/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | DispatcherServlet 8 | org.springframework.web.servlet.DispatcherServlet 9 | 10 | 11 | contextConfigLocation 12 | /WEB-INF/config/springmvc-config.xml 13 | 14 | 15 | 16 | 17 | 18 | DispatcherServlet 19 | / 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ModelScopedAttributeXML/src/main/java/xing/rujuan/controller/ApplicationScopeAttributeController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | 8 | import javax.servlet.ServletContext; 9 | 10 | @Controller 11 | @RequestMapping("/application") 12 | public class ApplicationScopeAttributeController { 13 | 14 | @Autowired 15 | ServletContext servletContext; 16 | 17 | @GetMapping("/") 18 | public String setApplicationScopeAttribute(){ 19 | servletContext.setAttribute("applicationName", "Model Scoped Attributes"); 20 | return "redirect:/application/display"; 21 | } 22 | 23 | @GetMapping("/display") 24 | public String display(){ 25 | return "appScopeAttribute"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ModelScopedAttributeXML/src/main/java/xing/rujuan/controller/RequestScopeAttributeController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import xing.rujuan.model.Customer; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | 10 | @Controller 11 | public class RequestScopeAttributeController { 12 | 13 | @GetMapping("/") 14 | public String requestAttribute(Model model, HttpServletRequest request){ 15 | model.addAttribute("channelName", "Miss Xing"); 16 | model.addAttribute("year", 2019); 17 | Customer cust = new Customer(1, "Tina"); 18 | model.addAttribute("customer", cust); 19 | model.addAttribute("abc"); //string=abc 20 | model.addAttribute(12.0); //double=12.0 21 | request.setAttribute("authorName", "Rujuan Xing"); 22 | return "redirect:/display"; 23 | } 24 | 25 | @GetMapping("/display") 26 | public String displayRequestAttribute(){ 27 | return "requestScopeAttribute"; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /ModelScopedAttributeXML/src/main/java/xing/rujuan/controller/SessionScopeAttributeController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.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.RequestMapping; 7 | import org.springframework.web.bind.annotation.SessionAttributes; 8 | import org.springframework.web.bind.support.SessionStatus; 9 | 10 | import javax.servlet.http.HttpSession; 11 | 12 | @Controller 13 | @RequestMapping("/session") 14 | @SessionAttributes({"channelName", "hello"}) 15 | public class SessionScopeAttributeController { 16 | 17 | @GetMapping("/") 18 | public String setSessionAttribute(Model model, HttpSession session){ 19 | model.addAttribute("channelName", "Miss Xing"); 20 | model.addAttribute("hello", "world"); 21 | session.setAttribute("authorName", "Tina Xing"); 22 | session.setAttribute("channelName", "Thank you...."); 23 | 24 | //When you use HttpSession to add Session Attribute, it will add immedidately 25 | //when you use @SessionAttribute to add attribute, it will add just before the page rendering, 26 | // before the current request ends 27 | return "redirect:/session/display"; 28 | } 29 | 30 | @GetMapping("/display") 31 | public String display(SessionStatus status){ 32 | //Only remove attributes set by using @SessionAttribute 33 | //It removes attributes from session scope after the page rendering 34 | status.setComplete(); 35 | return "sessionScopeAttribute"; 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /ModelScopedAttributeXML/src/main/java/xing/rujuan/model/Customer.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.model; 2 | 3 | public class Customer { 4 | 5 | private int id; 6 | private String name; 7 | 8 | public Customer() { 9 | } 10 | 11 | public Customer(int id, String name) { 12 | this.id = id; 13 | this.name = name; 14 | } 15 | 16 | public int getId() { 17 | return id; 18 | } 19 | 20 | public void setId(int id) { 21 | this.id = id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ModelScopedAttributeXML/src/main/webapp/WEB-INF/config/springmvc-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ModelScopedAttributeXML/src/main/webapp/WEB-INF/jsp/appScopeAttribute.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/3/2019 5 | Time: 8:25 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Title 12 | 13 | 14 |

App Name: ${applicationName}

15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /ModelScopedAttributeXML/src/main/webapp/WEB-INF/jsp/requestScopeAttribute.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/3/2019 5 | Time: 6:25 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Request Scope Attribute 12 | 13 | 14 |

Spring MVC way to set Attribute in Request Scope by using Model: ${channelName}

15 |

Plain HTTP Servlet API to set attribute in request Scope: ${authorName}

16 | 17 | 18 | -------------------------------------------------------------------------------- /ModelScopedAttributeXML/src/main/webapp/WEB-INF/jsp/sessionScopeAttribute.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/3/2019 5 | Time: 8:03 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Session Attribute JSP 12 | 13 | 14 |

Channel Name: ${channelName}

15 |

Hello: ${hello}

16 |

Author Name: ${authorName}

17 |
18 |

Application Scope attribute Name: ${applicationName}

19 | 20 | 21 | -------------------------------------------------------------------------------- /ModelScopedAttributeXML/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | DispatcherServlet 8 | org.springframework.web.servlet.DispatcherServlet 9 | 10 | 11 | contextConfigLocation 12 | /WEB-INF/config/springmvc-config.xml 13 | 14 | 15 | 16 | 17 | 18 | DispatcherServlet 19 | / 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /PRGDemo/src/main/java/xing/rujuan/Order.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan; 2 | 3 | public class Order { 4 | 5 | private String productName; 6 | private String quantity; 7 | 8 | public String getProductName() { 9 | return productName; 10 | } 11 | 12 | public void setProductName(String productName) { 13 | this.productName = productName; 14 | } 15 | 16 | public String getQuantity() { 17 | return quantity; 18 | } 19 | 20 | public void setQuantity(String quantity) { 21 | this.quantity = quantity; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /PRGDemo/src/main/java/xing/rujuan/config/DispatcherServletInit.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | public class DispatcherServletInit extends AbstractAnnotationConfigDispatcherServletInitializer { 6 | 7 | @Override 8 | protected Class[] getRootConfigClasses() { 9 | return null; 10 | } 11 | 12 | @Override 13 | protected Class[] getServletConfigClasses() { 14 | return new Class[]{WebApplicationContextConfig.class}; 15 | } 16 | 17 | @Override 18 | protected String[] getServletMappings() { 19 | return new String[]{"/"}; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /PRGDemo/src/main/java/xing/rujuan/config/WebApplicationContextConfig.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.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 | 10 | 11 | @Configuration 12 | @EnableWebMvc 13 | @ComponentScan("xing.rujuan") 14 | public class WebApplicationContextConfig implements WebMvcConfigurer { 15 | 16 | @Bean 17 | public InternalResourceViewResolver getInternalResourceViewResolver(){ 18 | InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); 19 | viewResolver.setPrefix("/WEB-INF/jsp/"); 20 | viewResolver.setSuffix(".jsp"); 21 | return viewResolver; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /PRGDemo/src/main/java/xing/rujuan/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.ModelAttribute; 6 | import org.springframework.web.bind.annotation.PostMapping; 7 | import org.springframework.web.servlet.mvc.support.RedirectAttributes; 8 | import xing.rujuan.Order; 9 | 10 | @Controller 11 | public class OrderController { 12 | 13 | @GetMapping("/") 14 | public String orderForm(@ModelAttribute Order myOrder){ 15 | return "orderForm"; 16 | } 17 | 18 | @PostMapping("/saveOrder") 19 | public String saveOrder(Order o, RedirectAttributes redirectAttributes){ 20 | //save to DB 21 | System.out.println("Save to DB...."); 22 | 23 | // redirectAttributes.addFlashAttribute("placedOrder", o); 24 | redirectAttributes.addFlashAttribute(o); //order 25 | return "redirect:/success"; 26 | } 27 | 28 | @GetMapping("/success") 29 | public String success(){ 30 | return "thankyou"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /PRGDemo/src/main/webapp/WEB-INF/jsp/orderForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/3/2019 5 | Time: 10:13 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 10 | 11 | 12 | Title 13 | 14 | 15 | 16 | 17 |

Name:

18 |

Quantity:

19 | 20 |
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /PRGDemo/src/main/webapp/WEB-INF/jsp/thankyou.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/3/2019 5 | Time: 10:17 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Title 12 | 13 | 14 |

You placed order successfully....

15 | 16 |

Product Purchased: ${order.productName}

17 |

Product purchased quantity: ${order.quantity}

18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spring -------------------------------------------------------------------------------- /SpringFormTagLibrary/src/main/java/xing/rujuan/config/DispatcherServletInit.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | public class DispatcherServletInit extends AbstractAnnotationConfigDispatcherServletInitializer { 6 | 7 | @Override 8 | protected Class[] getRootConfigClasses() { 9 | return null; 10 | } 11 | 12 | @Override 13 | protected Class[] getServletConfigClasses() { 14 | return new Class[]{WebApplicationContextConfig.class}; 15 | } 16 | 17 | @Override 18 | protected String[] getServletMappings() { 19 | return new String[]{"/"}; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SpringFormTagLibrary/src/main/java/xing/rujuan/config/WebApplicationContextConfig.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.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.format.FormatterRegistry; 7 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 9 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 10 | import xing.rujuan.formatter.PhoneFormatter; 11 | import xing.rujuan.model.Phone; 12 | 13 | @Configuration 14 | @EnableWebMvc 15 | @ComponentScan("xing.rujuan") 16 | public class WebApplicationContextConfig implements WebMvcConfigurer { 17 | 18 | @Bean 19 | public InternalResourceViewResolver getInternalResourceViewResolver(){ 20 | InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); 21 | viewResolver.setPrefix("/WEB-INF/jsp/"); 22 | viewResolver.setSuffix(".jsp"); 23 | return viewResolver; 24 | } 25 | 26 | public void addFormatters(FormatterRegistry registry) { 27 | 28 | registry.addFormatter(new PhoneFormatter()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /SpringFormTagLibrary/src/main/java/xing/rujuan/formatter/PhoneFormatter.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.formatter; 2 | 3 | import org.springframework.format.Formatter; 4 | import xing.rujuan.model.Phone; 5 | 6 | import java.text.ParseException; 7 | import java.util.Locale; 8 | 9 | public class PhoneFormatter implements Formatter { 10 | 11 | @Override 12 | public Phone parse(String s, Locale locale) throws ParseException { 13 | //s=641-451-1111 14 | String[] temp = s.split("-"); 15 | Phone p = new Phone(); 16 | p.setAreaCode(temp[0]); 17 | p.setPrefix(temp[1]); 18 | p.setNumber(temp[2]); 19 | System.out.println("Inside PhoneFormatter parse method: "); 20 | System.out.println(p); 21 | return p; 22 | } 23 | 24 | @Override 25 | public String print(Phone phone, Locale locale) { 26 | String phoneStrDisplayedOnJSPPage = phone.getAreaCode() + "&&" + phone.getPrefix() + "**" + phone.getNumber(); 27 | System.out.println("Inside PhoneFormatter print() method:"); 28 | System.out.println("phoneStrDisplayedOnJSPPage: " + phoneStrDisplayedOnJSPPage); 29 | return phoneStrDisplayedOnJSPPage; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /SpringFormTagLibrary/src/main/java/xing/rujuan/model/Country.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.model; 2 | 3 | public class Country { 4 | 5 | private String id; 6 | private String name; 7 | 8 | public Country() { 9 | } 10 | 11 | public Country(String id, String name) { 12 | this.id = id; 13 | this.name = name; 14 | } 15 | 16 | public String getId() { 17 | return id; 18 | } 19 | 20 | public void setId(String id) { 21 | this.id = id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /SpringFormTagLibrary/src/main/java/xing/rujuan/model/Customer.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.model; 2 | 3 | public class Customer { 4 | 5 | private String first; 6 | private String last; 7 | private Phone phone; 8 | private Country country; 9 | 10 | public Customer() { 11 | } 12 | 13 | public Customer(String first, String last, Phone phone) { 14 | this.first = first; 15 | this.last = last; 16 | this.phone = phone; 17 | } 18 | 19 | public String getFirst() { 20 | return first; 21 | } 22 | 23 | public void setFirst(String first) { 24 | this.first = first; 25 | } 26 | 27 | public String getLast() { 28 | return last; 29 | } 30 | 31 | public void setLast(String last) { 32 | this.last = last; 33 | } 34 | 35 | public Phone getPhone() { 36 | return phone; 37 | } 38 | 39 | public void setPhone(Phone phone) { 40 | this.phone = phone; 41 | } 42 | 43 | public Country getCountry() { 44 | return country; 45 | } 46 | 47 | public void setCountry(Country country) { 48 | this.country = country; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /SpringFormTagLibrary/src/main/java/xing/rujuan/model/Phone.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.model; 2 | 3 | public class Phone { 4 | 5 | private String areaCode; 6 | private String prefix; 7 | private String number; 8 | 9 | public Phone() { 10 | } 11 | 12 | public Phone(String areaCode, String prefix, String number) { 13 | this.areaCode = areaCode; 14 | this.prefix = prefix; 15 | this.number = number; 16 | } 17 | 18 | public String getAreaCode() { 19 | return areaCode; 20 | } 21 | 22 | public void setAreaCode(String areaCode) { 23 | this.areaCode = areaCode; 24 | } 25 | 26 | public String getPrefix() { 27 | return prefix; 28 | } 29 | 30 | public void setPrefix(String prefix) { 31 | this.prefix = prefix; 32 | } 33 | 34 | public String getNumber() { 35 | return number; 36 | } 37 | 38 | public void setNumber(String number) { 39 | this.number = number; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "Phone{" + 45 | "areaCode='" + areaCode + '\'' + 46 | ", prefix='" + prefix + '\'' + 47 | ", number='" + number + '\'' + 48 | '}'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /SpringFormTagLibrary/src/main/webapp/WEB-INF/jsp/customerDetail.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/2/2019 5 | Time: 7:58 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Customer Detail 12 | 13 | 14 |

Name: ${customer.first} ${customer.last}

15 |

Phone Number: ${customer.phone.areaCode} - ${customer.phone.prefix}- ${customer.phone.number}

16 | 17 | 18 | -------------------------------------------------------------------------------- /SpringFormTagLibrary/src/main/webapp/WEB-INF/jsp/customerEditForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/2/2019 5 | Time: 8:22 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Edit a Customer 12 | 13 | 14 |
15 | 16 |

First Name:

17 |

Last Name:

18 |

Phone Number:

19 | 20 | 21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /SpringFormTagLibrary/src/main/webapp/WEB-INF/jsp/customerForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/2/2019 5 | Time: 7:55 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 10 | 11 | 12 | Add a new Customer 13 | 14 | 15 | 16 |

Add a new Customer

17 | 18 | 19 |

First Name:

20 |

Last Name:

21 |

Phone Number:

22 |

Select your country: 23 | <%----%> 24 | <%----%> 25 | <%----%> 26 | 27 | 28 | Please select a Category 29 | 30 | 31 |

32 | 33 | 34 |
35 | 36 | 37 | -------------------------------------------------------------------------------- /SpringMVCContentNegotiatingViewResolver/src/main/java/xing/rujuan/config/DispatcherServletInit.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | public class DispatcherServletInit extends AbstractAnnotationConfigDispatcherServletInitializer { 6 | 7 | @Override 8 | protected Class[] getRootConfigClasses() { 9 | return null; 10 | } 11 | 12 | @Override 13 | protected Class[] getServletConfigClasses() { 14 | return new Class[]{WebApplicationConfig.class}; 15 | } 16 | 17 | @Override 18 | protected String[] getServletMappings() { 19 | return new String[]{"/"}; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /SpringMVCContentNegotiatingViewResolver/src/main/java/xing/rujuan/config/WebApplicationConfig.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.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.accept.ContentNegotiationManager; 7 | import org.springframework.web.servlet.View; 8 | import org.springframework.web.servlet.ViewResolver; 9 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 10 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 11 | import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; 12 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 13 | import org.springframework.web.servlet.view.json.MappingJackson2JsonView; 14 | import org.springframework.web.servlet.view.xml.MappingJackson2XmlView; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | @Configuration 20 | @EnableWebMvc 21 | @ComponentScan(basePackages = {"xing.rujuan"}) 22 | public class WebApplicationConfig implements WebMvcConfigurer { 23 | 24 | @Bean 25 | public ViewResolver getInternalResourceViewResolver() { 26 | InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver(); 27 | internalResourceViewResolver.setPrefix("/WEB-INF/jsp/"); 28 | internalResourceViewResolver.setSuffix(".jsp"); 29 | return internalResourceViewResolver; 30 | } 31 | 32 | @Bean 33 | public MappingJackson2JsonView jsonView(){ 34 | MappingJackson2JsonView jsonView = new MappingJackson2JsonView(); 35 | jsonView.setPrettyPrint(true); 36 | return jsonView; 37 | } 38 | 39 | @Bean 40 | public ViewResolver contentNegotiatingViewResolver(ContentNegotiationManager manager){ 41 | ContentNegotiatingViewResolver viewResolver = new ContentNegotiatingViewResolver(); 42 | viewResolver.setContentNegotiationManager(manager); 43 | List views = new ArrayList<>(); 44 | views.add(jsonView()); 45 | views.add(new MappingJackson2XmlView()); 46 | viewResolver.setDefaultViews(views); 47 | return viewResolver; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /SpringMVCContentNegotiatingViewResolver/src/main/java/xing/rujuan/controller/ProductController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import xing.rujuan.domain.Product; 7 | 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | @Controller 12 | public class ProductController { 13 | 14 | @GetMapping({"/", "/list"}) 15 | public String getProductList(Model model){ 16 | List products = Arrays.asList( 17 | new Product(1L, "Mic", 129.00), 18 | new Product(2L, "Tablet", 229.00), 19 | new Product(3L, "Laptop", 329.00) 20 | ); 21 | // model.addAttribute("author", "Miss Xing"); 22 | model.addAttribute("products", products); 23 | return "index"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /SpringMVCContentNegotiatingViewResolver/src/main/java/xing/rujuan/domain/Product.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.domain; 2 | 3 | public class Product { 4 | 5 | private Long id; 6 | private String name; 7 | private Double price; 8 | 9 | public Product() { 10 | } 11 | 12 | public Product(Long id, String name, Double price) { 13 | this.id = id; 14 | this.name = name; 15 | this.price = price; 16 | } 17 | 18 | public Long getId() { 19 | return id; 20 | } 21 | 22 | public void setId(Long id) { 23 | this.id = id; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public Double getPrice() { 35 | return price; 36 | } 37 | 38 | public void setPrice(Double price) { 39 | this.price = price; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /SpringMVCContentNegotiatingViewResolver/src/main/webapp/WEB-INF/jsp/index.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/9/2019 5 | Time: 5:43 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 10 | 11 | 12 | Product List Page 13 | 15 | 16 | 17 |
18 |

Product List

19 |

Author: ${author}

20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 |
IDNamePrice
${p.id}${p.name}${p.price}
38 |
39 | 40 | 41 | -------------------------------------------------------------------------------- /SpringMVCContentNegotiatingViewResolverXML/src/main/java/xing/rujuan/controller/ProductController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import xing.rujuan.domain.Product; 7 | 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | @Controller 12 | public class ProductController { 13 | 14 | @GetMapping({"/", "/list"}) 15 | public String getProductList(Model model){ 16 | List products = Arrays.asList( 17 | new Product(1L, "Mic", 129.00), 18 | new Product(2L, "Tablet", 229.00), 19 | new Product(3L, "Laptop", 329.00) 20 | ); 21 | // model.addAttribute("author", "Miss Xing"); 22 | model.addAttribute("products", products); 23 | return "index"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /SpringMVCContentNegotiatingViewResolverXML/src/main/java/xing/rujuan/domain/Product.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.domain; 2 | 3 | public class Product { 4 | 5 | private Long id; 6 | private String name; 7 | private Double price; 8 | 9 | public Product() { 10 | } 11 | 12 | public Product(Long id, String name, Double price) { 13 | this.id = id; 14 | this.name = name; 15 | this.price = price; 16 | } 17 | 18 | public Long getId() { 19 | return id; 20 | } 21 | 22 | public void setId(Long id) { 23 | this.id = id; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public Double getPrice() { 35 | return price; 36 | } 37 | 38 | public void setPrice(Double price) { 39 | this.price = price; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /SpringMVCContentNegotiatingViewResolverXML/src/main/webapp/WEB-INF/config/springmvc-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 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 | -------------------------------------------------------------------------------- /SpringMVCContentNegotiatingViewResolverXML/src/main/webapp/WEB-INF/jsp/index.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/9/2019 5 | Time: 5:43 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 10 | 11 | 12 | Product List Page 13 | 15 | 16 | 17 |
18 |

Product List

19 |

Author: ${author}

20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 |
IDNamePrice
${p.id}${p.name}${p.price}
38 |
39 | 40 | 41 | -------------------------------------------------------------------------------- /SpringMVCContentNegotiatingViewResolverXML/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | DispatcherServlet 8 | org.springframework.web.servlet.DispatcherServlet 9 | 10 | 11 | contextConfigLocation 12 | /WEB-INF/config/springmvc-config.xml 13 | 14 | 15 | 16 | 17 | 18 | DispatcherServlet 19 | / 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /SpringMVCStaticResourcesHandlingXML/src/main/java/xing/rujuan/IndexController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class IndexController { 8 | 9 | @GetMapping("/") 10 | public String index(){ 11 | return "index"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /SpringMVCStaticResourcesHandlingXML/src/main/java/xing/rujuan/config/WebApplicationContextConfig.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.config; 2 | 3 | import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; 4 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | public class WebApplicationContextConfig implements WebMvcConfigurer { 8 | 9 | // 10 | 11 | @Override 12 | public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { 13 | configurer.enable(); 14 | } 15 | 16 | // 17 | @Override 18 | public void addResourceHandlers(final ResourceHandlerRegistry registry) { 19 | registry.addResourceHandler("/abc/**").addResourceLocations("/resources/"); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /SpringMVCStaticResourcesHandlingXML/src/main/webapp/WEB-INF/config/springmvc-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /SpringMVCStaticResourcesHandlingXML/src/main/webapp/WEB-INF/jsp/index.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/3/2019 5 | Time: 8:38 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 10 | 11 | 12 | Static Resources 13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 |     
21 | 
22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /SpringMVCStaticResourcesHandlingXML/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | DispatcherServlet 8 | org.springframework.web.servlet.DispatcherServlet 9 | 10 | 11 | contextConfigLocation 12 | /WEB-INF/config/springmvc-config.xml 13 | 14 | 15 | 16 | 17 | 18 | DispatcherServlet 19 | / 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /SpringMVCStaticResourcesHandlingXML/src/main/webapp/resources/images/dog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TinaXing2012/Spring/83e697da35760183e6d13ab462b45cbfa580ed91/SpringMVCStaticResourcesHandlingXML/src/main/webapp/resources/images/dog.jpg -------------------------------------------------------------------------------- /SpringMVCStaticResourcesHandlingXML/src/main/webapp/resources/images/user/cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TinaXing2012/Spring/83e697da35760183e6d13ab462b45cbfa580ed91/SpringMVCStaticResourcesHandlingXML/src/main/webapp/resources/images/user/cat.jpg -------------------------------------------------------------------------------- /SpringMVCViewResolverXML/src/main/java/xing/rujuan/controller/ViewResolverDemoController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.ModelAttribute; 6 | 7 | @Controller 8 | public class ViewResolverDemoController { 9 | 10 | @GetMapping("/") 11 | public String home(){ 12 | return "redirect:/jsp"; 13 | } 14 | 15 | @GetMapping("/jsp") 16 | public String jspDemo(){ 17 | return "index.jsp"; 18 | } 19 | 20 | @GetMapping("/thymeleaf") 21 | public String thymeleafDemo(){ 22 | return "index.html"; 23 | } 24 | 25 | @ModelAttribute("projectName") 26 | public String getProjectName(){ 27 | return "View Resolver Demo"; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /SpringMVCViewResolverXML/src/main/webapp/WEB-INF/config/springmvc-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 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 | -------------------------------------------------------------------------------- /SpringMVCViewResolverXML/src/main/webapp/WEB-INF/jsp/index.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/9/2019 5 | Time: 5:43 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | JSP Page 12 | 13 | 14 |

${projectName}

15 | This is JSP demo..... 16 | 17 | 18 | -------------------------------------------------------------------------------- /SpringMVCViewResolverXML/src/main/webapp/WEB-INF/thymeleaf/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Home Page 6 | 7 | 8 | 9 |

10 | This is Thymeleaf demo..... 11 | 12 | 13 | -------------------------------------------------------------------------------- /SpringMVCViewResolverXML/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | DispatcherServlet 8 | org.springframework.web.servlet.DispatcherServlet 9 | 10 | 11 | contextConfigLocation 12 | /WEB-INF/config/springmvc-config.xml 13 | 14 | 15 | 16 | 17 | 18 | DispatcherServlet 19 | / 20 | 21 | 22 | -------------------------------------------------------------------------------- /SpringMVCi18nJavaConfig/src/main/java/xing/rujuan/config/DispatcherServletInit.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | public class DispatcherServletInit extends AbstractAnnotationConfigDispatcherServletInitializer { 6 | @Override 7 | protected Class[] getRootConfigClasses() { 8 | return null; 9 | } 10 | 11 | @Override 12 | protected Class[] getServletConfigClasses() { 13 | return new Class[]{WebApplicationContextConfig.class}; 14 | } 15 | 16 | @Override 17 | protected String[] getServletMappings() { 18 | return new String[]{"/"}; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /SpringMVCi18nJavaConfig/src/main/java/xing/rujuan/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class UserController { 8 | 9 | @GetMapping({"/", "/add"}) 10 | public String userForm(){ 11 | return "userForm"; 12 | } 13 | 14 | @GetMapping("/test") 15 | public String testLocale(){ 16 | return "home"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /SpringMVCi18nJavaConfig/src/main/resources/messages.properties: -------------------------------------------------------------------------------- 1 | userform.title=Add New User 2 | userform.username=User Name: 3 | userform.password=Password: -------------------------------------------------------------------------------- /SpringMVCi18nJavaConfig/src/main/resources/messages_zh_CN.properties: -------------------------------------------------------------------------------- 1 | userform.title=\u65B0\u6210\u5458 2 | userform.username=\u7528\u6237\u540D\uFF1A 3 | userform.password=\u5BC6\u7801\uFF1A -------------------------------------------------------------------------------- /SpringMVCi18nJavaConfig/src/main/webapp/WEB-INF/jsp/home.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/8/2019 5 | Time: 9:50 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 10 | 11 | 12 | Title 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /SpringMVCi18nJavaConfig/src/main/webapp/WEB-INF/jsp/userForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/8/2019 5 | Time: 8:22 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 10 | 11 | 12 | <spring:message code="userform.title" text="Default Title"/> 13 | 14 | 15 |

English|Chinese

16 |

17 |
18 |

19 |

20 | " /> 21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /SpringMVCi18nXML/src/main/java/xing/rujuan/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class UserController { 8 | 9 | @GetMapping({"/", "/add"}) 10 | public String userForm(){ 11 | return "userForm"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /SpringMVCi18nXML/src/main/resources/messages.properties: -------------------------------------------------------------------------------- 1 | userform.title=Add New User 2 | userform.username=User Name: 3 | userform.password=Password: -------------------------------------------------------------------------------- /SpringMVCi18nXML/src/main/resources/messages_zh_CN.properties: -------------------------------------------------------------------------------- 1 | userform.title=新成员 2 | userform.username=\u7528\u6237\u540D\uFF1A 3 | userform.password=\u5BC6\u7801\uFF1A -------------------------------------------------------------------------------- /SpringMVCi18nXML/src/main/webapp/WEB-INF/config/springmvc-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 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 | -------------------------------------------------------------------------------- /SpringMVCi18nXML/src/main/webapp/WEB-INF/jsp/userForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/8/2019 5 | Time: 8:22 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 10 | 11 | 12 | <spring:message code="userform.title" text="Default Title"/> 13 | 14 | 15 |

English|Chinese

16 |

17 |
18 |

19 |

20 | " /> 21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /SpringMVCi18nXML/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | DispatcherServlet 8 | org.springframework.web.servlet.DispatcherServlet 9 | 10 | 11 | contextConfigLocation 12 | /WEB-INF/config/springmvc-config.xml 13 | 14 | 15 | 16 | 17 | 18 | DispatcherServlet 19 | / 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /SpringValidationJavaConfig/src/main/java/xing/rujuan/config/DispatcherServletInit.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | public class DispatcherServletInit extends AbstractAnnotationConfigDispatcherServletInitializer { 6 | @Override 7 | protected Class[] getRootConfigClasses() { 8 | return null; 9 | } 10 | 11 | @Override 12 | protected Class[] getServletConfigClasses() { 13 | return new Class[]{WebApplicationContextConfig.class}; 14 | } 15 | 16 | @Override 17 | protected String[] getServletMappings() { 18 | return new String[]{"/"}; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /SpringValidationJavaConfig/src/main/java/xing/rujuan/config/WebApplicationContextConfig.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.config; 2 | 3 | import org.springframework.context.MessageSource; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.context.support.ResourceBundleMessageSource; 8 | import org.springframework.validation.Validator; 9 | import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; 10 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 11 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 12 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 13 | 14 | @Configuration 15 | @EnableWebMvc 16 | @ComponentScan({"xing.rujuan"}) 17 | public class WebApplicationContextConfig implements WebMvcConfigurer { 18 | 19 | @Bean 20 | public InternalResourceViewResolver getInternalResourceViewResolver(){ 21 | InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); 22 | viewResolver.setPrefix("/WEB-INF/jsp/"); 23 | viewResolver.setSuffix(".jsp"); 24 | return viewResolver; 25 | } 26 | 27 | @Bean 28 | public MessageSource messageSource() { 29 | ResourceBundleMessageSource resource = new ResourceBundleMessageSource(); 30 | resource.setBasenames("messages", "errorMessages"); 31 | return resource; 32 | } 33 | 34 | @Bean(name="validator") 35 | public LocalValidatorFactoryBean validator() { 36 | LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean(); 37 | bean.setValidationMessageSource(messageSource()); 38 | return bean; 39 | } 40 | 41 | @Override 42 | public Validator getValidator() { 43 | return validator(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /SpringValidationJavaConfig/src/main/java/xing/rujuan/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.validation.BindingResult; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.ModelAttribute; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.servlet.mvc.support.RedirectAttributes; 11 | import xing.rujuan.domain.User; 12 | 13 | import javax.validation.Valid; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | @Controller 18 | @RequestMapping("/user") 19 | public class UserController { 20 | 21 | @ModelAttribute("roles") 22 | private Map populateRoles(){ 23 | Map roleMap = new HashMap<>(); 24 | roleMap.put("Admin", "Admin"); 25 | roleMap.put("DBA", "DBA"); 26 | return roleMap; 27 | } 28 | 29 | @GetMapping("/add") 30 | public String getUserForm(@ModelAttribute("newUser") User user, Model model){ 31 | return "userForm"; 32 | } 33 | 34 | @PostMapping("/add") 35 | public String saveUser(@Valid @ModelAttribute("newUser") User user, BindingResult result, RedirectAttributes redirectAttributes){ 36 | if(result.hasErrors()){ 37 | 38 | return "userForm"; 39 | } 40 | 41 | //Save to DB 42 | redirectAttributes.addFlashAttribute("savedUser", user); 43 | return "redirect:/user/userDetails"; 44 | } 45 | 46 | @GetMapping("/userDetails") 47 | public String success(){ 48 | 49 | return "success"; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /SpringValidationJavaConfig/src/main/java/xing/rujuan/domain/Address.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.domain; 2 | 3 | import javax.validation.constraints.NotBlank; 4 | import javax.validation.constraints.NotNull; 5 | import javax.validation.constraints.Size; 6 | 7 | public class Address { 8 | 9 | @NotBlank(message = "{address.street}") 10 | private String street; 11 | 12 | @Size(min=2, max=2, message = "Size of state must be 2") 13 | private String state; 14 | 15 | @NotNull(message = "zipcode is a required field") 16 | private Integer zipcode; 17 | 18 | public String getStreet() { 19 | return street; 20 | } 21 | 22 | public void setStreet(String street) { 23 | this.street = street; 24 | } 25 | 26 | public String getState() { 27 | return state; 28 | } 29 | 30 | public void setState(String state) { 31 | this.state = state; 32 | } 33 | 34 | public Integer getZipcode() { 35 | return zipcode; 36 | } 37 | 38 | public void setZipcode(Integer zipcode) { 39 | this.zipcode = zipcode; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /SpringValidationJavaConfig/src/main/java/xing/rujuan/domain/User.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.domain; 2 | 3 | import org.springframework.format.annotation.DateTimeFormat; 4 | 5 | import javax.validation.Valid; 6 | import javax.validation.constraints.*; 7 | import java.time.LocalDate; 8 | import java.util.Date; 9 | 10 | public class User { 11 | 12 | @Size(min=2, max=30, message = "{abc}") 13 | private String name; 14 | 15 | @Email(message = "Email must follow the formatter: ***@***") 16 | @NotBlank(message = "Email must have a value") 17 | private String email; 18 | 19 | @Min(value = 18, message = "must be greater or equal to 18") 20 | @NotNull(message = "{notnull.age}") 21 | private Integer age; 22 | 23 | @NotNull(message = "birthday is a required field.") 24 | @DateTimeFormat(pattern = "MM-dd-yyyy") 25 | private LocalDate birthday; 26 | 27 | @NotBlank(message = "Role must have a value") 28 | private String role; 29 | 30 | @Valid 31 | private Address addr; 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | public String getEmail() { 42 | return email; 43 | } 44 | 45 | public void setEmail(String email) { 46 | this.email = email; 47 | } 48 | 49 | public Integer getAge() { 50 | return age; 51 | } 52 | 53 | public void setAge(Integer age) { 54 | this.age = age; 55 | } 56 | 57 | public LocalDate getBirthday() { 58 | return birthday; 59 | } 60 | 61 | public void setBirthday(LocalDate birthday) { 62 | this.birthday = birthday; 63 | } 64 | 65 | public String getRole() { 66 | return role; 67 | } 68 | 69 | public void setRole(String role) { 70 | this.role = role; 71 | } 72 | 73 | public Address getAddr() { 74 | return addr; 75 | } 76 | 77 | public void setAddr(Address addr) { 78 | this.addr = addr; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /SpringValidationJavaConfig/src/main/resources/errorMessages.properties: -------------------------------------------------------------------------------- 1 | abc=Size of {0} must between {2} and {1} 2 | notnull.age={0} must be greater than 18 3 | address.street={0} cannot be blank 4 | 5 | name=User Name 6 | age=Age 7 | addr.street=Address Street 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /SpringValidationJavaConfig/src/main/resources/messages.properties: -------------------------------------------------------------------------------- 1 | userForm.title=Add a new user 2 | user.name=User Name: 3 | user.email=Email: -------------------------------------------------------------------------------- /SpringValidationJavaConfig/src/main/webapp/WEB-INF/jsp/success.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/5/2019 5 | Time: 5:24 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Success 12 | 13 | 14 |

User Saved Successfully

15 |

Name: ${savedUser.name}

16 |

Email: ${savedUser.email}

17 |

Birthday: ${savedUser.birthday}

18 |

Age: ${savedUser.age}

19 |

Role: ${savedUser.role}

20 | 21 |

Address Info

22 |

Street: ${savedUser.addr.street}

23 |

State: ${savedUser.addr.state}

24 |

Zip Code: ${savedUser.addr.zipcode}

25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /SpringValidationJavaConfig/src/main/webapp/WEB-INF/jsp/userForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/5/2019 5 | Time: 5:11 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 10 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 11 | 12 | 13 | Add A new User 14 | 19 | 20 | 21 | 22 |

23 | 24 | 25 |

26 |

27 |

28 |

29 |

30 |

Age:

31 |

Role: 32 | 33 | Select Role 34 | 35 | 36 | 37 |

38 | 39 |

Address Info:

40 |

Street:

41 |

State:

42 |

Zip code:

43 | 44 | 45 | 46 |
47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /SpringValidationXML/src/main/java/xing/rujuan/controller/HomeController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import xing.rujuan.exception.UserNotFoundException; 6 | 7 | @Controller 8 | public class HomeController { 9 | 10 | @GetMapping("/") 11 | public String index(){ 12 | return "redirect:/user/add"; 13 | } 14 | 15 | @GetMapping("/user/retrieve") 16 | public String fakeGetUser(){ 17 | throw new UserNotFoundException("This is a practice......"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /SpringValidationXML/src/main/java/xing/rujuan/domain/Address.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.domain; 2 | 3 | import javax.validation.constraints.NotBlank; 4 | import javax.validation.constraints.NotNull; 5 | import javax.validation.constraints.Size; 6 | 7 | public class Address { 8 | 9 | @NotBlank(message = "{address.street}") 10 | private String street; 11 | 12 | @Size(min=2, max=2, message = "Size of state must be 2") 13 | private String state; 14 | 15 | @NotNull(message = "zipcode is a required field") 16 | private Integer zipcode; 17 | 18 | public String getStreet() { 19 | return street; 20 | } 21 | 22 | public void setStreet(String street) { 23 | this.street = street; 24 | } 25 | 26 | public String getState() { 27 | return state; 28 | } 29 | 30 | public void setState(String state) { 31 | this.state = state; 32 | } 33 | 34 | public Integer getZipcode() { 35 | return zipcode; 36 | } 37 | 38 | public void setZipcode(Integer zipcode) { 39 | this.zipcode = zipcode; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /SpringValidationXML/src/main/java/xing/rujuan/domain/User.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.domain; 2 | 3 | import org.springframework.format.annotation.DateTimeFormat; 4 | import org.springframework.web.multipart.MultipartFile; 5 | import xing.rujuan.validation.Age; 6 | 7 | import javax.validation.Valid; 8 | import javax.validation.constraints.*; 9 | import java.time.LocalDate; 10 | import java.util.Date; 11 | 12 | @Age(message = "{custom.age.message}") 13 | public class User { 14 | 15 | @Size(min=2, max=30, message = "{abc}") 16 | private String name; 17 | 18 | @Email(message = "Email must follow the formatter: ***@***") 19 | @NotBlank(message = "Email must have a value") 20 | private String email; 21 | 22 | @Min(value = 18, message = "must be greater or equal to 18") 23 | @NotNull(message = "{notnull.age}") 24 | private Integer age; 25 | 26 | @NotNull(message = "birthday is a required field.") 27 | @DateTimeFormat(pattern = "MM-dd-yyyy") 28 | private LocalDate birthday; 29 | 30 | @NotBlank(message = "Role must have a value") 31 | private String role; 32 | 33 | private MultipartFile profileImage; 34 | 35 | @Valid 36 | private Address addr; 37 | 38 | public String getName() { 39 | return name; 40 | } 41 | 42 | public void setName(String name) { 43 | this.name = name; 44 | } 45 | 46 | public String getEmail() { 47 | return email; 48 | } 49 | 50 | public void setEmail(String email) { 51 | this.email = email; 52 | } 53 | 54 | public Integer getAge() { 55 | return age; 56 | } 57 | 58 | public void setAge(Integer age) { 59 | this.age = age; 60 | } 61 | 62 | public LocalDate getBirthday() { 63 | return birthday; 64 | } 65 | 66 | public void setBirthday(LocalDate birthday) { 67 | this.birthday = birthday; 68 | } 69 | 70 | public String getRole() { 71 | return role; 72 | } 73 | 74 | public void setRole(String role) { 75 | this.role = role; 76 | } 77 | 78 | public Address getAddr() { 79 | return addr; 80 | } 81 | 82 | public void setAddr(Address addr) { 83 | this.addr = addr; 84 | } 85 | 86 | public MultipartFile getProfileImage() { 87 | return profileImage; 88 | } 89 | 90 | public void setProfileImage(MultipartFile profileImage) { 91 | this.profileImage = profileImage; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /SpringValidationXML/src/main/java/xing/rujuan/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.exception; 2 | 3 | import org.springframework.ui.Model; 4 | import org.springframework.web.bind.annotation.ControllerAdvice; 5 | import org.springframework.web.bind.annotation.ExceptionHandler; 6 | import org.springframework.web.bind.annotation.InitBinder; 7 | import org.springframework.web.bind.annotation.ModelAttribute; 8 | import org.springframework.web.multipart.MaxUploadSizeExceededException; 9 | 10 | @ControllerAdvice 11 | public class GlobalExceptionHandler { 12 | 13 | @ModelAttribute("channel") 14 | public String channelName(){ 15 | return "Miss Xing"; 16 | } 17 | 18 | @ExceptionHandler(UserNotFoundException.class) 19 | public String handleUserNotFoundException(UserNotFoundException e, Model model){ 20 | model.addAttribute("msg", e.getMessage()); 21 | return "error"; 22 | } 23 | 24 | @ExceptionHandler(MaxUploadSizeExceededException.class) 25 | public String handleMaxUploadSizeExceededException(Exception e, Model m){ 26 | m.addAttribute("msg", e.getMessage()); 27 | return "error"; 28 | } 29 | 30 | @ExceptionHandler(Exception.class) 31 | public String handleException(Exception e, Model m){ 32 | m.addAttribute("msg", e.getMessage()); 33 | return "error"; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /SpringValidationXML/src/main/java/xing/rujuan/exception/UserNotFoundException.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "This is a bad request....") 7 | public class UserNotFoundException extends RuntimeException { 8 | private String message; 9 | 10 | public UserNotFoundException(String message) { 11 | this.message = message; 12 | } 13 | 14 | @Override 15 | public String getMessage() { 16 | return message; 17 | } 18 | 19 | public void setMessage(String message) { 20 | this.message = message; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SpringValidationXML/src/main/java/xing/rujuan/interceptor/ProcessingTimeInterceptor.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.interceptor; 2 | 3 | import org.springframework.lang.Nullable; 4 | import org.springframework.web.servlet.HandlerInterceptor; 5 | import org.springframework.web.servlet.ModelAndView; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | public class ProcessingTimeInterceptor implements HandlerInterceptor { 11 | 12 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 13 | long startTime = System.currentTimeMillis(); 14 | request.setAttribute("startTime", startTime); 15 | return true; 16 | } 17 | 18 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception { 19 | long endTime = System.currentTimeMillis(); 20 | long startTime = (Long) request.getAttribute("startTime"); 21 | System.out.println("Processing this request " + request.getRequestURI() + " took " + (endTime - startTime)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SpringValidationXML/src/main/java/xing/rujuan/validation/Age.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.validation; 2 | 3 | import javax.validation.Constraint; 4 | import javax.validation.Payload; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | @Target(ElementType.TYPE) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Constraint(validatedBy = AgeValidation.class) 13 | public @interface Age { 14 | String message() default "{age.error.message}"; 15 | Class[] groups() default {}; 16 | public abstract Class[] payload() default {}; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /SpringValidationXML/src/main/java/xing/rujuan/validation/AgeValidation.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.validation; 2 | 3 | import xing.rujuan.domain.User; 4 | 5 | import javax.validation.ConstraintValidator; 6 | import javax.validation.ConstraintValidatorContext; 7 | import java.time.LocalDate; 8 | import java.time.Period; 9 | 10 | public class AgeValidation implements ConstraintValidator { 11 | 12 | @Override 13 | public boolean isValid(User user, ConstraintValidatorContext constraintValidatorContext) { 14 | if(user.getBirthday() == null || user.getAge() == null) return false; 15 | Period p = Period.between(user.getBirthday(), LocalDate.now()); 16 | return p.getYears() == user.getAge(); 17 | } 18 | 19 | @Override 20 | public void initialize(Age constraintAnnotation) { 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SpringValidationXML/src/main/resources/errorMessages.properties: -------------------------------------------------------------------------------- 1 | abc=Size of {0} must between {2} and {1} 2 | notnull.age={0} must be greater than 18 3 | address.street={0} cannot be blank 4 | 5 | name=User Name 6 | age=Age 7 | addr.street=Address Street 8 | 9 | age.error.message=Age and Birth Date doesn't match - from externalized message file 10 | custom.age.message=Age and Birth Date doesn't match-Customized from message file....... 11 | 12 | -------------------------------------------------------------------------------- /SpringValidationXML/src/main/resources/messages.properties: -------------------------------------------------------------------------------- 1 | userForm.title=Add a new user 2 | user.name=User Name: 3 | user.email=Email: -------------------------------------------------------------------------------- /SpringValidationXML/src/main/resources/messages_zh_CN.properties: -------------------------------------------------------------------------------- 1 | userForm.title=\u65B0\u6210\u5458 2 | user.name=\u7528\u6237\u540D\uFF1A 3 | user.email=\u5BC6\u7801\uFF1A -------------------------------------------------------------------------------- /SpringValidationXML/src/main/webapp/WEB-INF/jsp/error.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/8/2019 5 | Time: 3:28 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Title 12 | 13 | 14 |

This is a customized user friendly error page

15 | ${msg} 16 | 17 |

Channel Name: ${channel}

18 | 19 | 20 | -------------------------------------------------------------------------------- /SpringValidationXML/src/main/webapp/WEB-INF/jsp/success.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/5/2019 5 | Time: 5:24 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 10 | 11 | 12 | Success 13 | 14 | 15 |

Channel Name: ${channel}

16 | 17 |

User Saved Successfully

18 |

Name: ${savedUser.name}

19 |

Email: ${savedUser.email}

20 |

Birthday: ${savedUser.birthday}

21 |

Age: ${savedUser.age}

22 |

Role: ${savedUser.role}

23 |

Profile Image:

24 |

Address Info

25 |

Street: ${savedUser.addr.street}

26 |

State: ${savedUser.addr.state}

27 |

Zip Code: ${savedUser.addr.zipcode}

28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /SpringValidationXML/src/main/webapp/WEB-INF/jsp/userForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/5/2019 5 | Time: 5:11 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 10 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 11 | <%@ taglib prefix="from" uri="http://www.springframework.org/tags/form" %> 12 | 13 | 14 | Add A new User 15 | 20 | 21 | 22 |

Channel Name: ${channel}

23 |

English|Chinese

24 |

25 | 26 | 27 |

28 |

29 |

30 |

31 |

32 |

Age:

33 |

Role: 34 | 35 | Select Role 36 | 37 | 38 | 39 |

40 | 41 |

Profile Image:

42 | 43 |

Address Info:

44 |

Street:

45 |

State:

46 |

Zip code:

47 | 48 | 49 | 50 |
51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /SpringValidationXML/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | DispatcherServlet 8 | org.springframework.web.servlet.DispatcherServlet 9 | 10 | 11 | contextConfigLocation 12 | /WEB-INF/config/springmvc-config.xml 13 | 14 | 15 | 16 | 17 | 18 | DispatcherServlet 19 | / 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /employee-management/.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 | -------------------------------------------------------------------------------- /employee-management/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.9.RELEASE 9 | 10 | 11 | xing.rujuan 12 | employee-management 13 | 0.0.1-SNAPSHOT 14 | employee-management 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-thymeleaf 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | org.projectlombok 33 | lombok 34 | true 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-test 39 | test 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-maven-plugin 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /employee-management/src/main/java/xing/rujuan/employeemanagement/EmployeeManagementApplication.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.employeemanagement; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class EmployeeManagementApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(EmployeeManagementApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /employee-management/src/main/java/xing/rujuan/employeemanagement/controller/EmployeeController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.employeemanagement.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.validation.BindingResult; 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 | import org.springframework.web.servlet.mvc.support.RedirectAttributes; 9 | import xing.rujuan.employeemanagement.domain.Employee; 10 | 11 | import javax.validation.Valid; 12 | 13 | @Controller 14 | public class EmployeeController { 15 | 16 | @GetMapping({"/","/addEmp"}) 17 | public String getEmpForm(@ModelAttribute("emp") Employee emp){ 18 | return "empForm"; 19 | } 20 | 21 | @PostMapping("/addEmp") 22 | public String saveEmp(@Valid @ModelAttribute("emp") Employee emp, BindingResult result, RedirectAttributes ra){ 23 | //save to DB 24 | if(result.hasErrors()){ 25 | return "empForm"; 26 | } 27 | ra.addFlashAttribute("savedEmployee", emp); 28 | return "redirect:/detail"; 29 | } 30 | 31 | @GetMapping("/detail") 32 | public String detail(){ 33 | return "empDetail"; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /employee-management/src/main/java/xing/rujuan/employeemanagement/domain/Address.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.employeemanagement.domain; 2 | 3 | 4 | import lombok.*; 5 | 6 | import javax.validation.constraints.NotBlank; 7 | import javax.validation.constraints.Size; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class Address { 13 | 14 | @NotBlank 15 | @Size(min = 5, max = 20, message = "First Name must be between 5 and 20") 16 | private String street; 17 | 18 | @Size(min=2, max=2, message = "State only allows 2 characters") 19 | private String state; 20 | private String zipCode; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /employee-management/src/main/java/xing/rujuan/employeemanagement/domain/Employee.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.employeemanagement.domain; 2 | 3 | import lombok.*; 4 | 5 | import javax.validation.Valid; 6 | import javax.validation.constraints.NotBlank; 7 | import javax.validation.constraints.NotNull; 8 | import javax.validation.constraints.Size; 9 | 10 | @Setter 11 | @Getter 12 | @ToString 13 | @EqualsAndHashCode 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | public class Employee { 17 | 18 | @NotNull(message = "Id cannot be Null") 19 | private Integer id; 20 | 21 | @NotBlank 22 | @Size(min = 2, max = 18, message = "First Name must be between 2 and 18") 23 | private String firstName; 24 | private String lastName; 25 | 26 | @Valid 27 | private Address address; 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /employee-management/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /employee-management/src/main/resources/templates/empDetail.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Employee Detail 6 | 7 | 8 |

ID:

9 |

First Name:

10 |

Last Name:

11 |

Street:

12 |

State:

13 |

ZipCode:

14 | 15 | 16 | -------------------------------------------------------------------------------- /employee-management/src/main/resources/templates/empForm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 11 | 12 | 13 |

Add new Employee

14 |
15 |
    16 |
  • Input is incorrect
  • 17 |
18 |

ID: 19 | 20 |

21 |

First Name: 22 |

23 |

Last Name:

24 |

Address:

25 |

Street: 26 |

27 |

28 |

State: 29 |

30 |

31 |

Zip Code:

32 | 33 |
34 | 35 | 36 | -------------------------------------------------------------------------------- /employee-management/src/test/java/xing/rujuan/employeemanagement/EmployeeManagementApplicationTests.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.employeemanagement; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class EmployeeManagementApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springaop/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | xing.rujuan 8 | springaop 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | org.springframework 14 | spring-context 15 | 5.2.1.RELEASE 16 | 17 | 18 | 19 | org.aspectj 20 | aspectjrt 21 | 1.9.4 22 | 23 | 24 | 25 | org.aspectj 26 | aspectjweaver 27 | 1.9.4 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/advices/AccountService.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.advices; 2 | 3 | public interface AccountService { 4 | 5 | void deposit(double amount); 6 | } 7 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/advices/AccountServiceImpl.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.advices; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class AccountServiceImpl implements AccountService { 7 | public void deposit(double amount) { 8 | System.out.println("Deposit successfully: " + amount); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/advices/App.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.advices; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 5 | 6 | public class App { 7 | 8 | public static void main(String[] args){ 9 | ApplicationContext context = new AnnotationConfigApplicationContext(Config.class); 10 | CustomerService customerService = context.getBean(CustomerService.class); 11 | // customerService.doSomething(); 12 | // 13 | // System.out.println("\n"); 14 | // 15 | // AccountService accountService = context.getBean(AccountService.class); 16 | // accountService.deposit(1000.00); 17 | 18 | // String returnName = customerService.getName(); 19 | // System.out.println(returnName); 20 | // customerService.getAge(); 21 | double payment = customerService.calculatePayment(20, 5); 22 | System.out.println("payment: " + payment); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/advices/Config.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.advices; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 6 | 7 | @Configuration 8 | @ComponentScan("xing.rujuan.aop.advices") 9 | @EnableAspectJAutoProxy 10 | public class Config { 11 | } 12 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/advices/CustomerService.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.advices; 2 | 3 | public interface CustomerService { 4 | 5 | void doSomething(); 6 | 7 | String getName(); 8 | 9 | String getAge(); 10 | 11 | double calculatePayment(double rate, int hours); 12 | } 13 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/advices/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.advices; 2 | 3 | import org.springframework.stereotype.Component; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class CustomerServiceImpl implements CustomerService { 8 | 9 | public void doSomething() { 10 | System.out.println("Do Something in CustomerServiceImpl..."); 11 | } 12 | 13 | public String getName() { 14 | return "Miss Xing"; 15 | } 16 | 17 | public String getAge() { 18 | throw new MyException("my exception..."); 19 | } 20 | 21 | public double calculatePayment(double rate, int hours) { 22 | System.out.println("Rate: " + rate + ", hours: " + hours); 23 | return rate * hours; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/advices/LogAspect.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.advices; 2 | 3 | import org.aspectj.lang.JoinPoint; 4 | import org.aspectj.lang.ProceedingJoinPoint; 5 | import org.aspectj.lang.annotation.*; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Aspect 9 | @Component 10 | public class LogAspect { 11 | 12 | @Before("execution(* xing.rujuan.aop.advices.AccountService.*(..))") 13 | public void logBefore(JoinPoint joinPoint) { 14 | System.out.println("Log before executing...." + joinPoint.getSignature().getName()); 15 | System.out.println(joinPoint.getTarget().getClass().getName()); 16 | System.out.println("Args: " + joinPoint.getArgs()[0]); 17 | System.out.println(joinPoint.getThis().getClass().getName()); 18 | } 19 | 20 | @After("execution(* xing.rujuan.aop.advices.CustomerService.*(..))") 21 | public void logAfter(JoinPoint joinPoint) { 22 | System.out.println("Log After executing---"); 23 | } 24 | 25 | @AfterReturning(pointcut = "execution(* *(..))", returning = "myname") 26 | public void logAfterReturning(String myname) { 27 | System.out.println("Return value: " + myname); 28 | } 29 | 30 | @AfterThrowing(pointcut = "execution(* getAge(..))", throwing="ex") 31 | public void logAfterThrowing(JoinPoint joinPoint, MyException ex){ 32 | System.out.println(joinPoint.getSignature().getName() + " throws exception: " + ex.getMsg()); 33 | } 34 | 35 | @Around("execution(* xing.rujuan.aop.advices.CustomerService.calculatePayment(double, int))") 36 | public Object aroundAdvice(ProceedingJoinPoint joinPoint){ 37 | Object[] args = joinPoint.getArgs(); 38 | System.out.println("Args in Around Advice: " + args[0] + ", " + args[1]); 39 | 40 | args[0] = 30; 41 | args[1] = 9; 42 | 43 | Object result = null; 44 | try{ 45 | result = joinPoint.proceed(args); 46 | }catch (Throwable ex){ 47 | ex.printStackTrace(); 48 | } 49 | System.out.println("Result in Around Advice: " + result); 50 | 51 | return 60.0; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/advices/MyException.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.advices; 2 | 3 | public class MyException extends RuntimeException { 4 | 5 | private String msg; 6 | 7 | public MyException(String msg) { 8 | this.msg = msg; 9 | } 10 | 11 | public String getMsg() { 12 | return msg; 13 | } 14 | 15 | public void setMsg(String msg) { 16 | this.msg = msg; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/proxy/App.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.proxy; 2 | 3 | public class App { 4 | 5 | public static void main(String[] args){ 6 | FancyBeanFactory beanFactory = new FancyBeanFactory(); 7 | CustomerService customerService = (CustomerService) beanFactory.getBean("customerService"); 8 | customerService.doSomething(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/proxy/CustomerService.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.proxy; 2 | 3 | public class CustomerService { 4 | 5 | public void doSomething(){ 6 | 7 | System.out.println("Do something in CustomerService..."); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/proxy/CustomerServiceProxy.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.proxy; 2 | 3 | public class CustomerServiceProxy extends CustomerService { 4 | 5 | public void doSomething(){ 6 | LoggerAspect loggerAspect = new LoggerAspect(); 7 | loggerAspect.logBefore(); 8 | 9 | super.doSomething(); 10 | 11 | loggerAspect.logAfter(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/proxy/FancyBeanFactory.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.proxy; 2 | 3 | public class FancyBeanFactory { 4 | 5 | public Object getBean(String beanName){ 6 | if("customerService".equals(beanName)) return new CustomerServiceProxy(); 7 | return null; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/proxy/LoggerAspect.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.proxy; 2 | 3 | public class LoggerAspect { 4 | 5 | public void logBefore(){ 6 | System.out.println("Logging before method being executed..."); 7 | } 8 | 9 | public void logAfter(){ 10 | System.out.println("Logging After method being executed==="); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/sequence/AccountService.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.sequence; 2 | 3 | public interface AccountService { 4 | 5 | void deposit(double amount); 6 | } 7 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/sequence/AccountServiceImpl.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.sequence; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class AccountServiceImpl implements AccountService { 7 | public void deposit(double amount) { 8 | System.out.println("Deposit successfully: " + amount); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/sequence/App.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.sequence; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 5 | 6 | public class App { 7 | 8 | public static void main(String[] args){ 9 | ApplicationContext context = new AnnotationConfigApplicationContext(Config.class); 10 | AccountService accountService = context.getBean(AccountService.class); 11 | accountService.deposit(100); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/sequence/Config.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.sequence; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 6 | 7 | @Configuration 8 | @ComponentScan("xing.rujuan.aop.sequence") 9 | @EnableAspectJAutoProxy 10 | public class Config { 11 | } 12 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/sequence/LogAspect1.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.sequence; 2 | 3 | import org.aspectj.lang.annotation.Aspect; 4 | import org.aspectj.lang.annotation.Before; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Aspect 8 | @Component 9 | public class LogAspect1 { 10 | 11 | @Before("execution(* *(..))") 12 | public void log1(){ 13 | System.out.println("Log...1 in LogAspect1....."); 14 | } 15 | 16 | @Before("execution(* *(..))") 17 | public void abc(){ 18 | System.out.println("Log...abc in LogAspect1....."); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/sequence/LogAspect2.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.sequence; 2 | 3 | import org.aspectj.lang.annotation.Aspect; 4 | import org.aspectj.lang.annotation.Before; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Aspect 8 | @Component 9 | public class LogAspect2 { 10 | 11 | @Before("execution(* *(..))") 12 | public void log1(){ 13 | System.out.println("Log...1 in LogAspect2....."); 14 | } 15 | 16 | @Before("execution(* *(..))") 17 | public void zz(){ 18 | System.out.println("Log...zz in LogAspect2....."); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/terms/App.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.terms; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 5 | 6 | public class App { 7 | 8 | public static void main(String[] args){ 9 | ApplicationContext context = new AnnotationConfigApplicationContext(Config.class); 10 | CustomerService customerService = context.getBean(CustomerService.class); 11 | 12 | customerService.doSomething(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/terms/Config.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.terms; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 6 | 7 | @Configuration 8 | @ComponentScan("xing.rujuan.aop.terms") 9 | @EnableAspectJAutoProxy 10 | public class Config { 11 | } 12 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/terms/CustomerService.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.terms; 2 | 3 | public interface CustomerService { 4 | 5 | void doSomething(); 6 | } 7 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/terms/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.terms; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class CustomerServiceImpl implements CustomerService { 7 | 8 | public void doSomething() { 9 | System.out.println("Do Something in CustomerServiceImpl..."); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/terms/LogAspect.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.terms; 2 | 3 | import org.aspectj.lang.annotation.Aspect; 4 | import org.aspectj.lang.annotation.Before; 5 | import org.aspectj.lang.annotation.Pointcut; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Aspect 9 | @Component 10 | public class LogAspect { 11 | 12 | @Before("execution(* *(..))") 13 | public void logBefore(){ 14 | System.out.println("logging before method being executed...."); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/xml/App.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.xml; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | public class App { 8 | 9 | public static void main(String[] args){ 10 | ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); 11 | CustomerService customerService = context.getBean(CustomerService.class); 12 | 13 | customerService.doSomething(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/xml/CustomerService.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.xml; 2 | 3 | public interface CustomerService { 4 | 5 | void doSomething(); 6 | } 7 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/xml/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.xml; 2 | 3 | import org.springframework.stereotype.Component; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class CustomerServiceImpl implements CustomerService { 8 | 9 | public void doSomething() { 10 | System.out.println("Do Something in CustomerServiceImpl..."); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springaop/src/main/java/xing/rujuan/aop/xml/LogAspect.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.aop.xml; 2 | 3 | import org.aspectj.lang.annotation.After; 4 | import org.aspectj.lang.annotation.Aspect; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Aspect 8 | @Component 9 | public class LogAspect { 10 | 11 | @After("execution(* *(..))") 12 | public void logAfter(){ 13 | System.out.println("Logging after method invoked...."); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springaop/src/main/resources/spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /springautowiring/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | xing.rujuan 8 | springautowiring 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | org.springframework 14 | spring-context 15 | 5.2.0.RELEASE 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /springautowiring/src/main/java/xing/rujuan/autowired/AppConfig.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.autowired; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | @Configuration 7 | @ComponentScan("xing.rujuan.autowired") 8 | public class AppConfig { 9 | } 10 | -------------------------------------------------------------------------------- /springautowiring/src/main/java/xing/rujuan/autowired/AppMain.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.autowired; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 5 | 6 | public class AppMain { 7 | public static void main(String[] args) { 8 | ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); 9 | CustomerService customerService = context.getBean("customerService", CustomerService.class); 10 | System.out.println(customerService.getCustomerDao()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springautowiring/src/main/java/xing/rujuan/autowired/CustomerDao.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.autowired; 2 | 3 | public interface CustomerDao { 4 | } 5 | -------------------------------------------------------------------------------- /springautowiring/src/main/java/xing/rujuan/autowired/CustomerDaoImpl.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.autowired; 2 | 3 | import org.springframework.stereotype.Repository; 4 | 5 | @Repository("custDao") 6 | public class CustomerDaoImpl implements CustomerDao { 7 | } 8 | -------------------------------------------------------------------------------- /springautowiring/src/main/java/xing/rujuan/autowired/CustomerDaoImpl2.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.autowired; 2 | 3 | import org.springframework.stereotype.Repository; 4 | 5 | @Repository 6 | public class CustomerDaoImpl2 implements CustomerDao { 7 | } 8 | -------------------------------------------------------------------------------- /springautowiring/src/main/java/xing/rujuan/autowired/CustomerService.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.autowired; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Qualifier; 5 | import org.springframework.stereotype.Service; 6 | 7 | @Service 8 | public class CustomerService { 9 | 10 | // @Autowired(required = false) 11 | @Autowired 12 | @Qualifier("custDao") 13 | private CustomerDao customerDao; 14 | 15 | public CustomerService(){ 16 | System.out.println("default constructor...."); 17 | } 18 | 19 | // @Autowired 20 | public CustomerService(CustomerDao customerDao) { 21 | System.out.println("customized constructor...."); 22 | this.customerDao = customerDao; 23 | } 24 | 25 | public CustomerDao getCustomerDao() { 26 | return customerDao; 27 | } 28 | 29 | // @Autowired 30 | public void setCustomerDao(CustomerDao customerDao) { 31 | System.out.println("setter..."); 32 | this.customerDao = customerDao; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /springautowiring/src/main/java/xing/rujuan/fourtypes/CustomerDao.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.fourtypes; 2 | 3 | public class CustomerDao { 4 | } 5 | -------------------------------------------------------------------------------- /springautowiring/src/main/java/xing/rujuan/fourtypes/CustomerService.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.fourtypes; 2 | 3 | public class CustomerService { 4 | 5 | private CustomerDao customerDao; 6 | 7 | public CustomerService() { 8 | System.out.println("default constructor..."); 9 | } 10 | 11 | public CustomerService(CustomerDao custDao) { 12 | System.out.println("Customized constructor------"); 13 | this.customerDao = custDao; 14 | } 15 | 16 | public CustomerDao getCustomerDao() { 17 | return customerDao; 18 | } 19 | 20 | public void setCustomerDao(CustomerDao customerDao) { 21 | System.out.println("setter...."); 22 | this.customerDao = customerDao; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /springautowiring/src/main/java/xing/rujuan/fourtypes/Main.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.fourtypes; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | public class Main { 7 | 8 | public static void main(String[] args) { 9 | ApplicationContext context = new ClassPathXmlApplicationContext("spring-fourtypes.xml"); 10 | CustomerService customerService = context.getBean("customerService", CustomerService.class); 11 | System.out.println(customerService.getCustomerDao()); 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /springautowiring/src/main/resources/spring-fourtypes.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /springbeanlifecycle/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | xing.rujuan 8 | spring-bean-life-cycle 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | org.springframework 14 | spring-context 15 | 5.2.0.RELEASE 16 | 17 | 18 | javax.annotation 19 | javax.annotation-api 20 | 1.3.2 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /springbeanlifecycle/src/main/java/destruction/Customer.java: -------------------------------------------------------------------------------- 1 | package destruction; 2 | 3 | import org.springframework.beans.factory.DisposableBean; 4 | import org.springframework.context.annotation.Scope; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.annotation.PreDestroy; 8 | 9 | @Component 10 | @Scope("prototype") 11 | public class Customer implements DisposableBean { 12 | 13 | @Override 14 | public void destroy() throws Exception { 15 | System.out.println("DisposableBean destroy....."); 16 | } 17 | 18 | @PreDestroy 19 | public void customDestory(){ 20 | System.out.println("customDestory************"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /springbeanlifecycle/src/main/java/destruction/DestructionMain.java: -------------------------------------------------------------------------------- 1 | package destruction; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.AbstractApplicationContext; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | public class DestructionMain { 8 | 9 | public static void main(String[] args) { 10 | ApplicationContext context = new ClassPathXmlApplicationContext("spring-destruction.xml"); 11 | ((AbstractApplicationContext) context).registerShutdownHook(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /springbeanlifecycle/src/main/java/javaconfig/AppConfig.java: -------------------------------------------------------------------------------- 1 | package javaconfig; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | @ComponentScan("javaconfig") 9 | public class AppConfig { 10 | 11 | @Bean(name="cust", initMethod = "customInit", destroyMethod = "customDestory") 12 | public Customer customer(){ 13 | return new Customer(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springbeanlifecycle/src/main/java/javaconfig/Customer.java: -------------------------------------------------------------------------------- 1 | package javaconfig; 2 | 3 | import org.springframework.beans.factory.DisposableBean; 4 | import org.springframework.context.annotation.Scope; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.annotation.PostConstruct; 8 | import javax.annotation.PreDestroy; 9 | 10 | @Component 11 | public class Customer { 12 | 13 | public Customer() { 14 | System.out.println("Default Constructor......"); 15 | } 16 | 17 | @PostConstruct 18 | public void customInit(){ 19 | System.out.println("Custom init....."); 20 | } 21 | 22 | @PreDestroy 23 | public void customDestory(){ 24 | System.out.println("Custom destory....."); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /springbeanlifecycle/src/main/java/javaconfig/JavaConfigMain.java: -------------------------------------------------------------------------------- 1 | package javaconfig; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 5 | import org.springframework.context.support.AbstractApplicationContext; 6 | 7 | public class JavaConfigMain { 8 | 9 | public static void main(String[] args) { 10 | ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); 11 | 12 | ((AbstractApplicationContext) context).registerShutdownHook(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /springbeanlifecycle/src/main/java/xing/rujuan/Address.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class Address { 7 | } 8 | -------------------------------------------------------------------------------- /springbeanlifecycle/src/main/java/xing/rujuan/CustomBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.config.BeanPostProcessor; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | public class CustomBeanPostProcessor implements BeanPostProcessor { 9 | 10 | @Override 11 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 12 | System.out.println("postProcessBeforeInitialization...." + beanName); 13 | return bean; 14 | } 15 | 16 | @Override 17 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 18 | System.out.println("postProcessAfterInitialization..." + beanName); 19 | return bean; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /springbeanlifecycle/src/main/java/xing/rujuan/Customer.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.BeanFactory; 5 | import org.springframework.beans.factory.BeanFactoryAware; 6 | import org.springframework.beans.factory.BeanNameAware; 7 | import org.springframework.beans.factory.InitializingBean; 8 | import org.springframework.context.ApplicationContext; 9 | import org.springframework.context.ApplicationContextAware; 10 | import org.springframework.stereotype.Component; 11 | 12 | import javax.annotation.PostConstruct; 13 | 14 | @Component("cust") 15 | public class Customer implements BeanNameAware , BeanFactoryAware, ApplicationContextAware, InitializingBean { 16 | 17 | private String firstName; 18 | 19 | public Customer() { 20 | System.out.println("Customer non-arg constructor..."); 21 | } 22 | 23 | public Customer(String firstName) { 24 | System.out.println("Customer First Name constructor..." + firstName); 25 | this.firstName = firstName; 26 | } 27 | 28 | public String getFirstName() { 29 | return firstName; 30 | } 31 | 32 | public void setFirstName(String firstName) { 33 | System.out.println("setFirstName..." + firstName); 34 | this.firstName = firstName; 35 | } 36 | 37 | @Override 38 | public void setBeanName(String s) { 39 | System.out.println("setBeanName...." + s); 40 | } 41 | 42 | @Override 43 | public void setBeanFactory(BeanFactory beanFactory) throws BeansException { 44 | System.out.println("setBeanFactory.." + beanFactory.isSingleton("cust")); 45 | } 46 | 47 | @Override 48 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 49 | System.out.println("setApplicationContext..." + applicationContext.isPrototype("cust")); 50 | this.firstName = "Xing in Application Contxt"; 51 | } 52 | 53 | @Override 54 | public void afterPropertiesSet() throws Exception { 55 | System.out.println("afterPropertiesSet...."); 56 | this.firstName = "Xing in afterPropertiesSet"; 57 | } 58 | 59 | @PostConstruct 60 | public void customInit(){ 61 | System.out.println("customInit...."); 62 | this.firstName = "Xing in customInit"; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /springbeanlifecycle/src/main/java/xing/rujuan/Main.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.support.ClassPathXmlApplicationContext; 5 | 6 | public class Main { 7 | 8 | public static void main(String[] args) { 9 | ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); 10 | String firstName = context.getBean("cust", Customer.class).getFirstName(); 11 | System.out.println("First Name: " + firstName); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /springbeanlifecycle/src/main/resources/spring-destruction.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /springbeanlifecycle/src/main/resources/spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /springbootjspdemo/.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 | -------------------------------------------------------------------------------- /springbootjspdemo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.9.RELEASE 9 | 10 | 11 | xing.rujuan 12 | springbootjspdemo 13 | 0.0.1-SNAPSHOT 14 | jar 15 | springbootjspdemo 16 | Demo project for Spring Boot 17 | 18 | 19 | 1.8 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-tomcat 31 | provided 32 | 33 | 34 | 35 | org.apache.tomcat.embed 36 | tomcat-embed-jasper 37 | provided 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-test 43 | test 44 | 45 | 46 | 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-maven-plugin 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /springbootjspdemo/src/main/java/xing/rujuan/springbootjspdemo/ServletInitializer.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.springbootjspdemo; 2 | 3 | import org.springframework.boot.builder.SpringApplicationBuilder; 4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 5 | 6 | public class ServletInitializer extends SpringBootServletInitializer { 7 | 8 | @Override 9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 10 | return application.sources(SpringbootjspdemoApplication.class); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springbootjspdemo/src/main/java/xing/rujuan/springbootjspdemo/SpringbootjspdemoApplication.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.springbootjspdemo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootjspdemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootjspdemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springbootjspdemo/src/main/java/xing/rujuan/springbootjspdemo/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.springbootjspdemo.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class IndexController { 8 | 9 | @GetMapping("/") 10 | public String index(){ 11 | return "index"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /springbootjspdemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.mvc.view.prefix=/WEB-INF/jsp/ 2 | spring.mvc.view.suffix=.jsp 3 | -------------------------------------------------------------------------------- /springbootjspdemo/src/main/webapp/WEB-INF/jsp/index.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/10/2019 5 | Time: 7:55 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Home 12 | 13 | 14 | Welcome to Spring Boot JSP Setup Demo!!! 15 | 16 | 17 | -------------------------------------------------------------------------------- /springbootjspdemo/src/test/java/xing/rujuan/springbootjspdemo/SpringbootjspdemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.springbootjspdemo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootjspdemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springbootthymeleafdemo/.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 | -------------------------------------------------------------------------------- /springbootthymeleafdemo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.9.RELEASE 9 | 10 | 11 | xing.rujuan 12 | springbootthymeleafdemo 13 | 0.0.1-SNAPSHOT 14 | springbootthymeleafdemo 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-thymeleaf 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /springbootthymeleafdemo/src/main/java/xing/rujuan/springbootthymeleafdemo/SpringbootthymeleafdemoApplication.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.springbootthymeleafdemo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootthymeleafdemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootthymeleafdemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springbootthymeleafdemo/src/main/java/xing/rujuan/springbootthymeleafdemo/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.springbootthymeleafdemo.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class IndexController { 8 | 9 | @GetMapping("/") 10 | public String index(){ 11 | return "index"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /springbootthymeleafdemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8888 2 | -------------------------------------------------------------------------------- /springbootthymeleafdemo/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Index 6 | 7 | 8 | Welcome to Spring boot Thymeleaf setup demo 9 | 10 | -------------------------------------------------------------------------------- /springbootthymeleafdemo/src/test/java/xing/rujuan/springbootthymeleafdemo/SpringbootthymeleafdemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.springbootthymeleafdemo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootthymeleafdemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springcore/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | xing.rujuan 8 | springcore 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | org.springframework 14 | spring-context 15 | 5.2.0.RELEASE 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /springcore/src/main/java/xing/rujuan/EmailService.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan; 2 | 3 | public class EmailService { 4 | 5 | public void sendEmail(String receiver, String message) { 6 | //provide actual logic 7 | System.out.println(message + " is being sent to " + receiver); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /springcore/src/main/java/xing/rujuan/annotation/MyAppConfig.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.annotation; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | @Configuration 7 | @ComponentScan({"xing.rujuan.annotation"}) 8 | public class MyAppConfig { 9 | } 10 | -------------------------------------------------------------------------------- /springcore/src/main/java/xing/rujuan/annotation/MyMain.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.annotation; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | public class MyMain { 8 | public static void main(String[] args) { 9 | // ApplicationContext context = new AnnotationConfigApplicationContext(MyAppConfig.class); 10 | ApplicationContext context = new ClassPathXmlApplicationContext("spring-annotation.xml"); 11 | 12 | SMSService smsService = (SMSService) context.getBean("smsService"); 13 | smsService.sendMessage("test@gmail.com", "Hi"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springcore/src/main/java/xing/rujuan/annotation/SMSService.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.annotation; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component("smsService") 6 | public class SMSService { 7 | 8 | public void sendMessage(String receiver, String message){ 9 | System.out.println(message + " is sent to " + receiver + " by Text message..."); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /springcore/src/main/java/xing/rujuan/config/AppConfig.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Scope; 6 | import xing.rujuan.EmailService; 7 | 8 | @Configuration 9 | public class AppConfig { 10 | 11 | @Bean 12 | public EmailService emailService(){ 13 | return new EmailService(); 14 | } 15 | 16 | @Bean 17 | @Scope("prototype") 18 | public EmailService prototypeEmailService(){ 19 | return new EmailService(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /springcore/src/main/resources/spring-annotation.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /springcore/src/main/resources/spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /springmvcjavaconfig/src/main/java/xing/rujuan/config/DispatcherServletInit.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.config; 2 | 3 | import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; 4 | 5 | public class DispatcherServletInit extends AbstractAnnotationConfigDispatcherServletInitializer { 6 | 7 | @Override 8 | protected Class[] getRootConfigClasses() { 9 | return null; 10 | } 11 | 12 | @Override 13 | protected Class[] getServletConfigClasses() { 14 | return new Class[]{WebApplicationContextConfig.class}; 15 | } 16 | 17 | @Override 18 | protected String[] getServletMappings() { 19 | return new String[]{"/"}; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /springmvcjavaconfig/src/main/java/xing/rujuan/config/WebApplicationContextConfig.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.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 | 10 | @Configuration 11 | @EnableWebMvc 12 | @ComponentScan("xing.rujuan") 13 | public class WebApplicationContextConfig implements WebMvcConfigurer { 14 | 15 | @Bean 16 | public InternalResourceViewResolver getInternalResourceViewResolver(){ 17 | InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); 18 | viewResolver.setPrefix("/WEB-INF/jsp/"); 19 | viewResolver.setSuffix(".jsp"); 20 | return viewResolver; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /springmvcjavaconfig/src/main/java/xing/rujuan/controller/ProductController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.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 xing.rujuan.model.Category; 8 | import xing.rujuan.model.Product; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | @Controller 14 | public class ProductController { 15 | 16 | @GetMapping("/getProductForm") 17 | public String getProductForm(@ModelAttribute("prod") Product product, Model model){ 18 | // model.addAttribute("categoryList", Arrays.asList( 19 | // new Category(1, "Computer"), 20 | // new Category(2, "Laptop") 21 | // )); 22 | // model.addAttribute("prod", new Product()); 23 | System.out.println("Inside getProductForm()...."); 24 | System.out.println(model.asMap().get("categoryList")); 25 | return "productForm"; 26 | } 27 | 28 | @GetMapping("/a") 29 | public String getA(Model model){ 30 | // model.addAttribute("categoryList", Arrays.asList( 31 | // new Category(1, "Computer"), 32 | // new Category(2, "Laptop") 33 | // )); 34 | System.out.println("Inside getA()...."); 35 | System.out.println(model.asMap().get("categoryList")); 36 | return "productForm"; 37 | } 38 | 39 | @GetMapping("/b") 40 | public String getB(Model model){ 41 | // model.addAttribute("categoryList", Arrays.asList( 42 | // new Category(1, "Computer"), 43 | // new Category(2, "Laptop") 44 | // )); 45 | System.out.println("Inside getB()...."); 46 | System.out.println(model.asMap().get("categoryList")); 47 | return "productForm"; 48 | } 49 | 50 | @ModelAttribute("categoryList") 51 | public List getCategoryList(){ 52 | return Arrays.asList( 53 | new Category(1, "Computer"), 54 | new Category(2, "Laptop") 55 | ); 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /springmvcjavaconfig/src/main/java/xing/rujuan/controller/WelcomeController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | @Controller 7 | public class WelcomeController { 8 | 9 | @RequestMapping("/") 10 | public String welcome(){ 11 | return "welcome"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /springmvcjavaconfig/src/main/java/xing/rujuan/model/Category.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.model; 2 | 3 | public class Category { 4 | 5 | private int id; 6 | private String name; 7 | 8 | public Category() { 9 | } 10 | 11 | public Category(int id, String name) { 12 | this.id = id; 13 | this.name = name; 14 | } 15 | 16 | public int getId() { 17 | return id; 18 | } 19 | 20 | public void setId(int id) { 21 | this.id = id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "Category{" + 35 | "id=" + id + 36 | ", name='" + name + '\'' + 37 | '}'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /springmvcjavaconfig/src/main/java/xing/rujuan/model/Product.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.model; 2 | 3 | public class Product { 4 | 5 | private String name = "Default Name"; 6 | private double price = 10.0; 7 | 8 | public String getName() { 9 | return name; 10 | } 11 | 12 | public void setName(String name) { 13 | this.name = name; 14 | } 15 | 16 | public double getPrice() { 17 | return price; 18 | } 19 | 20 | public void setPrice(double price) { 21 | this.price = price; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "Product{" + 27 | "name='" + name + '\'' + 28 | ", price=" + price + 29 | '}'; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /springmvcjavaconfig/src/main/webapp/WEB-INF/jsp/productForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/2/2019 5 | Time: 5:29 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Product Form 12 | 13 | 14 |

Product Name: ${prod.name}

15 |

Product price: ${prod.price}

16 | 17 | 18 | -------------------------------------------------------------------------------- /springmvcjavaconfig/src/main/webapp/WEB-INF/jsp/welcome.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/1/2019 5 | Time: 5:34 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Welcome 12 | 13 | 14 | 15 |

Welcome to my channel - Miss Xing

16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /springmvcxml/src/main/java/xing/rujuan/ProductController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | @Controller 7 | @RequestMapping("/product") 8 | public class ProductController { 9 | 10 | 11 | //http://localhost:8080/product/listProducts?categoryId=1&categoryName=computer 12 | @GetMapping("/listProducts") 13 | public String getProductByCategory(@RequestParam Integer categoryId, 14 | @RequestParam(value = "categoryName", required = false, defaultValue = "laptop") String name) { 15 | System.out.println("Id: " + categoryId + " , Name: " + name); 16 | return "welcome"; 17 | } 18 | 19 | //http://localhost:8080/product/categoryId/2/categoryName/computer 20 | @GetMapping("categoryId/{cateid}/categoryName/{cateName}") 21 | public String getProducts(@PathVariable String cateid, @PathVariable("cateName") String name){ 22 | System.out.println("cateId: " + cateid + " , cateName: " + name); 23 | return "welcome"; 24 | } 25 | 26 | @PostMapping("/save") 27 | public String saveProduct() { 28 | return "welcome"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /springmvcxml/src/main/java/xing/rujuan/SignUpController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan; 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.PostMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import xing.rujuan.model.User; 10 | 11 | 12 | @Controller 13 | @RequestMapping(value={"/user"}) 14 | public class SignUpController { 15 | 16 | // @RequestMapping(value = "/signup", method = RequestMethod.GET) 17 | @GetMapping({"/", "/signup"}) 18 | public String getSignUpForm() { 19 | return "SignUpForm"; 20 | } 21 | 22 | // @RequestMapping(value = "/signup", method = RequestMethod.POST) 23 | @PostMapping("/signup") 24 | public String saveUser(User user, Model model) { 25 | System.out.println(user); 26 | return "result"; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /springmvcxml/src/main/java/xing/rujuan/WelcomeController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | @Controller 8 | public class WelcomeController { 9 | 10 | @RequestMapping("/") 11 | public String welcome(){ 12 | return "welcome"; 13 | } 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springmvcxml/src/main/java/xing/rujuan/model/Address.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.model; 2 | 3 | public class Address { 4 | 5 | private String street; 6 | private Integer zipcode; 7 | 8 | public String getStreet() { 9 | return street; 10 | } 11 | 12 | public void setStreet(String street) { 13 | this.street = street; 14 | } 15 | 16 | public Integer getZipcode() { 17 | return zipcode; 18 | } 19 | 20 | public void setZipcode(Integer zipcode) { 21 | this.zipcode = zipcode; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "Address{" + 27 | "street='" + street + '\'' + 28 | ", zipcode=" + zipcode + 29 | '}'; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /springmvcxml/src/main/java/xing/rujuan/model/User.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.model; 2 | 3 | public class User { 4 | 5 | private String firstName; 6 | private String lastName; 7 | 8 | private Address address; 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 Address getAddress() { 27 | return address; 28 | } 29 | 30 | public void setAddress(Address address) { 31 | this.address = address; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "User{" + 37 | "firstName='" + firstName + '\'' + 38 | ", lastName='" + lastName + '\'' + 39 | ", address=" + address + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /springmvcxml/src/main/webapp/WEB-INF/config/springmvc-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /springmvcxml/src/main/webapp/WEB-INF/jsp/SignUpForm.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/1/2019 5 | Time: 7:35 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Sign Up Form 12 | 13 | 14 | 15 |
16 |

First Name:

17 |

Last Name:

18 |

Address:

19 | 20 |

Street:

21 |

ZipCode:

22 | 23 |
24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /springmvcxml/src/main/webapp/WEB-INF/jsp/result.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/1/2019 5 | Time: 7:40 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Signup Successfully 12 | 13 | 14 |

Congrats, you Signup Successfully...

15 | 16 | 17 | -------------------------------------------------------------------------------- /springmvcxml/src/main/webapp/WEB-INF/jsp/welcome.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: rXing 4 | Date: 10/1/2019 5 | Time: 4:56 PM 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | Welcome 12 | 13 | 14 |

Welcome to my channel - Miss Xing

15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /springmvcxml/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | DispatcherServlet 8 | org.springframework.web.servlet.DispatcherServlet 9 | 10 | 11 | contextConfigLocation 12 | /WEB-INF/config/springmvc-config.xml 13 | 14 | 15 | 16 | 17 | 18 | DispatcherServlet 19 | / 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /thymeleaf-layout-hierarchical-style/.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 | -------------------------------------------------------------------------------- /thymeleaf-layout-hierarchical-style/src/main/java/xing/rujuan/thymeleaflayouthierarchicalstyle/ThymeleafLayoutHierarchicalStyleApplication.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.thymeleaflayouthierarchicalstyle; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ThymeleafLayoutHierarchicalStyleApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ThymeleafLayoutHierarchicalStyleApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /thymeleaf-layout-hierarchical-style/src/main/java/xing/rujuan/thymeleaflayouthierarchicalstyle/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.thymeleaflayouthierarchicalstyle.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class IndexController { 8 | 9 | @GetMapping("/") 10 | public String index(){ 11 | return "index"; 12 | } 13 | 14 | 15 | @GetMapping("/user") 16 | public String user(){ 17 | return "user"; 18 | } 19 | 20 | @GetMapping("/admin/index") 21 | public String admin(){ 22 | return "admin/index"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /thymeleaf-layout-hierarchical-style/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /thymeleaf-layout-hierarchical-style/src/main/resources/static/css/cover.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Globals 3 | */ 4 | 5 | /* Links */ 6 | a, 7 | a:focus, 8 | a:hover { 9 | color: #fff; 10 | } 11 | 12 | /* Custom default button */ 13 | .btn-secondary, 14 | .btn-secondary:hover, 15 | .btn-secondary:focus { 16 | color: #333; 17 | text-shadow: none; /* Prevent inheritance from `body` */ 18 | background-color: #fff; 19 | border: .05rem solid #fff; 20 | } 21 | 22 | 23 | /* 24 | * Base structure 25 | */ 26 | 27 | html, 28 | body { 29 | height: 100%; 30 | background-color: #333; 31 | } 32 | 33 | body { 34 | display: -ms-flexbox; 35 | display: -webkit-box; 36 | display: flex; 37 | -ms-flex-pack: center; 38 | -webkit-box-pack: center; 39 | justify-content: center; 40 | color: #fff; 41 | text-shadow: 0 .05rem .1rem rgba(0, 0, 0, .5); 42 | box-shadow: inset 0 0 5rem rgba(0, 0, 0, .5); 43 | } 44 | 45 | .cover-container { 46 | max-width: 42em; 47 | } 48 | 49 | 50 | /* 51 | * Header 52 | */ 53 | .masthead { 54 | margin-bottom: 2rem; 55 | } 56 | 57 | .masthead-brand { 58 | margin-bottom: 0; 59 | } 60 | 61 | .nav-masthead .nav-link { 62 | padding: .25rem 0; 63 | font-weight: 700; 64 | color: rgba(255, 255, 255, .5); 65 | background-color: transparent; 66 | border-bottom: .25rem solid transparent; 67 | } 68 | 69 | .nav-masthead .nav-link:hover, 70 | .nav-masthead .nav-link:focus { 71 | border-bottom-color: rgba(255, 255, 255, .25); 72 | } 73 | 74 | .nav-masthead .nav-link + .nav-link { 75 | margin-left: 1rem; 76 | } 77 | 78 | .nav-masthead .active { 79 | color: #fff; 80 | border-bottom-color: #fff; 81 | } 82 | 83 | @media (min-width: 48em) { 84 | .masthead-brand { 85 | float: left; 86 | } 87 | .nav-masthead { 88 | float: right; 89 | } 90 | } 91 | 92 | 93 | /* 94 | * Cover 95 | */ 96 | .cover { 97 | padding: 0 1.5rem; 98 | } 99 | .cover .btn-lg { 100 | padding: .75rem 1.25rem; 101 | font-weight: 700; 102 | } 103 | 104 | 105 | /* 106 | * Footer 107 | */ 108 | .mastfoot { 109 | color: rgba(255, 255, 255, .5); 110 | } 111 | -------------------------------------------------------------------------------- /thymeleaf-layout-hierarchical-style/src/main/resources/templates/admin/index.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Admin Page 7 | 8 | 9 |
10 |

Welcome to our ADMIN index Page$$$$$$$$$

11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /thymeleaf-layout-hierarchical-style/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | Index Page 8 | 9 | 10 |
11 |

Welcome to our Home Page.....

12 |
13 | 14 | 15 | -------------------------------------------------------------------------------- /thymeleaf-layout-hierarchical-style/src/main/resources/templates/page_layout/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /thymeleaf-layout-hierarchical-style/src/main/resources/templates/page_layout/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 |
9 |
10 |

Cover

11 | 16 |
17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /thymeleaf-layout-hierarchical-style/src/main/resources/templates/page_layout/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Layout Title 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 |
28 |
29 |

Cover

30 | 33 |
34 |
35 | 36 |
37 |

This main content will be decorated by the actual page returned in the controller methods.

38 |
39 | 40 |
41 |
42 | footer here will be replaced 43 |
44 |
45 |
46 | 47 | 48 | -------------------------------------------------------------------------------- /thymeleaf-layout-hierarchical-style/src/main/resources/templates/user.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | User Page 7 | 8 | 9 |
10 |

Welcome to our User Page*******

11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /thymeleaf-layout-hierarchical-style/src/test/java/xing/rujuan/thymeleaflayouthierarchicalstyle/ThymeleafLayoutHierarchicalStyleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.thymeleaflayouthierarchicalstyle; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ThymeleafLayoutHierarchicalStyleApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /thymeleaf-layout-include-style/.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 | -------------------------------------------------------------------------------- /thymeleaf-layout-include-style/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.0.RELEASE 9 | 10 | 11 | xing.rujuan 12 | thymeleaf-layout-include-style 13 | 0.0.1-SNAPSHOT 14 | thymeleaf-layout-include-style 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-thymeleaf 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-devtools 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-test 38 | test 39 | 40 | 41 | org.junit.vintage 42 | junit-vintage-engine 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-maven-plugin 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /thymeleaf-layout-include-style/src/main/java/xing/rujuan/thymeleaflayoutincludestyle/ThymeleafLayoutIncludeStyleApplication.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.thymeleaflayoutincludestyle; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ThymeleafLayoutIncludeStyleApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ThymeleafLayoutIncludeStyleApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /thymeleaf-layout-include-style/src/main/java/xing/rujuan/thymeleaflayoutincludestyle/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.thymeleaflayoutincludestyle.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class IndexController { 8 | 9 | @GetMapping("/") 10 | public String index(){ 11 | return "index"; 12 | } 13 | 14 | 15 | @GetMapping("/user") 16 | public String user(){ 17 | return "user"; 18 | } 19 | 20 | @GetMapping("/admin/index") 21 | public String admin(){ 22 | return "admin"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /thymeleaf-layout-include-style/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /thymeleaf-layout-include-style/src/main/resources/static/css/cover.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Globals 3 | */ 4 | 5 | /* Links */ 6 | a, 7 | a:focus, 8 | a:hover { 9 | color: #fff; 10 | } 11 | 12 | /* Custom default button */ 13 | .btn-secondary, 14 | .btn-secondary:hover, 15 | .btn-secondary:focus { 16 | color: #333; 17 | text-shadow: none; /* Prevent inheritance from `body` */ 18 | background-color: #fff; 19 | border: .05rem solid #fff; 20 | } 21 | 22 | 23 | /* 24 | * Base structure 25 | */ 26 | 27 | html, 28 | body { 29 | height: 100%; 30 | background-color: #333; 31 | } 32 | 33 | body { 34 | display: -ms-flexbox; 35 | display: -webkit-box; 36 | display: flex; 37 | -ms-flex-pack: center; 38 | -webkit-box-pack: center; 39 | justify-content: center; 40 | color: #fff; 41 | text-shadow: 0 .05rem .1rem rgba(0, 0, 0, .5); 42 | box-shadow: inset 0 0 5rem rgba(0, 0, 0, .5); 43 | } 44 | 45 | .cover-container { 46 | max-width: 42em; 47 | } 48 | 49 | 50 | /* 51 | * Header 52 | */ 53 | .masthead { 54 | margin-bottom: 2rem; 55 | } 56 | 57 | .masthead-brand { 58 | margin-bottom: 0; 59 | } 60 | 61 | .nav-masthead .nav-link { 62 | padding: .25rem 0; 63 | font-weight: 700; 64 | color: rgba(255, 255, 255, .5); 65 | background-color: transparent; 66 | border-bottom: .25rem solid transparent; 67 | } 68 | 69 | .nav-masthead .nav-link:hover, 70 | .nav-masthead .nav-link:focus { 71 | border-bottom-color: rgba(255, 255, 255, .25); 72 | } 73 | 74 | .nav-masthead .nav-link + .nav-link { 75 | margin-left: 1rem; 76 | } 77 | 78 | .nav-masthead .active { 79 | color: #fff; 80 | border-bottom-color: #fff; 81 | } 82 | 83 | @media (min-width: 48em) { 84 | .masthead-brand { 85 | float: left; 86 | } 87 | .nav-masthead { 88 | float: right; 89 | } 90 | } 91 | 92 | 93 | /* 94 | * Cover 95 | */ 96 | .cover { 97 | padding: 0 1.5rem; 98 | } 99 | .cover .btn-lg { 100 | padding: .75rem 1.25rem; 101 | font-weight: 700; 102 | } 103 | 104 | 105 | /* 106 | * Footer 107 | */ 108 | .mastfoot { 109 | color: rgba(255, 255, 255, .5); 110 | } 111 | -------------------------------------------------------------------------------- /thymeleaf-layout-include-style/src/main/resources/templates/commoncomponents.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Shared Components 6 | 7 | 8 | 9 |
10 |
11 |

My Cover Header

12 | 18 |
19 |
20 | 21 | 22 | 23 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /thymeleaf-layout-include-style/src/main/resources/templates/fragments/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Footer Component 6 | 7 | 8 | 9 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /thymeleaf-layout-include-style/src/main/resources/templates/fragments/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Header Component 6 | 7 | 8 | 9 |
10 |
11 |

Fragment herder.html Cover Header

12 | 18 |
19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /thymeleaf-layout-include-style/src/main/resources/templates/user.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Cover Template for Bootstrap 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 |
27 | 28 |
29 |

User Info

30 |

Main message for User

31 |

32 | Learn more 33 |

34 |
35 | 36 |
37 | 38 |
39 |
40 | 41 | 42 | -------------------------------------------------------------------------------- /thymeleaf-layout-include-style/src/test/java/xing/rujuan/thymeleaflayoutincludestyle/ThymeleafLayoutIncludeStyleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.thymeleaflayoutincludestyle; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ThymeleafLayoutIncludeStyleApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/.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 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.9.RELEASE 9 | 10 | 11 | xing.rujuan 12 | thymeleafexpressionsyntax 13 | 0.0.1-SNAPSHOT 14 | thymeleafexpressionsyntax 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-thymeleaf 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/src/main/java/xing/rujuan/thymeleafexpressionsyntax/ThymeleafexpressionsyntaxApplication.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.thymeleafexpressionsyntax; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ThymeleafexpressionsyntaxApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ThymeleafexpressionsyntaxApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/src/main/java/xing/rujuan/thymeleafexpressionsyntax/controller/ConditionalExpression.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.thymeleafexpressionsyntax.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import xing.rujuan.thymeleafexpressionsyntax.domain.Address; 7 | import xing.rujuan.thymeleafexpressionsyntax.domain.Person; 8 | 9 | @Controller 10 | public class ConditionalExpression { 11 | 12 | @GetMapping("/conditionalExpression") 13 | public String simpleExpression(Model model){ 14 | Address address = new Address("1000 N 10th ST", "52556"); 15 | Person tina1 = new Person(1, "Miss Xing", address); 16 | Person tina2 = new Person(2, "Rujuan Xing", null); 17 | model.addAttribute("person1", tina1); 18 | model.addAttribute("person2", tina2); 19 | 20 | model.addAttribute("gender", "M"); 21 | return "conditionalExpression"; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/src/main/java/xing/rujuan/thymeleafexpressionsyntax/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.thymeleafexpressionsyntax.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class IndexController { 8 | 9 | @GetMapping("/") 10 | public String index(){ 11 | return "index"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/src/main/java/xing/rujuan/thymeleafexpressionsyntax/controller/IterationExpressionController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.thymeleafexpressionsyntax.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import xing.rujuan.thymeleafexpressionsyntax.domain.Person; 7 | 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | @Controller 12 | public class IterationExpressionController { 13 | 14 | @GetMapping("/iterationExpression") 15 | public String iterationExpression(Model model){ 16 | List people = Arrays.asList( 17 | new Person(91, "Josh"), 18 | new Person(92, "Mary"), 19 | new Person(93, "Elsa") 20 | ); 21 | model.addAttribute("people", people); 22 | return "iterationExpression"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/src/main/java/xing/rujuan/thymeleafexpressionsyntax/controller/SimpleExpressionController.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.thymeleafexpressionsyntax.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import xing.rujuan.thymeleafexpressionsyntax.domain.Address; 7 | import xing.rujuan.thymeleafexpressionsyntax.domain.Person; 8 | 9 | @Controller 10 | public class SimpleExpressionController { 11 | 12 | @GetMapping("/simpleExpression") 13 | public String simpleExpression(Model model){ 14 | Address address = new Address("1000 N 10th ST", "52556"); 15 | Person tina = new Person(1, "Miss Xing", address); 16 | model.addAttribute("person", tina); 17 | return "simpleExpression"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/src/main/java/xing/rujuan/thymeleafexpressionsyntax/domain/Address.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.thymeleafexpressionsyntax.domain; 2 | 3 | public class Address { 4 | 5 | private String street; 6 | private String zipCode; 7 | 8 | public Address() { 9 | } 10 | 11 | public Address(String street, String zipCode) { 12 | this.street = street; 13 | this.zipCode = zipCode; 14 | } 15 | 16 | public String getStreet() { 17 | return street; 18 | } 19 | 20 | public void setStreet(String street) { 21 | this.street = street; 22 | } 23 | 24 | public String getZipCode() { 25 | return zipCode; 26 | } 27 | 28 | public void setZipCode(String zipCode) { 29 | this.zipCode = zipCode; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/src/main/java/xing/rujuan/thymeleafexpressionsyntax/domain/Person.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.thymeleafexpressionsyntax.domain; 2 | 3 | public class Person { 4 | 5 | private Integer id; 6 | private String name; 7 | 8 | private Address address; 9 | 10 | public Person() { 11 | } 12 | 13 | public Person(Integer id, String name) { 14 | this.id = id; 15 | this.name = name; 16 | } 17 | 18 | public Person(Integer id, String name, Address address) { 19 | this.id = id; 20 | this.name = name; 21 | this.address = address; 22 | } 23 | 24 | public Integer getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Integer id) { 29 | this.id = id; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public Address getAddress() { 41 | return address; 42 | } 43 | 44 | public void setAddress(Address address) { 45 | this.address = address; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/src/main/resources/messages.properties: -------------------------------------------------------------------------------- 1 | channel.name=Miss Xing 2 | project.name=Thymeleaf Standard Expression Syntax -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/src/main/resources/templates/conditionalExpression.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 |

Conditional Expression

9 |

If-then

10 |

Default person1 Street

11 |

Default person2 Street

12 | 13 |

If-then-else

14 |

Default Zipcode 1

15 |

Default Zipcode 2

16 | 17 |

Elvis Operator

18 |

Default address1

19 |

Default address2

20 | 21 |

If-Unless

22 |

Female

23 |

Male

24 | 25 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Index 6 | 7 | 8 |

Simple Expression

9 |

Conditional Expression

10 |

Iteration Expression

11 | 12 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/src/main/resources/templates/iterationExpression.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Iteration Expression 6 | 8 | 9 | 10 |
11 |

Iteration Expression

12 |

Without Index

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
#IDName
11Otto
30 | 31 |

Without Index - Version 1

32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
#IDName
11Otto
49 | 50 |

Without Index - Version 2

51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 |
#IDName
11Otto
68 |
69 | 70 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/src/main/resources/templates/simpleExpression.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Simple Expression 6 | 7 | 8 |

Simple Expression

9 |

Variable Expression

10 |

ID: 0

11 |

Name: Tina

12 |

Address

13 |

Street: 1234 Burlington Ave

14 |

Zipcode: 1234567890

15 | 16 |

Selection Variable expression

17 |
18 |

ID: 0

19 |

Name: Tina

20 |

Address

21 |

Street: 1234 Burlington Ave

22 |

Zipcode: 1234567890

23 |
24 | 25 |

Message Expression

26 |

Default Channel Name

27 |

Default Project Name

28 | 29 |

Link URL Expression

30 |

Link 1

31 | 32 |

Query String URL

33 | 34 |

Path Variable URL

35 | 36 | -------------------------------------------------------------------------------- /thymeleafexpressionsyntax/src/test/java/xing/rujuan/thymeleafexpressionsyntax/ThymeleafexpressionsyntaxApplicationTests.java: -------------------------------------------------------------------------------- 1 | package xing.rujuan.thymeleafexpressionsyntax; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ThymeleafexpressionsyntaxApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------