头疼程序员 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 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加