Friday 15 July 2011

java - How to list data from database in a web page in spring framework -



java - How to list data from database in a web page in spring framework -

i have created database called pupil base of operations on tutorial provided tutorials point pdf, have covered how map form , insert values in database using controllers, have not explained how display info database on webpage.

my code list students.

@override public list<student> liststudents() { string sql = "select * student"; list<student> students = jdbctemplateobject.query(sql, new studentmapper()); homecoming students; }

how phone call controller in spring , homecoming list webpage.

my contoller given below

@controller public class studentcontroller { @requestmapping(value = "/student", method = requestmethod.get) public modelandview student() { homecoming new modelandview("student", "command", new student()); } @requestmapping(value = "/addstudent", method = requestmethod.post) public string addstudent(@modelattribute("springweb")student student, modelmap model) { applicationcontext context = new classpathxmlapplicationcontext("beans.xml"); studentjdbctemplate studentjdbctemplate = (studentjdbctemplate)context.getbean("studentjdbctemplate"); studentjdbctemplate.create(student.getname(), student.getage()); model.addattribute("name", student.getname()); model.addattribute("age", student.getage()); model.addattribute("msg", "student enrolled"); homecoming "result"; } // how write listing controller? }

from details provide ,

public string liststudents(modelmap model) { list<student> list= yourserviceclassobj.liststudents(); model.addattribute("result", list); homecoming "view name here"; }

java spring spring-mvc java-ee

No comments:

Post a Comment