详解JAVA语言的@Select注解的情况下,重载的报错
小标 2018-07-17 来源 : 阅读 1702 评论 0

摘要:本文主要向大家介绍了详解JAVA语言的@Select注解的情况下,重载的报错,通过具体的内容向大家展示,希望对大家学习JAVA语言有所帮助。

本文主要向大家介绍了详解JAVA语言的@Select注解的情况下,重载的报错,通过具体的内容向大家展示,希望对大家学习JAVA语言有所帮助。

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

我仔细看了看代码:

 

 1     @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}")

 2     public int insertComment(Comment comment);

 3     

 4     @Select("DELETE FROM comment WHERE com_id =#{comment.com_id}")

 5     public int delCommentById(int id);

 6     

 7     @Select("DELETE FROM comment where user_name=#{comment.user_name}")

 8     public int delCommentAll(String name);

 9    

10     @Select("update comment set com_content=#{comment.com_content},com_score=#{comment.com_score}  where com_id=#{comment.com_id}")

11     public int updateComment(Comment comment);

12    

13     @Select("SELECT * FROM comment where com_pro=#{comment.com_pro}")

14     public List<Comment> findCommentAll(String proname);

15     

16     @Select("SELECT * FROM comment where com_pro=#{proname} and com_score=#{com_score}")

17     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是不支持方法重载的(如果红字不算执行结果的话)。

封印代码:

 

 1     @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}")

 2     public int insertComment(Comment comment);

 3     

 4     @Select("DELETE FROM comment WHERE com_id =#{comment.com_id}")

 5     public int delCommentById(int id);

 6     

 7     @Select("DELETE FROM comment where user_name=#{comment.user_name}")

 8     public int delCommentAll(String name);

 9     

10     @Select("update comment set com_content=#{comment.com_content},com_score=#{comment.com_score}  where com_id=#{comment.com_id}")

11     public int updateComment(Comment comment);

12     

13 //    @Select("SELECT * FROM comment where com_pro=#{comment.com_pro}")

14 //    public List<Comment> findCommentAll(String proname);

15 //    

16 //    @Select("SELECT * FROM comment where com_pro=#{proname} and com_score=#{com_score}")

17 //    public List<Comment> findCommentAll(String proname,String com_score);

 

运行我的Test:

 

1     @Test2     public void test() {3         ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");4         ActivityService ad = ctx.getBean(ActivityService.class);5         List<Activity> list = ad.findActivityAll();6         for (Activity e : list) {7             System.out.println(e.toString());8         }9     }

 

得到输出结果:

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

总结:

记者:为什么要写注解?

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

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

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

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

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

以上就是职坐标整理发布关于JAVA的介绍,先祝大家对它有了一定的了解吧,了解更多内容,请关注职坐标编程语言JAVA频道!


本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程