1.使用maven管理依赖,在项目的pom.xml中加入依赖:
<pre name="code" class="html"> <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.sorm-framework</groupId>
<artifactId>sorm</artifactId>
<version>0.3.15</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
最好不需要的依赖都不要加,以防运行时报错
2.使用SORM与mysql的最简测试代码如下:
package scala_mysql
case class Person(name: String)
import sorm._
object db extends Instance(
entities = Set(Entity[Person]()),
url = "jdbc:mysql://localhost/testscala",
user = "root",
password = "",
initMode = InitMode.Create
)
/**
* Created by aminic on 14-11-17.
*/
object Main {
def main(args: Array[String]) {
println("OK")
val name = "lucy"
val p = Person(name)
db.save(p)
val r = db.query[Person]
.whereEqual("name", name)
.fetchOne()
println(r.get.name.equals(name))
println("saved")
}
}