问答详情
源自:4-5 基于myBatis实现DAO编程(下)

SSM提取单列数据报错

Caused by: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'org.libM.dao.bookDao.getImage'.  It's likely that neither a Result Type nor a Result Map was specified.

单列数据的类型是String ,不是不用配置吗?我如果配置成实体类的话,它不就是返回一个封装的实体类?我不需要别的呀

提问者:Wings丶 2018-03-14 20:34

个回答

  • colg
    2018-04-06 01:55:28

    需要配置resultType类型的。

    String findNameById(@Param("seckillId") String seckillId);
    	<select id="findNameById" resultType="String">
    		SELECT s.name
    		FROM seckill s
    		WHERE s.seckill_id = #{seckillId}
    	</select>
    	@Test
    	public void testFindNameById() {
    		String id = "c18c12a838c311e89fa754ee75c6aeb0";
    		String name = seckillMapper.findNameById(id);
    		log.info("name:{}", name);
    	}
    执行结果:INFO cn.colg.dao.SeckillMapperTest - name:1000元秒杀iphone6