2022年7月31日 星期日

Spring MVC

 

# Model, View, Controller

# Frontend controller (DispatcherServlet), Model,

# Controller (business logic, handle request, store/ retrieve data, place data in model),

# Model, View Template (JSP + JSP standard tag library)

 

# configure web.xml

Ø  Configure spring MVC dispatcher servlet

n   contextConfigLocation

Ø  Setup URL mapping to Spring MVC Dispatcher Servlet

 

# configure contextConfigLocation

Ø  Add support for Spring component scanning

Ø  Add support for conversion, formatting and validation

Ø  Configure Spring MVC View Resolver

 

# Develop Process

Ø  Create Controller class

Ø  Define Controller method

Ø  Add Request Mapping to Controller method

Ø  Return view name

Ø  Develop view page

Ø   

 

 

Annotation

@RequestParam (Bind it to the variable)

@RequestMapping

Ø  RequestMapping to controller ( serves as parent mapping for controller)

 

Spring MVC Form Tag

Ø  Building block for a web page

Ø  Make use of data binding

Ø  Automatically setting / retrieving data from java object

Ø  Define taglib (tag library)

 

Get request < controller receive (create model ) for return model to jsp

# this model is bind a object

 

@ModelAttribute(“student”)

 

@Valid ( perform validation rules on this customer object)

 

@InitBinder = pre-process all web request coming into our controller

Ø  StringTrimmerEditor = remove whitespace – leading and trailing

 

# Custom Validation

@ Create custom java annotation from scratch

Ø  @CourseCode

Ø  1. Create custom validation rule

Ø  >Create @CourseCode annotation

n   @Constraint(validatedBy = CourseCodeConstraintValidator.class)

n   @Target

n   @Retention

n   @interface CourseCode

Ø  >CreateCourseCodeConstraintValidator


 

沒有留言:

張貼留言

IT Knowledge Map

https://docs.google.com/spreadsheets/d/1ZmN7G1unUAEpTPp5ObDnlAUtILLwwvluy-KHumMPEUU/edit#gid=0