Java开发常见错误:org.mybatis.spring.MyBatisSystemException

来源:互联网 发布:js data- 编辑:程序博客网 时间:2024/04/20 21:54
org.apache.ibatis.binding.BindingException: Parameter 'username' not found. Available parameters are [param1, tag]
《===================================解决方案一======================================》
传递的参数为Map类型
  一直对Map类型作为参数不是很熟悉,后来定位到Map参数取值问题。
  原因是:Dao接口里面使用了@Param 而参数为Map时,去参数应该是#{paraMap.email}
       public List<Book> getBooksUnderEmailAndTag(@Param(value="tag")Map<String,String> paraMap);
《===================================解决方案二=======================================》
一般出项这种情况,都是有关联对象,而且想一次性添加或者修改。可以使用分离对象添加或修改。
比如User和Department对象。User中有dep_id.这样我们可以先通过depId查出dep的name。先设置user的部门为dep.
然后再添加User对象。想这样的逻辑处理可以放到service层。。
UserService中。
public void update(User user,int depId) {Department dep=departmentDao.load(depId);user.setDepartment(dep);       //设置部门this.userDao.update(user);    //添加User对象。}
至于SQL不用改变,一次性写好。
insert into t_user(username,password,nickname,dep_id)       value(#{username},#{password},#{nickname},#{department.id});
1 0
原创粉丝点击