1.创建mysql数据库,如:create database fun;
2.在application.conf中开启mysql,如:
db=mysql://root:123456@127.0.0.1/fun
3.mysql语句,基本语法同db=em的相同,不同,如
String url="select p from Post p order by postedAt asc";
posts = Post.find(url).fetch();
String url="select p from Post p where p.author.id=?";
posts = Post.find(url, user_id).fetch();、
4.告诉EntityManager哪个object不用更新,可以调用refresh(),我们在object提交之前但object不应该被更新时使用。
5.遍历list的方法
![](https://i-blog.csdnimg.cn/blog_migrate/f7c3c3edd469b1ae9a28a8973df98813.jpeg)
会报类型不匹配的错误。
有以下两种方法可以解决:
![](https://i-blog.csdnimg.cn/blog_migrate/cae7a38fa28239d31f16393dfbf32578.jpeg)
![](https://i-blog.csdnimg.cn/blog_migrate/0bf546ce0e7dcb83dcf95e169e744499.jpeg)