", as the storage path//here with for (int i=1;i Five, Tool class Package Com.geenk.web.velocity_engine;import Org.apache.velocity.template;import Org.apache.velocity.velocitycontext;import Org.apache.velocity.app.velocity;import Org.slf4j.Logger;import Org.slf4j.loggerfactory;import Java.io.bufferedwriter;import Java.io.file;import Java.io.FileOutputStream;import Java.io.outputstreamwriter;import java.util.properties;/** * @author duchong * @since 2018-04-28 18:35 **/public class Ge nerateh
Of course, looking for cases of the big people generally want to go directly to a case on the line, not a lot of time to read a lot of text, so not long-winded.
One of course first to download velocity required jar bag, everywhere there are downloads of course I'm going to the official download, after all, the official things are generally more formal
To say the Apache official, think of just start out to work in the basic daily in the official Apac
(Do not use this template, the latest version of spring boot is not supported.) Use Freemarker bar: http://blog.csdn.net/clementad/article/details/51942629)
In a few simple steps, use the velocity template to generate text in spring boot:
1. Introduction of Dependency
2. Create templates directory in Resources
3. Create a. VM template file Welcome.vm:
4, use the template, test cases:
@Autowired
velocityengine velocityengine;
There are two ways to integrate struts2 with velocity
1, mainly to struts2. Struts2 built-in support for velocity, as long as the Issue: When accessing VM files directly, the source code of the VM is output. How to prohibit direct access to *.VM type files.
Benefit: You can use similar struts tags. I always feel that this is a strange use.
2, with velocity as t
1. How to get the WiFi object and operate the WiFi device, you need to get Context.getsystemservice (Context.wifi_service) to get the Wifimanager object, and use this object to manage WiFi devices. Addnetwork (wificonfiguration config) Adds a config description of the WiFi network, by default, this
An example of Velocity application keywords : Java, JSP, Servlet, template, templates, Apache, Jakarta, VelocityReader Requirements : Understanding Java Servlet Basic ConceptsVelocity is a general-purpose, java-based template tool that comes from jakarta.apache.org.Velocity is a reference to the velocity--Java Web development technology . Here is an example of its application.This example refers to the stru
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
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.