@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);
当我运行代码的时候,就会就收到如下错误:
严重: 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注解的情况下,重载的报错的更多相关文章
- [Android自动化] 在 pip-9.0.1 版本情况下安装 uiautomator2 报错的解决办法
1.在命令窗口中使用命令: pip install uiautomator2 时报 pip 版本过低,需要先升级 pip 版本,理论上会按照提示进行升级 pip 操作,但执行升级命令时到最后却还是报错 ...
- linux 下 tomcat 运行报错 Broken pipe
linux 下 tomcat 运行报错 Broken pipe 感谢:http://hi.baidu.com/liupenglover/blog/item/4048c23ff19f1cd67d1e71 ...
- 【转】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 ...
- [转]解决IIS下UTF-8文件报错乱码的问题
找了两天才找到解决办法…….晕晕晕...用第二种方法解决了. 网上找到的方法都没有写这一条 If objASPError.ASPDescription > "" Then 后 ...
- [原创] 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 ...
- mac下brew install 报错
mac下brew install 报错 错误提示: 原因:是这个brew的权限不正确 修改一下这个brew的权限 chown root:wheel /usr/local/bin/brew
- Linux下Oracle11G RAC报错:在安装oracle软件时报file not found一例
Linux下Oracle11G RAC报错:在安装oracle软件时报file notfound一例 1.现象 之前安装一切都比較顺利,安装oracle软件时,进度到30%时报错:file not f ...
- Linux系统下启动MySQL报错:Neither host 'localhost.localdomain' nor 'localhost' could be looked up with
Linux系统下启动MySQL报错:Neither host 'localhost.localdomain' nor 'localhost' could be looked up with 摘要 Li ...
- 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 解决: 如果没有配置环境,在安 ...
随机推荐
- 20165226 学习基础和C语言基础调查
心得体会 驱动迭代 学习是一个老师与学生互动的过程,二者关系又恰如健身教练与学员,在进行基础知识的培训后还需借助工具加强相关方面的训练.学习提升的过程离不开学生在实践中发现问题并在老师的帮助下解决问题 ...
- gdb命令调试技巧
gdb命令调试技巧 一.信息显示1.显示gdb版本 (gdb) show version2.显示gdb版权 (gdb) show version or show warranty3.启动时不显示提示信 ...
- Netty实现客户端和服务端通信简单例子
Netty是建立在NIO基础之上,Netty在NIO之上又提供了更高层次的抽象. 在Netty里面,Accept连接可以使用单独的线程池去处理,读写操作又是另外的线程池来处理. Accept连接和读写 ...
- DB2开发系列之一——基本语法
最近看了些db2开发方面的资料,现做摘要,以供自己和大家参考: 1.变量声明 DECLARE v_salary DEC(9,2) DEFAULT 0.0; DECLARE v_status char( ...
- equals和hashCode详解
equals和hashCode详解 http://www.cnblogs.com/Qian123/p/5703507.html
- 17.C++-string字符串类(详解)
C++字符串string类 在C语言里,字符串是用字符数组来表示的,而对于应用层而言,会经常用到字符串,而继续使用字符数组,就使得效率非常低. 所以在C++标准库里,通过类string从新自定义了字符 ...
- linux --> 计算机是如何启动的?
计算机是如何启动的? 零.boot的含义 "启动"用英语怎么说?回答是boot.boot原来的意思是靴子,"启动"与靴子有什么关系呢? 原来,这里的boot是b ...
- echarts图表变形解决方案
在同一页面的多个echarts图在查询或切换图片时可能会变形,如图 解决方案是添加以下几行代码 /*在查询或切换统计图时图片有可能会变形,于是每次调getEchartsData()都给每个chart的 ...
- linux小白成长之路9————打包部署SpringBoot项目
[内容指引] SpringBoot项目介绍: 打包SpringBoot项目: 1.pom.xml: 2.application.properties配置: 3.application-dev.prop ...
- Redux----Regular的Redux实现整理
Regular的Redux实现整理 什么问题? 组件的树形结构决定了数据的流向,导致的数据传递黑洞 怎么解决? 所有组件都通过中介者传递共享数据 方案: 中介者: (function create ...