会报错如下
org.springframework.web.util.nestedservletexception: solicitar o processamento da solicitação; A exceção aninhada é org.apache.ibatis.binding.bindingException: Method Method 'com.bill.springmybatis.dao.userdao.getuseridbyname tentou retornar nulo de um método com um tipo de retorno primitivo (int).
org.springframework.web.servlet.frameworkservlet.processrequest (estrutura
org.springframework.web.servlet.frameworkservlet.doget (estrutura
javax.servlet.http.httpServlet.service (httpServlet.java:734)
javax.servlet.http.httpServlet.service (httpServlet.java:847)
org.springframework.web.filter.characterencodingFilter.dofilterinternal (caracterencodingfilter.java:88)
org.springframework.web.filter.onceperRequestFilter.dofilter (OncePerRequestFilter.java:76)
返回类型设置为封装类型 Inteiro 或者基本类型 int , 都有可能出错
例如
<select id = "QueryPaysum" resultType = "java.lang.integer" parameterType = "map"> selecione Sum (p.cash_fee) de pay_info p where 1 = 1 e p.trade_result_code = #{tradeResultcode} </select>我用的 Oracle 利用 nvl () 函数 解决问题 解决问题
<select id = "QueryPaysum" resultType = "java.lang.integer" parameterType = "map"> selecione nvl (sum (p.cash_fee), 0) de pay_info p onde 1 = 1 e p.trade_result_code = #{tradeResultcode} </select>补充
下面给大家在看下 : 用 isnull (), nvl (), ifnull () e coalesce () 函数替换空值
在数据库操作中 , 往往要对一些查询出来的空值进行替换 , 如函数 sum (), 这个函数如果没有值会返回 null, 这是我们不希望看到的 ,
在 Mysql 中我们可以这样来写:
Selecione ifnull (soma (dados), 0) ...
在 SQLSERVER 中我们可以这样写:
Selecione IsNull (Sum (Data), 0) ...
在 Oracle 中我们可以这样写:
Selecione NVL (Sum (Data), 0) ...
对于所有数据库适用的方法可以这样写
selecione Coalesce (soma (dados), 0) ...
Coalesce () 用法:
Coalesce (valor, ...)
返回第一个不是 null 的值 , 如果参数列表全是 nulo, null
Sseleclect Coalesce (NULL, 1); -> 1Select Coalesce (NULL, NULL, NULL); -> nulo