MindMap Gallery Spring mind map
This detailed mind map explores the theme of springtime, detailing beans, annotations, and static resources, and further expanding to models and object-relational mapping. The mind map presents central ideas and issues in a radial layout, similar to the neural network structure of the human brain. This visual method effectively enhances memory, organizes information, and promotes creative thinking.
Edited at 2023-03-01 04:34:52Spring
Bean
là một đối tượng dùng để đóng gói dữ liệu
loại
singleton
prototype
request
secssion and global secssion
constructor
setter
dependence injection
Dependence Injection
AutoWire:tự động tìm bean và gán
byName
byType
constructor
autodetect
Inject: thông qua gán bean trực tiếp class cho biến
mangaged by IOC container
Spring
RequestMapping
value = {}: để cho phép nhiều đường dẫn
method = requestMethod.methodName: dùng để hạn chế các quyền truy cập
có 2 cách để ReqestMapping
RequestMapping ở đầu trang
@RequestMapping("/admin) ở ngay đầu trang thì nó chỉ cho phép các đường dẫn mà có /admin
/admin/hello
thuộc tính produces
dùng để ánh xạ đến Accept của Request, nói cách khác để quy định kiểu context type
Annotation
@RequestParam(name="id", required = true) int id
name tên của param
required: yêu cầu đường dẫn gửi lên từ client, có hoặc không
khái niệm: dùng để lấy giá trị từ thanh url sau giấu chẩm hỏi . vd: /student?action=delete
@PathVarible
dùng để lấy giá trị từ thanh url tương tự nhưng RequestParam, nhưng nó ở sau giấu/
ví dụ: @GetMapping("/pet/{petId}" do đó khi bạn nhập đường dẫn vào trình duyệt phải khai báo giá trị cho petId: /pet/6/
muốn dùng giá trị đó thì phải @PathVarible Int id,
@Component
cho phép một class được tạo ra là một cái bean
muốn sử dụng nó thì phải sử dụng <context: component-scan..gì đó trong web.xml
@ComponentScan dùng để kiểm tra Component
@Service
dùng để đánh dấu một class thuộc tầng service
@Component
dùng để đánh dấu một class dùng để xử lý các request
@Repository
cái này sẽ truy cập vào database, và thực hiện tất cả các hoạt động liên quan tới database
Static Resources
Subtopic
DispartcherServlet
overview
Subtopic
concept
acts as a front controller for Spring-based applications, it handles all requirements and responses.
3 ways to config
in web.xml
<servlet> <!-- Provide a Servlet Name --> <servlet-name>frontcontroller-dispatcher</servlet-name> <!-- Provide a fully qualified path to the DispatcherServelt class --> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet>
<servlet-mapping> <!-- Provide a Servlet Name that you want to map --> <servlet-name>frontcontroller-dispatcher</servlet-name> <!-- Provide a url pattern --> <url-pattern>/gfg.com/*</url-pattern> </servlet-mapping>
<load-on-startup>1</load-on-startup>
to make sure that dispartcher will get started when the server startup.
webApplicationInitializer
// Java Program to Illustrate // CalculatorApplicationInitializer Class package com.geeksforgeeks.calculator.config; // Importing required classes import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration; import org.springframework.web.WebApplicationInitializer; import org.springframework.web.context.support.XmlWebApplicationContext; import org.springframework.web.servlet.DispatcherServlet; // Class public class CalculatorApplicationInitializer implements WebApplicationInitializer { // Method public void onStartup(ServletContext servletContext) throws ServletException { XmlWebApplicationContext webApplicationContext = new XmlWebApplicationContext(); // Putting the spring configuration XML file webApplicationContext.setConfigLocation( "classpath:application-config.xml"); // Creating a dispatcher servlet object DispatcherServlet dispatcherServlet = new DispatcherServlet(webApplicationContext); // Registering Dispatcher Servlet // with Servlet Context ServletRegistration .Dynamic myCustomDispatcherServlet = servletContext.addServlet( "myDispatcherServlet", dispatcherServlet); // Setting load on startup myCustomDispatcherServlet.setLoadOnStartup(1); // Adding mapping URL myCustomDispatcherServlet.addMapping("/gfg.com/*"); } }
AbstractAnnotationConfigDispatcherServletInitializer
// Java Program to Demonstrate CalculatorAppInitializer Class package com.geeksforgeeks.calculator.config; // Importing required classes import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; // Class public class CalculatorAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { // Method @Override protected Class<?>[] getRootConfigClasses() { return null; } // Method @Override protected Class<?>[] getServletConfigClasses() { return aClass; } // Method @Override protected String[] getServletMappings() { return arr; } }
more infor
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- The definition of the Root Spring Container shared by all Servlets and Filters --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/root-context.xml</param-value> </context-param> <!-- Creates the Spring Container shared by all Servlets and Filters --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- Processes application requests --> <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
reference
https://huongdanjava.com/vi/khoi-tao-va-cau-hinh-dispatcherservlet-trong-spring-mvc.html
so sánh giữa 2 cách config
Subtopic
ViewResolver
là cơ chế để xử lý tầng view của spring MVC
ánh xạ tên của view sang đối tượng view tương úng
là bộ phận quyết dịnh Front Controller sẽ trả về view thực tế nào
Form-Databinding
databinding là một cơ chế liên kết dữ liệu đầu vào hoặc đầu ra với các đối tượng model .
Form
dùng để tạo một form
comandName, ModelAtribute
đều dụng để thao tác với Mode, trong khi dố Name là cách cũ, Model là cách mới
Thư viện form.tld
hỗ trợ nhiểu tiện ích như option, passworkd....
path, iterms
path dùng để liên kết với trường hiện tại
iterms dùng để liệt kê các danh sách hạng mục các trường
@ModelAtribute
dùng nó đẻ ràng buộc tham số hoặc kết quả thành một Model attribute cụ thể..
OOM (Object-relational Mapping)
concept
là một kỹ thuật liên kết các đối tượng trong lập trình với các đối tượng trong cơ sở dũ liểu.
pros and cons