The project structure is as shown in the screenshot:
1, first, the introduction of velocity programming required jar package, build all kinds of files. Under the required JAR package:
2. Configure the Web. xml file
Hellohandler.java specific code is as follows:
public class Hellohandler extends velocityviewservlet{private static final long serialversionuid = 1L;
Private Velocityengine Velo; @Override public void Init () throws servletexce
There are several ways to determine if it is null:
1. #if (! $foo) determine that $foo is empty and that non-null is #if ($foo)
2. Use #ifnull () or #ifnotnull ()
#ifnull ($foo)
To use this feature, you must include the following in the Velocity.properties file:
userdirective = org.apache.velocity.tools.generic.directive.Ifnull
userdirective = Org.apache.velocity.tools.generic.directive.Ifnotnull
3. Use the null tool to determine
#if ($null. IsNull ($foo))
Note that this is especially useful,
parsing and including corresponding resource files# Parse ("me. VM"), which shares the corresponding context with the main file # Stop: Used to stop parsing and return results. It is mainly used for debugging.6. Velocity # macro is quite powerful.# Macro, similar to macro definition, is used to customize the corresponding tag.A macro is defined as follows, which is used to output the list in the table.# Macro (tablerows $ color $ somelist)# Foreach (
Velocity. Exception. parseerrorexception: encountered "
Was expecting one:
"("..."##"..."\\\\"..."\\"..."*#"..."*#"..."{"..."}"...
After checking for more than an hour, I found that there is a # if not used # End closed in the VM file.
The problem is solved.
Velocity foreach usage, velocityforeach# Set ($ result =$ {list })# Set ($ I = 0)# Foreach ($ onlineData in $ {onlineDataList })$ Result. get ($ I)# Set ($ I = $ I + 1)# Foreach ($ hour in [0 .. 23])# End
# Foreach ($ online in $ onlineData)
# End
# End
Note: onlineDataList is a list defined in the background. It accesses multiple onlineData and onlineData is also a list.
1. Path Problem When Using velocityengine. gettemplate (filepath) (The resource does not exist)
Note: The relative path must be used to set the template location. The path is relative to the "file. Resource. loader. Path" attribute of velocityengine. You can set this attribute as follows.
Velocityengine VE = new velocityengine ();
Ve. setproperty ("file. Resource. loader. Path", "E: // resource // Java // tpsno02 // res // template // test ");
Ve. INIT ();
2.
1. because it is the latest eclipse, the plug-in prior to installation needs to install the support plug-in Eclipse 2.0 Style Plugin Help, Install New software->add follow the interface input Click OK, wait a minute.Only tick the selection of the red box, because I have installed, so the icon before the text is white. The color is not installed.Click on the next button, eclipse will automatically find the required dependencies, after the check will pop up the page to agree to the Agreement, c
The standard notation for velocity calls Java code is this
$! {Classname.staticmethod ()} or $! {Objectname.instancemethod ()}
Like what:
$! {Salehelper.iswltuser ($info. Getcateid (), $info. GetUserID ())}
This code, which belongs to the type of the object invocation instance method, needs to be noted for two places:
1, the syntax format must be correct, otherwise call not to the back-end Java method, and not to debug to the
2, the parameter ty
Recently, in the project, you need to add and subtract operations in the VM page, such as
#set ($balance =$!{ sumamont}+$! {surcharge}-$! {Depositamount})Always error, print on the page is
100+50-120
In the tangle for a long time after finally resolved, recorded here, one is to remind themselves, the second is for everyone to meet this error not like me, tangled too long.
The symbols on the page in velocity automatically call the ToString metho
Method 1: Valid for null and FALSE
#if (! $car. Fuel)Method 2: null and "" are valid#if ("$!car.fuel" = = "")If you judge the character blank:#if ("$car. Fuel" = = "")Combination Method 1 and 2, the judging field can only be null#if ((! $car. Fuel) ("$!car.fuel" = = ""))Method 4: Use tool detection, see: Http://wiki.apache.org/velocity/NullTool#if ($null. IsNull ($car. Fuel))Method 5: Use your own method to detect#if ($car. Fuelempty)The car class i
There are several workarounds for Velocity's $ vs. jquery $ conflict:
1. Use jquery instead of $.
such as: Jquery.ajax ();
Cons: Not suitable for expansion, once replaced with a third-party library, it is troublesome
2, use Jquery.noconflict.
such as: var j = jquery.noconflict (); J.ajax ();
Cons: When using jquery's related plugins, it will invalidate the plugin.
3. The conflict method in wrap jquery.
If $.ajax () conflicts in velocity, it is red
Learn the things to write here, forget to come back at any time to check, good memory than bad blog, haha, good nonsense not to say, this article mainly introduces the integration of SPRINGMVC and MyBatis
Note: SPRINGMVC version 3.1.2. MyBatis version 3.2.2 Database is Oracle First look at the configuration of Spring.xml
Very simple, just configure the @service support and database connection resource files, of course you can also add some other need to initialize the resource files;
2. Confi
Problem Description:
In the context of using the Velocity template engine, when using jquery, such as: $.fullcalendar.gcalfeed (' http://www.google.com/calendar/feeds/sfzc1% 40realintelligence.com/public/basic ')
where $ conflicts with velocity variables.
Solution:
Define a velocity variable: #set ($jquery = "$.") Then: ${jquery}fullcalendar.gcalfeed
For this issue please refer to:
http://www.oschina.net/question/100267_20922
Turn the content on the post and add your own solution.
Tsl0922 said: "
Beginner velocity, want to write a Velocitytool class implementation to embed dynamic pages in a relative path, the idea is roughly the same as in http://www.oschina.net/code/snippet_12_694, because the new version of the Init (Object ARG0) method has been Deprecated , swap with configure (MAP props) (s
The configuration of a rigid mobile robot is usually described in 6 variables: his three-dimensional Cartesian coordinate system, and the relative external coordinate system of three Euler angles (RPY roll, pitch, yaw), so in the plane environment generally with three variables can be described, called posture.So in general, the posture information of a robot is a two-dimensional planar coordinate (x, y) of a robot and its azimuth Θ\theta, which is represented by this vector:⎛⎝⎜xyθ⎞⎠⎟\begin{pmat
;Echo ' Used time of foreach: '. Round ($time _used, 7). ' (s)';?>Test results:
Used time of for:0.0228429 (s)
Used time of while:0.0544658 (s)
Used time of foreach:0.0085628 (s)
After repeated tests, the result shows that for traversing the same array, the foreach speed is the fastest and the slowest is the while. In principle, foreach operates on an array copy (by copying the arrays), while the while is manipulated by moving the internal indicators
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.