学生类:
public class Student extends Model<Student> { public static final Student dao = new Student(); public Classes getClasses() { return Classes.dao.findById(get("class_id")); } }
班级类:
public class Classes extends Model<Classes> { public static final Classes dao = new Classes(); }
DemoConfig:
@Override public void configPlugin(Plugins me) { // 数据库的ORM映射的配置。 C3p0Plugin cp = new C3p0Plugin("jdbc:mysql://localhost:3306/wt", "root", "111111"); me.add(cp); ActiveRecordPlugin arp = new ActiveRecordPlugin(cp); me.add(arp); arp.addMapping("t_user", User.class); arp.addMapping("t_class", "class_id", Classes.class); arp.addMapping("t_student", "id", Student.class); }
jsp:
<c:forEach items="${studentList}" var="student"> <tr> <td> ${student.name} </td> <td> ${student.age} </td> <td> ${student.sex} </td> <td> ${student.getClasses().class_name} </td> <td> <a href="/student/delete/${student.studentid}">删除</a> <a href="/student/get/${student.studentid}">修改</a> </td> </tr> </c:forEach>
${student.getClasses().class_name}这一句报空指针异常,望高手解惑 ,哪里没弄对 .
解决方案
30
student 绑表,写sql