Java Novice Learning Guide [day33]---JavaBean&EL&JSTL&MVC thinking

1、JavaBean

JavaBean is a special class, or a class that meets certain specifications; it can be reused, reducing code redundancy, and facilitating maintenance.

1. Specifications to be met:

  • Must have a package;-Programming standards/good programming habits
  • Must be concrete and public; – maximum access rights, non-abstract
  • There must be a public and non-parameter structure;-It is convenient for the framework or the bottom layer to create objects through reflection
  • There must be corresponding public setter and getter methods;-It is convenient to set and get properties/el expressions
  • Privatization of object fields;-control direct manipulation of object fields

2. Note :

In JavaBean: getter and setter are called attributes, get: readable attributes set: writable attributes

At the same time, fields and attributes are not necessarily related

3. Use beanutils to copy properties

		//导包:beanutils,collections:集合的扩展功能 ,logging:日志包
		BeanUtils.copyProperties(stu02, stu01); 
		//意思是把01的属性拷备给02
		//可以是不同类的对象,也可以把map的值拷备给对象

2. EL expression

1. Writing method: ${ key}

It will find the value corresponding to the key from the four scopes in turn. If the key does not exist, it will be displayed as an empty string instead of the null value (good experience);

2. The order of values ​​in the four scopes

Order (from small to large): page -> request -> session -> application

Note: When the scope names are the same, the display order is from small to large, and the problem of duplicating names should be avoided.

3. ${pageContext.request.contextPath} can get the context path. If the path path is configured in server.xml-it is best to use this method to specify the absolute path;

3. JSTL tags (jsp standard tag library)

Guide package: jstl,
imported from standard jsp page:<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>c

Among the parameters: uri—used to introduce jstl; prefix—tag name, which can be taken at will, but generally named'c'

Common method

1. c: foreach tag: used to loop
items: traversed collection var: the value of each traverse
2. c: if

4. MVC mode

Is a development design pattern: JSP + Servlet + JavaBean

M:model: Model (domain, javabean)
V:view: View (jsp, html, etc.)
C:controller: Controller (servlet, controller)
Three-tier architecture: dao (data layer), service (business layer), controller (control layer)

MVC is not directly related to the three-tier architecture. MVC is a design pattern, while the three-tier architecture is a software architecture.

5. Special attention

1. Path A servlet can be configured with multiple paths
/*: all requests
*.action: interception suffix
2. Servlet creation time The
default is the first visit, which can be set to server startup creation

<load-on-startup>1</load-on-startup>

3. Servlet is singleton, don't use member variables indiscriminately

Guess you like

Origin blog.csdn.net/WLK0423/article/details/110789465
Recommended