Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

java - Velocity string function

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...