关于springboot与mybatis整合出现Invalid bound statement (not found): com.llfy.demo.dao.LoginMapper.getAll问题

https://q.cnblogs.com/q/106081/

[已解决问题] 浏览: 4348次 解决于 2018-05-16 17:15 

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.llfy.demo.dao.LoginMapper">
    <resultMap id="BannerResultMap" type="com.llfy.demo.entity.Login">
        <result property="id" column="id" jdbcType="INTEGER" />
        <result property="name" column="name" jdbcType="VARCHAR" />
        <result property="password" column="password" jdbcType="VARCHAR" />
    </resultMap>
    <select id="getAll" resultType="com.llfy.demo.entity.Login">
        select * from login
    </select>
</mapper>
package com.llfy.demo.dao;

import com.llfy.demo.entity.Login;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
@Mapper
public interface LoginMapper {
    /**
     *  查询管理员列表。
     * @return
     */
    List<Login> getAll();
}

复制代码

package com.llfy.demo;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
@MapperScan("com.llfy.demo.dao")
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

复制代码

求解决。。。。。。

刘凌枫羽的主页刘凌枫羽 | 菜鸟二级 | 园豆:358
提问于:2018-05-08 13:56

< > 找找看

分享

最佳答案

0

配置扫描mapper文件的路径了吗?

例如:
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/数据库名?useSSL=false&useUnicode=true&characterEncoding=utf-8
username: root
password: wubiaowp
driver-class-name: com.mysql.jdbc.Driver
initialSize: 5
maxActive: 200
minIdle: 5
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20

mybatis:
mapper-locations: classpath:mapper/*_mapper.xml
type-aliases-package: com.util.model

奖励园豆:5

、熙和 | 小虾三级 |园豆:1481 | 2018-05-08 18:10

springboot不是支持注解吗,@MapperScan("com.llfy.demo.dao")

刘凌枫羽 | 园豆:358 (菜鸟二级) | 2018-05-08 18:16

sql使用注解是没有问题的,使用xml文件就会有这个错

刘凌枫羽 | 园豆:358 (菜鸟二级) | 2018-05-08 18:21

@刘凌枫羽: 你这个配置是扫描dao接口的; 自己看一下呀, @MapperScan("com.llfy.demo.dao"); 你的mapper文件是在resources/mapper下面的
你得告诉spring 去哪里把mapper文件加载进来 对吧?

猜你喜欢

转载自blog.csdn.net/lppl010_/article/details/88216247
今日推荐