<?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); } }
配置扫描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
springboot不是支持注解吗,@MapperScan("com.llfy.demo.dao")
sql使用注解是没有问题的,使用xml文件就会有这个错
@刘凌枫羽: 你这个配置是扫描dao接口的; 自己看一下呀, @MapperScan("com.llfy.demo.dao"); 你的mapper文件是在resources/mapper下面的
你得告诉spring 去哪里把mapper文件加载进来 对吧?
resultMap="BannerResultMap" 你返回的是list,应该这么写吧
这个并没有解决问题,应该不是
最后怎么解决的啊
////////