student实体类
@Table("student")
public class Student {
@ManyMany(target = Lesson.class,relation = "less_stu",from="stuId",to="lessId")
private List<Lesson> lesson;
@Id
private int id;
@Column
@ColDefine(width = 20)
@Comment("名字")
private String stuname;
Lesson实体类
@Table("lesson")
public class Lesson {
@ManyMany(target = Student.class,relation = "less_stu",from="lessId",to="stuId")
private List<Student> students;
@Id
private int id;
@Column
@ColDefine(width = 20)
@Comment("名字")
private String lesname;
插入操作
如果你已经实现准备好了这样的对象:
Food food = new Food("Fish");
List<Pet> pets = new ArrayList<Pet>();
pets.add(new Pet("XiaoBai");
pets.add(new Pet("XiaoHei");
food.setPets(pets);
这个Food food=new Food("Fish")中的fish是啥?我在上面的实体类中找不到 求教
```
添加方法
@At("addStudent")
@Ok(">>:queryArrStu")
@Aop(TransAop.READ_COMMITTED)
public boolean AddStudent(HttpServletRequest request){
String name = request.getParameter("name");
int lessId = Integer.parseInt(request.getParameter("lessId"));
Student student=new Student();
List lessons=new ArrayList();
Lesson lesson = new Lesson();
lesson.setId(lessId);
lessons.add(lesson);
student.setLesson(lessons);
student.setStuname(name);
Student insert = dao.insert(student);
Student student1 = dao.insertRelation(student, "lesson");
if(insert==null&&student1==null){
return false;
}
return true;
}
服务器结果
2017-07-12 15:22:16[INFO ]org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/][203]-15:22:14.346 DEBUG org.nutz.mvc.impl.UrlMappingImpl - Found mapping for [GET] path=/ : LoginController.index(LoginController.java:36)
15:22:14.374 DEBUG org.nutz.ioc.impl.NutIoc - Get 'loginController'<class team.chance.simple.module.web.controller.LoginController>
15:22:14.374 DEBUG org.nutz.ioc.impl.NutIoc - >> Load definition name=loginController
15:22:14.376 DEBUG org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(loginController) in AnnotationIocLoader(packages=[team.chance.simple.module])
15:22:14.377 DEBUG org.nutz.ioc.impl.NutIoc - >> Make...'loginController'<class team.chance.simple.module.web.controller.LoginController>
15:22:14.378 DEBUG org.nutz.ioc.aop.impl.DefaultMirrorFactory - Load class team.chance.simple.module.web.controller.LoginController without AOP
15:22:14.379 DEBUG org.nutz.ioc.impl.ScopeContext - Save object 'loginController' to [app]
15:22:14.411 DEBUG org.nutz.ioc.impl.NutIoc - Get 'dao'<interface org.nutz.dao.Dao>
2017-07-12 15:22:20[INFO ]org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/][203]-15:22:19.223 DEBUG org.nutz.mvc.impl.UrlMappingImpl - Found mapping for [GET] path=/queryTeacher : ShowTeacher.QueryTeacher(ShowTeacher.java:42)
15:22:19.224 DEBUG org.nutz.ioc.impl.NutIoc - Get 'showTeacher'<class team.chance.simple.module.web.controller.ShowTeacher>
15:22:19.224 DEBUG org.nutz.ioc.impl.NutIoc - >> Load definition name=showTeacher
15:22:19.224 DEBUG org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(showTeacher) in AnnotationIocLoader(packages=[team.chance.simple.module])
15:22:19.224 DEBUG org.nutz.ioc.impl.NutIoc - >> Make...'showTeacher'<class team.chance.simple.module.web.controller.ShowTeacher>
15:22:19.227 DEBUG org.nutz.ioc.impl.NutIoc - Get 'txREAD_COMMITTED'<interface org.nutz.aop.MethodInterceptor>
15:22:19.228 DEBUG org.nutz.ioc.impl.NutIoc - >> Load definition name=txREAD_COMMITTED
15:22:19.228 DEBUG org.nutz.ioc.loader.map.MapLoader - Loading define for name=txREAD_COMMITTED
15:22:19.239 DEBUG org.nutz.ioc.loader.combo.ComboIocLoader - Found IocObject(txREAD_COMMITTED) in TransIocLoader@1506363121
15:22:19.239 DEBUG org.nutz.ioc.impl.NutIoc - >> Make...'txREAD_COMMITTED'<interface org.nutz.aop.MethodInterceptor>
15:22:19.239 DEBUG org.nutz.ioc.impl.ScopeContext - Save object 'txREAD_COMMITTED' to [app]
15:22:19.263 DEBUG org.nutz.ioc.impl.NutIoc - Get 'txREAD_COMMITTED'<interface org.nutz.aop.MethodInterceptor>
15:22:19.265 DEBUG org.nutz.ioc.impl.NutIoc - Get 'txREAD_COMMITTED'<interface org.nutz.aop.MethodInterceptor>
15:22:19.272 DEBUG org.nutz.aop.asm.AsmClassAgent - AsmClassAgent will define class in Version 50
15:22:19.306 DEBUG org.nutz.ioc.impl.ScopeContext - Save object 'showTeacher' to [app]
15:22:19.350 DEBUG org.nutz.ioc.impl.NutIoc - Get 'dao'<interface org.nutz.dao.Dao>
15:22:19.580 DEBUG org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT t.id,t.tchname,l.lesname FROM teacher t INNER JOIN lesson l ON t.lessId=l.id
2017-07-12 15:22:22[INFO ]org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/][203]-15:22:22.039 DEBUG org.nutz.mvc.impl.UrlMappingImpl - Found mapping for [GET] path=/toaddstudent : ShowTeacher.toAddStudent(ShowTeacher.java:117)
15:22:22.040 DEBUG org.nutz.ioc.impl.NutIoc - Get 'showTeacher'<class team.chance.simple.module.web.controller.ShowTeacher>
15:22:22.065 DEBUG org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM lesson
2017-07-12 15:22:29[INFO ]org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/][203]-15:22:29.798 DEBUG org.nutz.mvc.impl.UrlMappingImpl - Search mapping for [GET] path=/addstruts : NOT Action match
前端报错
HTTP Status 404 - /addstruts
type Status report
message /addstruts
description The requested resource is not available.
Apache Tomcat/8.0.38