头疼程序员 2022-06-08 12:05 采纳率: 90%
浏览 50
已结题

卡了4h小时了,springboot整合mybatis

server:
  port: 9090
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/nhy?serverTimezone=GMT%2b8
    username: root
    password: 123456
mybatis:
  mapper-locations: classpath:mapper/*.xml  #扫描所有mybatis的xml文件
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
<?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.example.demo.dao.UserDao">
    <resultMap id="userSearch" type="com.example.demo.pojo.userBean">
        <id column="id" property="id"></id>
        <result column="username" property="name"></result>
        <result column="password" property="pwd"></result>
        <result column="nickname" property="nickname"></result>
        <result column="email" property="email"></result>
        <result column="phone" property="phone"></result>
        <result column="address" property="address"></result>
    </resultMap>

    <select id="search"  resultMap="userSearch">
        select * from sys_user limit #{newPageNum},#{newPageSize};
    </select>
</mapper>

//@Mapper
public interface UserDao {
   //@Select(" select * from sys_user where username like concat('%',#{username},'%') limit  #{newPageNum},#{newPageSize};")
    List<UserBean> search(@Param("newPageNum") Integer pageNum,@Param("newPageSize") Integer pageSize,String username,String address);
   // @Select("select count(*) from sys_user")
    Integer finaAll();
}

img


一启动就报错,mapper-locations: classpath:mapper/*.xml 删了就好了,只用注解的话就没问题,应该是配置文件问题
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Inject

boot用的2.7,mybatis-boot2.2

  • 写回答

3条回答 默认 最新

  • 皮蛋不吃粥 2022-06-08 12:33
    关注

    主要还是的mapper.xml的实体映射问题。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 6月16日
  • 已采纳回答 6月8日
  • 创建了问题 6月8日

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器