在编写代码的时候,我对查询这个方法进行了重载,这样调用的时候会根据参数的不同,进而去执行不同的操作,但是......问题来了。想法都是美好的,实际情况却不是我理想的状态。运行代码的时候他动了几下,然后一片红色。

我仔细看了看代码:

     @Select("INSERT  INTO comment (com_pro,user_name,com_content,com_score) VALUES (#{comment.com_pro},#{comment.user_name},#{comment.com_content},#{comment.com_score}")
public int insertComment(Comment comment); @Select("DELETE FROM comment WHERE com_id =#{comment.com_id}")
public int delCommentById(int id); @Select("DELETE FROM comment where user_name=#{comment.user_name}")
public int delCommentAll(String name); @Select("update comment set com_content=#{comment.com_content},com_score=#{comment.com_score} where com_id=#{comment.com_id}")
public int updateComment(Comment comment); @Select("SELECT * FROM comment where com_pro=#{comment.com_pro}")
public List<Comment> findCommentAll(String proname); @Select("SELECT * FROM comment where com_pro=#{proname} and com_score=#{com_score}")
public List<Comment> findCommentAll(String proname,String com_score);

当我运行代码的时候,就会就收到如下错误:

严重: Error while adding the mapper 'interface com.sh.dao.CommentDao' to configuration.
java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.sh.dao.CommentDao.findCommentAll

告诉我这个方法“添加映射的接口的COM的错误。sh.dao commentdao”配置。”(百度翻译)

方法名是否真的不可以一样?

答案是肯定的,少侠。

mybatis @Select是不支持方法重载的(如果红字不算执行结果的话)。

封印代码:

     @Select("INSERT  INTO comment (com_pro,user_name,com_content,com_score) VALUES (#{comment.com_pro},#{comment.user_name},#{comment.com_content},#{comment.com_score}")
public int insertComment(Comment comment); @Select("DELETE FROM comment WHERE com_id =#{comment.com_id}")
public int delCommentById(int id); @Select("DELETE FROM comment where user_name=#{comment.user_name}")
public int delCommentAll(String name); @Select("update comment set com_content=#{comment.com_content},com_score=#{comment.com_score} where com_id=#{comment.com_id}")
public int updateComment(Comment comment); // @Select("SELECT * FROM comment where com_pro=#{comment.com_pro}")
// public List<Comment> findCommentAll(String proname);
//
// @Select("SELECT * FROM comment where com_pro=#{proname} and com_score=#{com_score}")
// public List<Comment> findCommentAll(String proname,String com_score);

运行我的Test:

     @Test
public void test() {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
ActivityService ad = ctx.getBean(ActivityService.class);
List<Activity> list = ad.findActivityAll();
for (Activity e : list) {
System.out.println(e.toString());
}
}

得到输出结果:

 Activity [act_id=1, act_theme=双十一, act_img=12345, act_time=Sat Nov 11 00:00:00 CST 2017]

总结:

记者:为什么要写注解?

我:没有钱了,肯定要做啊,不做没有钱用。

记者:你有手有脚的怎么不去写重载?

我:重载方面......重载是不可能重载的 这辈子不可能重载的,做实现类又不会写,就是接口这种东西,才能维持得了生活这样子.

记者:那你觉得注解好还是看重载好?

我:不写重载的感觉像回家一样,我一年写重载,大年三十 晚上我都不回去,就平时重载出点事,我就回去看看这样子,注解的感觉,比重载感觉好多了,在重载的时候一个人很无聊,都没有朋友,女朋友玩 ,写了注解发现个个都是人才,说话又好听,超 喜欢写注解。

@Select注解的情况下,重载的报错的更多相关文章

  1. [Android自动化] 在 pip-9.0.1 版本情况下安装 uiautomator2 报错的解决办法

    1.在命令窗口中使用命令: pip install uiautomator2 时报 pip 版本过低,需要先升级 pip 版本,理论上会按照提示进行升级 pip 操作,但执行升级命令时到最后却还是报错 ...

  2. linux 下 tomcat 运行报错 Broken pipe

    linux 下 tomcat 运行报错 Broken pipe 感谢:http://hi.baidu.com/liupenglover/blog/item/4048c23ff19f1cd67d1e71 ...

  3. 【转】Eclipse下启动tomcat报错:/bin/bootstrap.jar which is referenced by the classpath, does not exist.

    转载地址:http://blog.csdn.net/jnqqls/article/details/8946964 1.错误: 在Eclipse下启动tomcat的时候,报错为:Eclipse下启动to ...

  4. [转]解决IIS下UTF-8文件报错乱码的问题

    找了两天才找到解决办法…….晕晕晕...用第二种方法解决了. 网上找到的方法都没有写这一条 If objASPError.ASPDescription > "" Then 后 ...

  5. [原创] ubuntu下安装scrapy报错 error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    Ubuntu14.04在virtualenv下安装scrapy报错,Failed building wheel for cffi,lxml,cryptography 等. error: command ...

  6. mac下brew install 报错

    mac下brew install 报错 错误提示: 原因:是这个brew的权限不正确 修改一下这个brew的权限 chown root:wheel /usr/local/bin/brew

  7. Linux下Oracle11G RAC报错:在安装oracle软件时报file not found一例

    Linux下Oracle11G RAC报错:在安装oracle软件时报file notfound一例 1.现象 之前安装一切都比較顺利,安装oracle软件时,进度到30%时报错:file not f ...

  8. Linux系统下启动MySQL报错:Neither host &#39;localhost.localdomain&#39; nor &#39;localhost&#39; could be looked up with

    Linux系统下启动MySQL报错:Neither host 'localhost.localdomain' nor 'localhost' could be looked up with 摘要 Li ...

  9. window下安装redis报错: creating server tcp listening socket 127.0.0.1:6379: bind No error

    window下安装redis报错: creating server tcp listening socket 127.0.0.1:6379: bind No error 解决: 如果没有配置环境,在安 ...

随机推荐

  1. u-boot的SPL源码流程分析

    上次梳理了一下SPL的基本概念和代码总体思路,这次就针对代码跑的流程做个梳理.SPL中,入口在u-boot-spl.lds中 ENTRY(_start) SECTIONS { .text : { __ ...

  2. 堆排序(Java数组实现)

    堆排序:利用大根堆 数组全部入堆,再出堆从后向前插入回数组中,数组就从小到大有序了. public class MaxHeap<T extends Comparable<? super T ...

  3. 在java或 js中的日期时间转换问题

    1.在js中需要求的当前日期的周一和周日 var now = new Date(); // 当前日期时间对象 var date = now.getDate(); // 当前是几号:当前日期在一个月中的 ...

  4. Java过滤器Filter使用详解

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6374212.html 在我的项目中有具体应用:https://github.com/ygj0930/Coupl ...

  5. DotNetBar控件,superTabControl多文档界面(MDI)的风格、多Tab的创建方法

    最近在做一个条码系统的项目,第一次用dotnetbar控件,,查找资料时看到伍老师一篇文章(链接),但是没有关于加载tab窗口的方法,自己摸索做了一个此类风格出来,并写了一个通用方法,供大家参考. 风 ...

  6. 使用SQLiteOpenHelper类对数据库简单操作

    实现数据库基本操作       数据库创建的问题解决了,接下来就该使用数据库实现应用程序功能的时候了.基本的操作包括创建.读取.更新.删除,即我们通常说的CRUD(Create, Read, Upda ...

  7. Java基础学习笔记二十三 Java核心语法之反射

    类加载器 类的加载 当程序要使用某个类时,如果该类还未被加载到内存中,则系统会通过加载,链接,初始化三步来实现对这个类进行初始化. 加载就是指将class文件读入内存,并为之创建一个Class对象.任 ...

  8. JAVA入门——Generic/泛型

    在台科大的第二次JAVA作业,老师课上讲的内容是泛型. 泛型(generic),泛型是Java SE 1.5的新特性,泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数.这种参数类型可以 ...

  9. Ubuntu登陆密码忘记

    在VMware中安装了Ubuntu 10.04,经过了一段时间,再次登录的时候居然进不去了, 一开始不知道怎样在虚拟机中进入到Grub启动界面,网上搜索了一番,按照以下步骤重新为用户设定了新密码. 重 ...

  10. "未找到应用程序的“aps-environment”的权利字符串"

    1.先生成App ID,在去Provisioning里面生成新的Profile 2.删除Xcode里面原来的push profile(如果没有就不用删除)再次双击新下载的profile(mobilep ...