Scala + Mybatis 传参问题
徐老师您好:
在完成 5-5 学习任务的过程中
结合Mybatis向数据库写入数据时, 将 "word" , "count" 封装到Map集合中并传递给了SqlSession对象的update方法. 用Java写的程序执行后数据正常写入到了数据库, 而Scala写的程序执行过程中发生如下错误信息:
Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'word' in 'class scala.collection.immutable.Map$Map2'
对应的Java, Scala代码如下, 望老师给予纠正
谢谢
Java
.foreachPartition(new VoidFunction<Iterator<Tuple2<String, Integer>>>() {
@Override
public void call(Iterator<Tuple2<String, Integer>> it) throws Exception {
SqlSession session = getSession();
while (it.hasNext()) {
Tuple2<String, Integer> tup = it.next();
Map map = new HashMap<>();
map.put("word", tup._1);
map.put("count", tup._2);
session.update("WordCountMapper.insert", map);
}
}Scala
val dataRDD: RDD[String] = sc.parallelize(Array("hello you", "hello me"))
dataRDD.flatMap(_.split(" "))
.map(word => (word, 1))
.reduceByKey(_ + _)
.sortByKey()
.foreachPartition(it => {
val session = getSession()
it.foreach(tup => {
val map = Map("word" -> tup._1, "count" -> tup._2)
session.update("WordCountMapper.insert", map)
})
})5
收起
正在回答 回答被采纳积分+1
1回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星