siye@r480:~/svlution/workspace/springmvc4322$ tree src/
src/
├── main
│ ├── java
│ │ ├── log4j.properties
│ │ └── ocn
│ │ └── site
│ │ └── springmvc
│ │ ├── controller
│ │ │ └── Manicontroller.java
│ │ ├── domain
│ │ │ └── User.java
│ │ ├── setup
│ │ │ ├── Appconfig.java
│ │ │ └── Webxmlconfig.java
│ │ └── validator
│ │ └── ValidatorImpl.java
│ ├── resources
│ └── webapp
│ ├── index.jsp
│ └── WEB-INF
│ ├── register.jsp
│ ├── success.jsp
│ └── web.xml
└── test
├── java
│ └── ocn
│ └── site
│ └── springmvc
│ └── controller
│ └── Runtest.java
└── resources
└── config
└── application.xml
20 directories, 12 files
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.22.RELEASE</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.22.RELEASE</version>
<scope>test</scope>
</dependency>
package ocn.site.springmvc.controller;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.context.request.WebRequest;
import ocn.site.springmvc.domain.User;
import ocn.site.springmvc.validator.ValidatorImpl;
@Controller
public class Manicontroller {
private final Logger logger = Logger.getLogger(this.getClass());
private @Autowired User user;
private @Autowired ValidatorImpl validatorImpl;
private final static String NAME_SUCCESS = "success";
private final static String NAME_REGISTER = "register";
@InitBinder
public void handlerInit(WebDataBinder binder, WebRequest request) {
binder.addValidators(validatorImpl);
logger.info("config validator success");
}
@ModelAttribute
public void handlerConfig(ModelMap map) {
map.addAttribute("user", user);
logger.info("first config success");
}
@GetMapping("/test")
public String handlerPage() {
return NAME_REGISTER