MyBatis
修心猿
这个作者很懒,什么都没留下…
展开
-
Mybatis 使用注解和Provider类实现动态条件查询
Mybatis 提供了基于Xml和注解的自定义SQL查询,相比Xml的方式,注解更加便捷、优雅。为了防止遗忘具体的细节编写,摘录一段曾经写过的代码。此处,一大片注解内容十分不优雅,更好的办法是通过调用Provider类的指定方法生成SQL。1.注解内拼写 Mybatis SQL 脚本@Repositorypublic interface CustomerFeedMapper exte...转载 2018-08-29 11:45:39 · 3500 阅读 · 0 评论 -
Mybatis解决sql中like通配符模糊匹配
针对oracle数据库:1、将查询条件通过功能类处理/** * Description: 处理转义字符%和_,针对ORACLE数据库 * * @param str * @return */ public static String escapeStr(String str) { String temp = ""; for (int i = 0; i <...转载 2018-09-04 10:30:43 · 2773 阅读 · 0 评论 -
mybatis3中@SelectProvider的使用技巧
mybatis的原身是ibatis,现在已经脱离了apache基金会,新官网是http://www.mybatis.org/。 mybatis3中增加了使用注解来配置Mapper的新特性,本篇文章主要介绍其中几个@Provider的使用方式,他们是:@SelectProvider、@UpdateProvider、@InsertProvider和@DeleteProvider。MyBatis ...转载 2018-09-04 13:12:19 · 161 阅读 · 0 评论 -
Parameter 'loginname' not found. Available parameters are [arg1, arg0, param
Parameter 'loginname' not found. Available parameters are [arg1, arg0, param最近用ssm整合,刚做就遇到这个问题了原来是这样写的@Select("select * from myuser where loginname=#{loginname} and password=#{password}") Us...原创 2018-09-04 14:14:35 · 1503 阅读 · 0 评论 -
Mybatis中的模糊查询
今天下午做的一个功能,要用到模糊查询,字段是description,刚开始我的写法用的是sql中的模糊查询语句,但是这个有问题,只有将字段的全部值传入其中,才能查询,所以不是迷糊查询。后来经过搜索,发现要加上一个concat字段,要先将字符串拼接后,才能实现模糊查询。改成这个样子后,模糊查询功能实现。 在我搜索到的博客中海油别的几种写法,但是试验了两个,有一个成功,另外...转载 2018-09-04 14:50:56 · 4476 阅读 · 0 评论 -
MyBatis注解select in参数
/** * * @param ids '1,2,3' * @return */@Select("select * from user_info where id in (${ids})")List<UserInfo> getUserbyIds(@Param("ids")String ids); 参数需要使用${}来引用,#{}不能识别。...原创 2018-09-04 17:28:02 · 3052 阅读 · 0 评论 -
mybatis in的爬坑
今天写map时,(伪代码):update xxx t set t.a='1' where id in (#{ids});当ids传入为string 1,2,3 时,得出效果只是更新了id=1的数据,原来#{xxx}是一个字符串,mybatis只会当他是一个值,如果你想达到字面上的效果:1 用${ids} 把ids当成字符串传进来2 update xxx t set t.a='1' where...原创 2018-09-21 10:12:22 · 129 阅读 · 0 评论 -
mybatis怎么实现对象参数和注解参数同时传入
自定义对象也用@param注解. 在mapper.xml中使用的时候,#{对象别名.属性名},如#{user.id} 注意,使用了@pram注解的话在mapper.xml不加parameterType。 1 2 3 4 public List<UserExtension> selectAllUsers( ...原创 2018-09-26 17:03:47 · 6576 阅读 · 0 评论