Velocity notes (Part 1)

Source: Internet
Author: User

By reading some velocity documents, you can write down what you see as a simple and unsystematic note, which enhances your memory.

Dynamic Language features:

A Dynamic Language requires an interpreter, which is generally on the server.

MVC

Model: Indicates the status of the system and application, which is generally a class or other data structure. Can change the system statusActionsAndMethod. TypicalJavabean. The original intention is to separate data from display.

View: Displays the components of the result data, alongModelAnd the status changes,ViewMake changes accordingly.

Controller: A bridge between users and applications.ControllerCapture user input and use the established logic to determine which command input is routedModel.

Use onlyJspTechnologyModel 1

JoinServletCall do laterModel 2

What isVelocity

Velocity is a template language designed to give Web designers an easy way

Present dynamic information to users of a Web site or application.

VelocityThere is a set calledContextTo put it bluntlyControllerAndModelEncapsulation of layer, provides a Web page template.

ImplementedVelocityThe code fromContextReplace the script element in the template with the data obtained from the object in.

VelocitySimple code:

A simple language description process is:VelocityInitialize andContextMediumPutEnter the object, and thenTemplateLoadVmTemplate, and then useTemplateSet thisVmAndContextProceedMerge.ViewPage.

ContextOther types of data can be stored.PutCome in,VelocityWill automatically callToStringMethod.

Next we will focus onContext.

Context Introduction

ContextEssentiallyJavaCode layer andVelocityA data bridge between the template layer.JavaDevelopers place various data objectsContext, Page Template designer fromContextObtainReference.VelocityDefined inVelocityContextTo provide basic implementation. This implementation correspondsJavaInHashtableSimilarly, the most useful and common method is

Public Object put (String key, Object value );

Public Object get (String key );

If you understandContextSo what can be included in the container feature?ContextFirst, you can put some iteration objects (Iterative Objects), Such as object ArrayObject [], java. util. Collection, java. util. Map, java. util. Iterator, java. util. Enumeration,And anyPublic Iterator iterator ()MethodPublic class. SecondContextAlso supportedPutStatic class (Static class), SuchContext. put ("Math", Math. class). Of course, inVelocityRuntime Template The generated object can also be placed inContext.

Velocity OfReference

VariableVariable: CorrespondingJavaA string representation of an object. The returned value is called.JavaOfToStringResult of the method.

MethodMethod: Call a method of the referenced object. The method must bePublicClassPublicMethod. If this method returns a valueVelocityAfter the method is called, the return value will be the same.ToStringPackaging. The parameter requirements are as follows:VelocityAll method parameters must beString.

AttributeProperty: Similar method, except for accessingJavaIs equivalentGet ***Method.

$!The prefix isQuiet notationWhen the referenced object does not exist, the reference generated with this prefix will return the "" string instead of the string of the name of the nonexistent object.

"""Is an escape character, which can be escaped$Symbols and other symbols

Velocity Command

# Stop: UsedDebug, WhenEngineWhen this command is run, the execution is stopped and the control is returned to the calling program.

# Include: Used to include external files. The content of the external files is directly added to the program.

# Parse: AndIncludeSimilar, but the difference is that,IncludeThe introduction of static files, whileParseThe template is dynamically loaded, that is,ParseWill parseVmFile, and then add it to the source file.

# Set: Is a very powerful value assignment command, no matter whether the assigned variable already exists or assigned a value, the newSetThe command will be completely overwritten. Command Format is# Set (ref = value). Several noteworthySetUsage:

ListAndRangeThe usage can be equivalentJavaInArrayList.

PairBooleanValueSet,SetSupport Short CircuitShort circuit

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.