鱼C论坛

 找回密码
 立即注册
查看: 561|回复: 7

[已解决]这个对象为什么创建不了

[复制链接]
发表于 2024-4-8 15:42:36 | 显示全部楼层 |阅读模式
30鱼币
本帖最后由 孤世星辰 于 2024-4-8 19:09 编辑
E:\JAVAJDK\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:E:\IDEA Community\IntelliJ IDEA Community Edition 2021.3.1\lib\idea_rt.jar=50939:E:\IDEA Community\IntelliJ IDEA Community Edition 2021.3.1\bin" -Dfile.encoding=UTF-8 -classpath "E:\IDEA Community\IntelliJ IDEA Community Edition 2021.3.1\lib\idea_rt.jar;E:\IDEA Community\IntelliJ IDEA Community Edition 2021.3.1\plugins\junit\lib\junit5-rt.jar;E:\IDEA Community\IntelliJ IDEA Community Edition 2021.3.1\plugins\junit\lib\junit-rt.jar;E:\JAVAJDK\jre\lib\charsets.jar;E:\JAVAJDK\jre\lib\deploy.jar;E:\JAVAJDK\jre\lib\ext\access-bridge-64.jar;E:\JAVAJDK\jre\lib\ext\cldrdata.jar;E:\JAVAJDK\jre\lib\ext\dnsns.jar;E:\JAVAJDK\jre\lib\ext\jaccess.jar;E:\JAVAJDK\jre\lib\ext\jfxrt.jar;E:\JAVAJDK\jre\lib\ext\localedata.jar;E:\JAVAJDK\jre\lib\ext\nashorn.jar;E:\JAVAJDK\jre\lib\ext\sunec.jar;E:\JAVAJDK\jre\lib\ext\sunjce_provider.jar;E:\JAVAJDK\jre\lib\ext\sunmscapi.jar;E:\JAVAJDK\jre\lib\ext\sunpkcs11.jar;E:\JAVAJDK\jre\lib\ext\zipfs.jar;E:\JAVAJDK\jre\lib\javaws.jar;E:\JAVAJDK\jre\lib\jce.jar;E:\JAVAJDK\jre\lib\jfr.jar;E:\JAVAJDK\jre\lib\jfxswt.jar;E:\JAVAJDK\jre\lib\jsse.jar;E:\JAVAJDK\jre\lib\management-agent.jar;E:\JAVAJDK\jre\lib\plugin.jar;E:\JAVAJDK\jre\lib\resources.jar;E:\JAVAJDK\jre\lib\rt.jar;C:\Users\a2032\Desktop\JAVA cod\mybatis_study\myabtis-1\target\test-classes;C:\Users\a2032\Desktop\JAVA cod\mybatis_study\myabtis-1\target\classes;C:\Users\a2032\.m2\repository\mysql\mysql-connector-java\5.1.47\mysql-connector-java-5.1.47.jar;C:\Users\a2032\.m2\repository\org\mybatis\mybatis\3.5.2\mybatis-3.5.2.jar;C:\Users\a2032\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\a2032\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 com.zwl.dao.UserDaoTest,test

java.lang.ExceptionInInitializerError
        at com.zwl.dao.UserDaoTest.test(UserDaoTest.java:13)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
        at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
        at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
        at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
        at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
        at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in com/zwl/dao/UserMapper.java (best guess)
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.zwl.dao.UserMapper.GetUserList. please check com/zwl/dao/UserMapper.xml and com/zwl/dao/UserMapper.java (best guess)
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
        at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
        at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
        at com.zwl.utils.MybatisUtils.<clinit>(MybatisUtils.java:18)
        ... 25 more
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.zwl.dao.UserMapper.GetUserList. please check com/zwl/dao/UserMapper.xml and com/zwl/dao/UserMapper.java (best guess)
        at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121)
        at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:98)
        at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78)
        ... 27 more
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.zwl.dao.UserMapper.GetUserList. please check com/zwl/dao/UserMapper.xml and com/zwl/dao/UserMapper.java (best guess)
        at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:947)
        at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:903)
        at org.apache.ibatis.session.Configuration.addMappedStatement(Configuration.java:702)
        at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:297)
        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parseStatement(MapperAnnotationBuilder.java:358)
        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:139)
        at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:72)
        at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:775)
        at org.apache.ibatis.builder.xml.XMLMapperBuilder.bindMapperForNamespace(XMLMapperBuilder.java:436)
        at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:96)
        at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:374)
        at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:119)
        ... 29 more


Process finished with exit code -1
package com.zwl.dao;

import com.zwl.pojo.User;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserMapper {

    @Select("select * from user")
    List<User> getUserList();
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zwl.dao.UserMapper">
   <select id="getUserList" resultType="com.zwl.pojo.User">
       select * from mybaits.User
   </select>

</mapper>
package com.zwl.pojo;

public class User {
   private int id;
    private String name;
    private String pwd;

    public User() {
    }

    public User(int id, String name, String pwd) {
        this.id = id;
        this.name = name;
        this.pwd = pwd;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", pwd='" + pwd + '\'' +
                '}';
    }
}
package com.zwl.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

//sqlSessionFactory-->sqlSession
public class MybatisUtils {
    private static SqlSessionFactory sqlSessionFactory;
    static {
        try {
            String resource = "Mybatis-config.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static SqlSession getSqlSession(){
        return sqlSessionFactory.openSession();
    }

}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/mysql/mybaits?useSSL=true&useUnicode=true&characterEncoding=UTF8"/>
                <property name="username" value="root"/>
                <property name="password" value="18870025610"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>
        <mapper resource="com/zwl/dao/UserMapper.xml"/>
    </mappers>
</configuration>
package com.zwl.dao;

import com.zwl.pojo.User;
import com.zwl.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class UserDaoTest {
    @Test
    public void test(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> usersist = mapper.getUserList();
        for (User user : usersist) {
            System.out.println(user);
        }

        sqlSession.close();

    }
}

捕获.PNG
最佳答案
2024-4-8 15:42:37
本帖最后由 holistic杀手 于 2024-10-1 16:42 编辑

你的错误是既写了注解的sql语句,又写了mapper的sql语句,你把@select(......)接口的这个sql删了就行

最佳答案

查看完整内容

你的错误是既写了注解的sql语句,又写了mapper的sql语句,你把@select(......)接口的这个sql删了就行
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2024-4-8 15:42:37 | 显示全部楼层    本楼为最佳答案   
本帖最后由 holistic杀手 于 2024-10-1 16:42 编辑

你的错误是既写了注解的sql语句,又写了mapper的sql语句,你把@select(......)接口的这个sql删了就行
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2024-4-8 15:42:56 | 显示全部楼层
根据你提供的错误信息和代码,问题出在`UserMapper`接口和`UserMapper.xml`文件的定义上。错误提示中指出 `Mapped Statements collection already contains value for com.zwl.dao.UserMapper.GetUserList.` 这意味着在同一个接口中重复定义了相同的方法。

解决办法是,检查你的`UserMapper`接口和对应的`UserMapper.xml`文件,确保没有重复定义相同的方法。根据你提供的代码,你可以尝试将`UserMapper`接口中的`GetUserList()`方法重命名为`getUserList()`(注意首字母小写),然后在`UserMapper.xml`文件中对应的SQL语句也做相应的修改。

修改后的`UserMapper`接口如下:
package com.zwl.dao;

import com.zwl.pojo.User;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserMapper {

    @Select("select * from user")
    List<User> getUserList();
}

然后,在`UserMapper.xml`文件中,将SQL语句修改为:
<select id="getUserList" resultType="com.zwl.pojo.User">
  select * from user
</select>

同时,确保`UserMapper.xml`文件的命名空间和接口路径一致,即:`com.zwl.dao.UserMapper`。

这样修改之后,重新运行你的测试代码即可。希望能帮到你!

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2024-4-8 16:25:21 | 显示全部楼层
FishC 发表于 2024-4-8 15:42
根据你提供的错误信息和代码,问题出在`UserMapper`接口和`UserMapper.xml`文件的定义上。错误提示中指出 ` ...
E:\JAVAJDK\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:E:\IDEA Community\IntelliJ IDEA Community Edition 2021.3.1\lib\idea_rt.jar=59138:E:\IDEA Community\IntelliJ IDEA Community Edition 2021.3.1\bin" -Dfile.encoding=UTF-8 -classpath "E:\IDEA Community\IntelliJ IDEA Community Edition 2021.3.1\lib\idea_rt.jar;E:\IDEA Community\IntelliJ IDEA Community Edition 2021.3.1\plugins\junit\lib\junit5-rt.jar;E:\IDEA Community\IntelliJ IDEA Community Edition 2021.3.1\plugins\junit\lib\junit-rt.jar;E:\JAVAJDK\jre\lib\charsets.jar;E:\JAVAJDK\jre\lib\deploy.jar;E:\JAVAJDK\jre\lib\ext\access-bridge-64.jar;E:\JAVAJDK\jre\lib\ext\cldrdata.jar;E:\JAVAJDK\jre\lib\ext\dnsns.jar;E:\JAVAJDK\jre\lib\ext\jaccess.jar;E:\JAVAJDK\jre\lib\ext\jfxrt.jar;E:\JAVAJDK\jre\lib\ext\localedata.jar;E:\JAVAJDK\jre\lib\ext\nashorn.jar;E:\JAVAJDK\jre\lib\ext\sunec.jar;E:\JAVAJDK\jre\lib\ext\sunjce_provider.jar;E:\JAVAJDK\jre\lib\ext\sunmscapi.jar;E:\JAVAJDK\jre\lib\ext\sunpkcs11.jar;E:\JAVAJDK\jre\lib\ext\zipfs.jar;E:\JAVAJDK\jre\lib\javaws.jar;E:\JAVAJDK\jre\lib\jce.jar;E:\JAVAJDK\jre\lib\jfr.jar;E:\JAVAJDK\jre\lib\jfxswt.jar;E:\JAVAJDK\jre\lib\jsse.jar;E:\JAVAJDK\jre\lib\management-agent.jar;E:\JAVAJDK\jre\lib\plugin.jar;E:\JAVAJDK\jre\lib\resources.jar;E:\JAVAJDK\jre\lib\rt.jar;C:\Users\a2032\Desktop\JAVA cod\mybatis_study\myabtis-1\target\test-classes;C:\Users\a2032\Desktop\JAVA cod\mybatis_study\myabtis-1\target\classes;C:\Users\a2032\.m2\repository\mysql\mysql-connector-java\5.1.47\mysql-connector-java-5.1.47.jar;C:\Users\a2032\.m2\repository\org\mybatis\mybatis\3.5.2\mybatis-3.5.2.jar;C:\Users\a2032\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\a2032\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 com.zwl.dao.UserDaoTest,test

java.lang.ExceptionInInitializerError
        at com.zwl.dao.UserDaoTest.test(UserDaoTest.java:13)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
        at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
        at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
        at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
        at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
        at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in com/zwl/dao/UserMapper.java (best guess)
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.zwl.dao.UserMapper.getUserList. please check com/zwl/dao/UserMapper.xml and com/zwl/dao/UserMapper.java (best guess)
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
        at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
        at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
        at com.zwl.utils.MybatisUtils.<clinit>(MybatisUtils.java:18)
        ... 25 more
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.zwl.dao.UserMapper.getUserList. please check com/zwl/dao/UserMapper.xml and com/zwl/dao/UserMapper.java (best guess)
        at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121)
        at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:98)
        at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78)
        ... 27 more
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.zwl.dao.UserMapper.getUserList. please check com/zwl/dao/UserMapper.xml and com/zwl/dao/UserMapper.java (best guess)
        at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:947)
        at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:903)
        at org.apache.ibatis.session.Configuration.addMappedStatement(Configuration.java:702)
        at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:297)
        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parseStatement(MapperAnnotationBuilder.java:358)
        at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:139)
        at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:72)
        at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:775)
        at org.apache.ibatis.builder.xml.XMLMapperBuilder.bindMapperForNamespace(XMLMapperBuilder.java:436)
        at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:96)
        at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:374)
        at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:119)
        ... 29 more


Process finished with exit code -1

修改之后这样了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2024-4-8 16:25:45 | 显示全部楼层
孤世星辰 发表于 2024-04-08 16:25
E:\JAVAJDK\bin\java.exe -ea -Didea.test.cyclic.buf ...


根据你提供的错误信息和代码,问题出在`UserMapper`接口和`UserMapper.xml`文件的定义上。错误提示中指出 `Mapped Statements collection already contains value for com.zwl.dao.UserMapper.getUserList.` 这意味着在同一个接口中重复定义了相同的方法。

解决办法是,检查你的`UserMapper`接口和对应的`UserMapper.xml`文件,确保没有重复定义相同的方法。根据你提供的代码,你可以尝试将`UserMapper`接口中的`getUserList()`方法重命名为`getUserList2()`(或其他不重复的名称),然后在`UserMapper.xml`文件中对应的SQL语句也做相应的修改。修改后的`UserMapper`接口如下:
package com.zwl.dao;

import com.zwl.pojo.User;
import org.apache.ibatis.annotations.Select;
import java.util.List;

public interface UserMapper {
    @Select("select * from user")
    List<User> getUserList2();
}

然后,在`UserMapper.xml`文件中,将SQL语句修改为:
<select id="getUserList2" resultType="com.zwl.pojo.User">
    select * from user
</select>

同时,确保`UserMapper.xml`文件的命名空间和接口路径一致,即:`com.zwl.dao.UserMapper`。

这样修改之后,重新运行你的测试代码即可。希望能帮到你!

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2024-4-8 19:08:24 | 显示全部楼层
FishC 发表于 2024-4-8 16:25
根据你提供的错误信息和代码,问题出在`UserMapper`接口和`UserMapper.xml`文件的定义上。错误提示中指 ...

还是一样的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2024-4-8 19:08:40 | 显示全部楼层


根据你提供的错误信息和代码,问题出在`UserMapper`接口和`UserMapper.xml`文件的定义上。错误提示中指出 `Mapped Statements collection already contains value for com.zwl.dao.UserMapper.getUserList.` 这意味着在同一个接口中重复定义了相同的方法。

问题可能出在你的`UserMapper.xml`文件中重复定义了同一个方法。请检查你的`UserMapper.xml`文件,确保只有一个`select`语句定义了`com.zwl.dao.UserMapper.getUserList`。

另外,还要注意确保`UserMapper`接口和`UserMapper.xml`文件的命名空间和路径一致,即`com.zwl.dao.UserMapper`。

如果你仍然遇到相同的问题,可以考虑重新构建整个项目,确保所有依赖库和配置文件都正确引入,并且没有重复定义的问题。

希望能帮到你!

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-12-22 02:29

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表