ibatis 多表查询操作详解
来源:百度文库 编辑:神马文学网 时间:2024/04/29 02:26:31
字串9
字串8
字串5
字串4
alias="condition" /> 字串8 字串6 字串9 字串9 class="com.infodeliver.pigeon.bean.Group"> 字串2 字串8 字串7 class="rolebean"> 字串2 字串1 字串6 字串5 class="userbean"> 字串5 字串6 字串1 字串3 字串2 字串7 字串5 字串3 字串6 字串7 字串3 select * from sew_role where role_id=#value# 字串7 字串9 字串5 字串1 字串5 字串6 insert into sew_user 字串3 values(sew_user_id_seq.nextval, 字串7 #username#,#password#,#email#,#group.groupid#,#role.role_id#,#nationality#, 字串9 #tel#,#address#,#language#,#isEvectioner#,#realname#) 字串8 字串5 字串3 业务逻辑: 字串5 Public class UserService{ 字串4 public User getUser(User user){ 字串2 User user1=null; 字串1 try { 字串2 System.out.println(user.getUser_id()); 字串2 user1 =(User)getSqlMapExecutor().queryForObject("getuser",user); 字串5 } catch (SQLException e) { 字串2 e.printStackTrace(); 字串4 return null; 字串7 } 字串8 return user1; 字串1 } 字串2 } 字串9 字串7 字串8 字串4 字串2 字串7 请看操作部分的代码: 字串9 实现效果:察看user_id为2的用户在那个组。 字串4 UserService us=new UserService(); 字串6 User ub=new User(); 字串9 ub.setUser_id(2); 字串3 ub =(User)us.getUser_Group(ub); 字串5 System.out.println("ok"+"\n"+ub.getUsername()+"\n"+ub.getGroup().getGroupname()+"\n"+ub.getRole().getRole_name()); 字串7 System.out.println(ub.getGroup().getGroupname()); 字串5 字串7 增加用户: 字串6 User user=new User(); 字串3 user.setUser_id(27); 字串2 user.setUsername("##梁静茹!!"); 字串2 user.setPassword("1111"); 字串5 user.setEmail("ljr@sohu.com"); 字串7 user.setLanguage("CN"); 字串5 user.setAddress("无锡.江苏"); 字串1 user.setNationality("中国"); 字串8 user.setTel("1390000000"); 字串5 user.setRealname("欧阳静茹"); 字串7 Group g=new Group(); 字串6 g.setGroupid(1); 字串8 Role r =new Role(); 字串7 r.setRole_id(1); 字串1 user.setGroup(g); 字串2 user.setRole(r); 字串4 user=us.saveUser(user); 字串6 if(user!=null) 字串1 System.out.println(user.getGroup().getGroupid()); 字串5 字串7 以上所有操作都是通过的!