12 个解决方案
#1
一个参数的话不需要吧
#2
多个参数才需要吧,单个的应该不需要的
#3
一个参数不需要用@Param吧,在mybatis中定义parameterType就行吧。
#4
bean对象作为单独参数时不加@param注解的话测试就报错,加了就对了。。很神奇
#5
bean参数?lz能贴代码出来看看
#6
dao接口代码:
import org.student.entity.Student;
public interface StudentDao {
int insertStudent(@Param("student")Student student);
int delStudent(int id);
int updateStudent(@Param("student") Student student);
Student queryById(int id);
List<Student> queryAll(@Param("offset") int offset,@Param("limit") int limit);
}
mapper实现代码:
<mapper namespace="org.student.dao.StudentDao">
<insert id="insertStudent">
insert ignore into student (name,sex,grade) VALUES (#{student.name},#{student.sex},#{student.grade});
</insert>
<delete id="delStudent">
delete from student where id=#{id};
</delete>
<update id="updateStudent">
update student set name=#{student.name},sex=#{student.sex},grade=#{student.grade} where id=#{student.id};
</update>
<select id="queryById" resultType="Student">
select id,name,sex,grade from student where id=#{id};
</select>
<select id="queryAll" resultType="Student">
select id,name,sex,grade from student
order by id
limit #{offset},#{limit};
</select>
insertStudent 方法的student参数不加Param注解junit测试就会报
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'student' in 'class org.student.entity.Student'
import org.student.entity.Student;
public interface StudentDao {
int insertStudent(@Param("student")Student student);
int delStudent(int id);
int updateStudent(@Param("student") Student student);
Student queryById(int id);
List<Student> queryAll(@Param("offset") int offset,@Param("limit") int limit);
}
mapper实现代码:
<mapper namespace="org.student.dao.StudentDao">
<insert id="insertStudent">
insert ignore into student (name,sex,grade) VALUES (#{student.name},#{student.sex},#{student.grade});
</insert>
<delete id="delStudent">
delete from student where id=#{id};
</delete>
<update id="updateStudent">
update student set name=#{student.name},sex=#{student.sex},grade=#{student.grade} where id=#{student.id};
</update>
<select id="queryById" resultType="Student">
select id,name,sex,grade from student where id=#{id};
</select>
<select id="queryAll" resultType="Student">
select id,name,sex,grade from student
order by id
limit #{offset},#{limit};
</select>
insertStudent 方法的student参数不加Param注解junit测试就会报
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'student' in 'class org.student.entity.Student'
#7
是你没定义parameterType,单个的话,如果是基本类型的话,如果你不加@param的话,我记得默认是value,如果是String的话,默认的是_parameter
#8
这个试过了...去掉@Param注解 在mapper文件中定义parameteType为Student的具体包路径 然后junit测试仍然报上述错误。。。
#9
如下代码所示,dao接口中insertStudent方法没有使用@Param注解:
public interface StudentDao {
int insertStudent(Student student);
int delStudent(int id);
int updateStudent(@Param("student") Student student);
Student queryById(int id);
List<Student> queryAll(@Param("offset") int offset,@Param("limit") int limit);
}
mapper文件中insertStudent方法的实现,并在parameterType中指定了Student的具体类型:
<insert id="insertStudent" parameterType="org.student.entity.Student">
insert ignore into student (name,sex,grade) VALUES (#{student.name},#{student.sex},#{student.grade});
</insert>
junit测试代码:
@Test
public void testInsertStudent() throws Exception {
System.out.println(studentDao.insertStudent(new Student("李四",0,62)));
}
测试报错:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'student' in 'class org.student.entity.Student'
public interface StudentDao {
int insertStudent(Student student);
int delStudent(int id);
int updateStudent(@Param("student") Student student);
Student queryById(int id);
List<Student> queryAll(@Param("offset") int offset,@Param("limit") int limit);
}
mapper文件中insertStudent方法的实现,并在parameterType中指定了Student的具体类型:
<insert id="insertStudent" parameterType="org.student.entity.Student">
insert ignore into student (name,sex,grade) VALUES (#{student.name},#{student.sex},#{student.grade});
</insert>
junit测试代码:
@Test
public void testInsertStudent() throws Exception {
System.out.println(studentDao.insertStudent(new Student("李四",0,62)));
}
测试报错:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'student' in 'class org.student.entity.Student'
#10
按照楼主的写法,肯定错误,还有insert语句有问题。插入语句的values属性不需要加student.name,应该直接写成对应的数据库属性,可以改成如下:
<insert id="insert" parameterType="com.hd.model.Student" >
insert into t_student (stuid, name, sex, grade) values (#{stuid }, #{name }, #{sex }, #{grade })
</insert>
本人已测试通过,请楼主把values里面的student.去掉即可不需要加注释
<insert id="insert" parameterType="com.hd.model.Student" >
insert into t_student (stuid, name, sex, grade) values (#{stuid }, #{name }, #{sex }, #{grade })
</insert>
本人已测试通过,请楼主把values里面的student.去掉即可不需要加注释
#11
测试通过了,是我写法有问题,还是对反射理解的不够透彻,非常感谢
#12
能告知么?我也很奇怪这个问题
#1
一个参数的话不需要吧
#2
多个参数才需要吧,单个的应该不需要的
#3
一个参数不需要用@Param吧,在mybatis中定义parameterType就行吧。
#4
bean对象作为单独参数时不加@param注解的话测试就报错,加了就对了。。很神奇
#5
bean参数?lz能贴代码出来看看
#6
dao接口代码:
import org.student.entity.Student;
public interface StudentDao {
int insertStudent(@Param("student")Student student);
int delStudent(int id);
int updateStudent(@Param("student") Student student);
Student queryById(int id);
List<Student> queryAll(@Param("offset") int offset,@Param("limit") int limit);
}
mapper实现代码:
<mapper namespace="org.student.dao.StudentDao">
<insert id="insertStudent">
insert ignore into student (name,sex,grade) VALUES (#{student.name},#{student.sex},#{student.grade});
</insert>
<delete id="delStudent">
delete from student where id=#{id};
</delete>
<update id="updateStudent">
update student set name=#{student.name},sex=#{student.sex},grade=#{student.grade} where id=#{student.id};
</update>
<select id="queryById" resultType="Student">
select id,name,sex,grade from student where id=#{id};
</select>
<select id="queryAll" resultType="Student">
select id,name,sex,grade from student
order by id
limit #{offset},#{limit};
</select>
insertStudent 方法的student参数不加Param注解junit测试就会报
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'student' in 'class org.student.entity.Student'
import org.student.entity.Student;
public interface StudentDao {
int insertStudent(@Param("student")Student student);
int delStudent(int id);
int updateStudent(@Param("student") Student student);
Student queryById(int id);
List<Student> queryAll(@Param("offset") int offset,@Param("limit") int limit);
}
mapper实现代码:
<mapper namespace="org.student.dao.StudentDao">
<insert id="insertStudent">
insert ignore into student (name,sex,grade) VALUES (#{student.name},#{student.sex},#{student.grade});
</insert>
<delete id="delStudent">
delete from student where id=#{id};
</delete>
<update id="updateStudent">
update student set name=#{student.name},sex=#{student.sex},grade=#{student.grade} where id=#{student.id};
</update>
<select id="queryById" resultType="Student">
select id,name,sex,grade from student where id=#{id};
</select>
<select id="queryAll" resultType="Student">
select id,name,sex,grade from student
order by id
limit #{offset},#{limit};
</select>
insertStudent 方法的student参数不加Param注解junit测试就会报
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'student' in 'class org.student.entity.Student'
#7
是你没定义parameterType,单个的话,如果是基本类型的话,如果你不加@param的话,我记得默认是value,如果是String的话,默认的是_parameter
#8
这个试过了...去掉@Param注解 在mapper文件中定义parameteType为Student的具体包路径 然后junit测试仍然报上述错误。。。
#9
如下代码所示,dao接口中insertStudent方法没有使用@Param注解:
public interface StudentDao {
int insertStudent(Student student);
int delStudent(int id);
int updateStudent(@Param("student") Student student);
Student queryById(int id);
List<Student> queryAll(@Param("offset") int offset,@Param("limit") int limit);
}
mapper文件中insertStudent方法的实现,并在parameterType中指定了Student的具体类型:
<insert id="insertStudent" parameterType="org.student.entity.Student">
insert ignore into student (name,sex,grade) VALUES (#{student.name},#{student.sex},#{student.grade});
</insert>
junit测试代码:
@Test
public void testInsertStudent() throws Exception {
System.out.println(studentDao.insertStudent(new Student("李四",0,62)));
}
测试报错:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'student' in 'class org.student.entity.Student'
public interface StudentDao {
int insertStudent(Student student);
int delStudent(int id);
int updateStudent(@Param("student") Student student);
Student queryById(int id);
List<Student> queryAll(@Param("offset") int offset,@Param("limit") int limit);
}
mapper文件中insertStudent方法的实现,并在parameterType中指定了Student的具体类型:
<insert id="insertStudent" parameterType="org.student.entity.Student">
insert ignore into student (name,sex,grade) VALUES (#{student.name},#{student.sex},#{student.grade});
</insert>
junit测试代码:
@Test
public void testInsertStudent() throws Exception {
System.out.println(studentDao.insertStudent(new Student("李四",0,62)));
}
测试报错:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'student' in 'class org.student.entity.Student'
#10
按照楼主的写法,肯定错误,还有insert语句有问题。插入语句的values属性不需要加student.name,应该直接写成对应的数据库属性,可以改成如下:
<insert id="insert" parameterType="com.hd.model.Student" >
insert into t_student (stuid, name, sex, grade) values (#{stuid }, #{name }, #{sex }, #{grade })
</insert>
本人已测试通过,请楼主把values里面的student.去掉即可不需要加注释
<insert id="insert" parameterType="com.hd.model.Student" >
insert into t_student (stuid, name, sex, grade) values (#{stuid }, #{name }, #{sex }, #{grade })
</insert>
本人已测试通过,请楼主把values里面的student.去掉即可不需要加注释
#11
测试通过了,是我写法有问题,还是对反射理解的不够透彻,非常感谢
#12
能告知么?我也很奇怪这个问题