Search code examples
mysqllistgrailsgsp

How can i get all the values/rows of a table from Mysql database by clicking on a button in grails (.GroovyServerPages page)?


how can i get all data from all the rows from a table into my Groovy Server Pages(GSP) page from MySQL database? already have tried to get list but not successful.

def list(){
    def student1 = Student.getAll(1,2,3)
    [student:student1]
}

Solution

  • def list(){
        [students: Student.list()]
    }
    

    and in your list.gsp

    <ul>
    <g:each in="${students}" var="student">
        <li>${student.id}</li> <!-- or other property -->
    </g:each>
    <ul>