I want to show all users present in a database. I want to place all users in a list and then render that list to a template.
Then I want to iterate over the list of users displaying each in a <p>
tag
For u in users:
<p>u.username</p>
Endfor
I want to know how to retrieve the users from the database.
Public static Result render_f() {
List<String> users = ask in db;
return ok(template.render(users));
Is the above approach reasonable? If not can I get some pointers on where to go from here?
That's the basic syntax, often showed in docs and samples (check ie. computer-database
sample
app/models/User.java
@Entity
public class User extends Model{
@Id
public Long id;
public String name;
public static Finder<Long,User> find = new Finder<Long,User>(Long.class, User.class);
}
app/controllers/Application.java
Public static Result render_f() {
List<User> users = User.find.all();
return ok(template.render(users));
}
template.scala.html
@(users: List[User])
@for(user <- users){
<p>user.id</p>
<p>user.name</p>
etc...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With