Now that we know how to connect Lift applications to the database, the next step is to learn how to create mappings between a database table and a Scala object using Mapper.
We will re-use the project we created in the previous recipe since it already has the connection configured.
Carry out the following steps to map a table into a Scala object using Mapper:
Create a new file named
Contact.scala
inside themodel
package undersrc/main/scala/code/
with the following code:package code.model import net.liftweb.mapper.{MappedString, LongKeyedMetaMapper, LongKeyedMapper, IdPK} class Contact extends LongKeyedMapper[Contact] with IdPK { def getSingleton = Contact object name extends MappedString(this, 100) } object Contact extends Contact with LongKeyedMetaMapper[Contact] { override def dbTableName = "contacts" }
Add the following import statement in the
Boot.scala
file:import code.model.Contact
Add the following code into the
boot...