scala - How to access fields of case class from JSP? -
when java programmer typical approach write pojo getters , access fields in jsp through getters ${pojo.field}
.
now i'm trying use scala. case classes looks replacement pojo's, scala provides field()
getters instead of getfield()
required jsp.
so, how access case class fields jsp without manually writing def getfield = field
each field? or maybe there more suitable approach purpose?
annotate fields of case classes scala.beans.beanproperty:
import scala.beans.beanproperty; case class person( @beanproperty val name : string, @beanproperty val age : int);
now person class have methods getname()
, getage()
name()
, age()
.
if need bean setters, use var
s:
class person( @beanproperty var name : string, @beanproperty var age : int);
(note: don't make nonimmutable objects case classes, though legal declare case
before mutable class declaration.)
now you'll find equivalents of java void setname( string name )
, void setage( int age )
have been defined.
Comments
Post a Comment