Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Velocity string function

Tags:

java

velocity

I just start using Java Velocity. Now I want to create a java class template.

package $app.package_namespace public class ${app.name}Station  {     #foreach($s_attribute in $app.station)          $s_attribute.type $s_attribute.name,     #end     public $app.name Station(#foreach($s_attribute in $app.station)                                  $s_attribute.type $s_attribute.name;                              #end) {     #foreach($s_attribute in $app.station)           $s_attribute.name=$s_attribute.name;     #end } #foreach($s_attribute in $app.station)     public ${s_attribute.type} get${s_attribute.name}()     {         return  get${s_attribute.name}();     } #end } 

The problem is s_attribute.name first character is lowercase. When I create getter and setter function for attributes. I need change first character to uppercase.

Did anyone know how to do it?

like image 398
Yiming Avatar asked Aug 09 '11 15:08

Yiming


People also ask

How does a velocity string work?

A small diameter tubing string, often coiled tubing that is suspended inside the existing production tubing. By occupying part of the flow path space, the velocity of the produced fluid is increased and the potential to lift water from the well is increased.

What is Apache velocity used for?

Velocity can be used to generate web pages, SQL, PostScript and other output from templates. It can be used either as a standalone utility for generating source code and reports, or as an integrated component of other systems.

How do you use velocity in HTML?

In the code you posted: there 2 ways to run velocity: running the main (but this is not what you do when you build your project) running ant form but since you don't fill any velocity context: velocity won't be able to replace the variable in your template (i.e. the generated html won't contains dynamic data)

What is velocity code?

A velocity code associates the location to a SKU's throughput. For example, fast moving items are stored in the lower level locations, or locations reachable by hand, in the bulk zone. Create a Velocity Code.


2 Answers

You can invoke standard java methods on these objects. If s_attribute.name is type String you can directly use $s_attribute.name.toUpperCase() or for your specific case use $s_attribute.name.substring(0,1).toUpperCase() and $s_attribute.name.substring(1).toLowerCase()

like image 97
d-live Avatar answered Oct 05 '22 23:10

d-live


There is capitalize() method in DisplayTool:

get${display.capitalize($s_attribute.name)}() 
like image 42
serg Avatar answered Oct 06 '22 00:10

serg