首页 > 其他 > 详细

查询用户是否存在引发的问题

时间:2017-09-28 00:18:30      阅读:582      评论:0      收藏:0      [点我收藏+]

使用Spring+SpringMVC+MyBatis查询用户名是否存在时,返回时不要返回 *

1、因为如果这样写,当用户可用时会报一个null的错误

技术分享
1 <!-- 根据name查询用户存在与否 -->
2     <select id="findName" resultType="int" parameterType="String" >
3         select * from user where name=#{name}
4     </select>
View Code

技术分享 

$正确写法,能解决这个问题

技术分享
1 <select id="findName" resultType="int" parameterType="String" >
2     select IFNULL(sum(id),0) from user where name=#{name}
3 </select>
View Code

注意:IFNULL(sum(id),0)

作用:当未查询到数据时(即用户名可用),会返回0,而不会报上面那个错。

 

 

 

 

查询用户是否存在引发的问题

原文:http://www.cnblogs.com/gaomanito/p/7604559.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!