Springboot整合Mybatis传值的常用方式总结

方式一:直接传

接口

public interface UserMapper {
    public List getUserById(int id);
}

xml



 


    

方式二:通过注解方式 @Param

这种方式,在模糊查询的时候会用到,注解的参数和xml中的变量必须一致!(xml中不知道为什么必须要使用 ${} 方式,使用#{} 的方式查还不出来数据!)
接口

public interface UserMapper {
    public List getLikeList(@Param("name")String pname);
}

xml



 


 
    
 

方式三:通过Map键值对儿方式

这种方式的好处是变量(就是Map类型中的key)不需要跟字段名一致,而且传的字段根据实际需求来定,对于这个例子来说,如果使用 User类作为参数类型,那么你必须要传递所有的属性才行!

接口

import com.lxc.springboot.domain.User;
import org.apache.ibatis.annotations.Param;
 
import java.util.List;
import java.util.Map;
 
public interface UserMapper {
    // 插入数据
    public void insertUser(Map user);
}

xml



 


 
    
        insert into user(user, name, age, password) values (#{userPost}, #{userName}, #{userAge}, #{userPassword})
    

就这么多,以后项目中用到别的方式,在记录!

到此这篇关于Springboot整合Mybatis传值的常用方式总结的文章就介绍到这了,更多相关Springboot整合Mybatis传值内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(Springboot整合Mybatis传值的常用方式总结)