会报错如下 :
org.springframework.web.util.nestedservletException: el procesamiento de solicitudes fallido; La excepción anidada es org.apache.ibatis.binding.BindingException: Mapper Method 'com.bill.springmybatis.dao.userdao.getuseridbyname intentó devolver nulo de un método con un tipo de retorno primitivo (int).
org.springframework.web.servlet.frameworkservlet.processrequest (frameworkservlet.java:894)
org.springframework.web.servlet.frameworkservlet.doget (frameworkservlet.java:778)
javax.servlet.http.httpservlet.service (httpservlet.java:734)
javax.servlet.http.httpservlet.service (httpservlet.java:847)
org.springframework.web.filter.CharacterEncodingFilter.DofilterInternal (caracteresCodingFilter.Java:88)
org.springframework.web.filter.onceperRequestFilter.dofilter (OnceperRequestFilter.java:76)
返回类型设置为封装类型 Integer 或者基本类型 int , 都有可能出错
例如
<select id = "QUYPAYSUM" resultType = "java.lang.integer" parametertype = "map"> select sum (p.cash_fee) de pay_info p donde 1 = 1 y p.trade_result_code = #{comerceSultcode} </select>我用的 Oracle 利用 nvl () 函数 解决问题
<select id = "QUYPAYSUM" resultType = "java.lang.integer" parametertype = "map"> select nvl (sum (p.cash_fee), 0) de pay_info p donde 1 = 1 y p.trade_result_code = #{comercianteSultcode} </sect>补充 :
下面给大家在看下 : 用 isnull (), nvl (), ifNull () y coalesesce () 函数替换空值
在数据库操作中 , 往往要对一些查询出来的空值进行替换 , 如函数 sum (), 这个函数如果没有值会返回 nulo, 这是我们不希望看到的 ,
在 mysql 中我们可以这样来写 :
Seleccione IfNull (suma (datos), 0) ...
在 SQLServer 中我们可以这样写 :
Seleccione ISNULL (suma (datos), 0) ...
在 Oracle 中我们可以这样写 :
Seleccione NVL (suma (datos), 0) ...
对于所有数据库适用的方法可以这样写 :
Seleccione Coalesce (suma (datos), 0) ...
Coalese () 用法 :
Fusionar (valor, ...)
返回第一个不是 NULL 的值 , 如果参数列表全是 如果参数列表全是 NULL, 则返回 NULL
sselect falesce (nulo, 1); -> 1Select Coalesce (NULL, NULL, NULL); -> nulo