Mybatis中select语句引入变量报错空指针异常

Ariana_Wang 2017-12-27 11:39:31
在mapper.xml中
<select id="getStationCount1" parameterType="String" resultType="com.ciic.common.pojo.entity.StationAmount">
select new_station_amount,back_station_amount,key_station_amount
from STATION_AMOUNT
where year_id =#{year_id} and month_id =#{month_id} and branch_id = '1001'
</select>

对应的dao层接口:
StationAmount getStationCount1(String branchId);

对应的Service层:
@Override
public Map<String, Object> getStationCount1(){
Map<String, Object> sa = new HashMap<>();
StationAmount saResult = ithemeDao.getStationCount1("1");
sa.put("NewStationAmount", saResult.getNewStationAmount());
sa.put("BackStationAmount", saResult.getBackStationAmount());
sa.put("KeyStationAmount", saResult.getKeyStationAmount());
System.out.println(sa);
return sa;
}
将mapper.xml中year_id =#{year_id} and month_id =#{month_id}写成变量就报控制珍异常

刚开始接触,求大神帮忙
...全文
1187 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
9527localhost 2018-09-07
  • 打赏
  • 举报
回复
属性名与列名不一致导致的
执见 2017-12-27
  • 打赏
  • 举报
回复
将SQL语句单独测试一下,看是否正确
Sunyiban 2017-12-27
  • 打赏
  • 举报
回复
你这参数名都不一样肯定找不到啊,mapper里面的参数名要和.xml里面引用的#{}一样,否则你就用占位符: here year_id =#{0} and month_id =#{0} and branch_id = '1001' 这么写
a584429317 2017-12-27
  • 打赏
  • 举报
回复
<if test="year_id != null"> year_id =#{year_id}, </if> 这样试试,可能是你的值没有传进去
qq_41228556 2017-12-27
  • 打赏
  • 举报
回复
如果想传递两个值的话,1.可以用map装;2.可以改成StationAmount getStationCount1(@Param(‘year_id’)String yearId,@Param(‘month_id’)String monthId);
  • 打赏
  • 举报
回复
http://www.cnblogs.com/whgk/p/6718979.html 看看里面传递成 1.4 讲解 Map
qq_41228556 2017-12-27
  • 打赏
  • 举报
回复
如果你想插入的#{year_id}和#{month_id}都是传的 branchId(也就是1)的话,将名称统一为#{branchId},试试
Ariana_Wang 2017-12-27
  • 打赏
  • 举报
回复
单独SQL没问题
qq_41228556 2017-12-27
  • 打赏
  • 举报
回复
你传一个值,声明引入两个变量?

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧