<insert id="insert" parameterType="com.example.pojo.Admin" > insert into admin (id, username, password ) values (#{id,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR} ) </insert>
时间: 2024-04-03 16:31:11 浏览: 96
这是一个Mybatis XML配置文件中的Insert语句,它的作用是向数据库的admin表中插入一条新的记录。其中,id、username、password是admin表中的列名,#{id}、#{username}、#{password}是对应列的值,jdbcType属性指定了对应列在数据库中的类型。参数类型为com.example.pojo.Admin,表示传入的参数为一个Admin对象。
相关问题
<update id="updateByPrimaryKeySelective" parameterType="com.example.pojo.Admin" > update admin <set > <if test="username != null" > username = #{username,jdbcType=VARCHAR}, </if> <if test="password != null" > password = #{password,jdbcType=VARCHAR}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <update id="updateByPrimaryKey" parameterType="com.example.pojo.Admin" > update admin set username = #{username,jdbcType=VARCHAR}, password = #{password,jdbcType=VARCHAR} where id = #{id,jdbcType=INTEGER} </update>
这是Mybatis XML配置文件中的两个Update语句。第一个Update语句的id为updateByPrimaryKeySelective,作用是根据传入的Admin对象更新admin表中对应记录的部分列,只更新非空属性。第二个Update语句的id为updateByPrimaryKey,作用是根据传入的Admin对象更新admin表中对应记录的所有列。两个语句的parameterType属性都为com.example.pojo.Admin,表示传入的参数为一个Admin对象。其中,<if>标签用于实现动态SQL,如果Admin对象的某个属性不为null,则会将对应的列更新为该属性的值。而<set>标签则用于在SET子句中动态生成列名和值的对应关系。最后,where子句用于指定更新哪条记录,根据Admin对象的id属性进行匹配。
<?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="org.pojo.UesrinfoMapper"> <select id="froUser" parameterType="Integer" resultType="org.pojo.Uesrinfo"> select * from uesrinfo </select> <insert id="intoUser" parameterType="org.pojo.Uesrinfo"> insert into uesrinfo(username,password,boo) values (#{username},#{password},#{boo}) </insert> <update id="updtUser" parameterType="org.pojo.Uesrinfo"> update uesrinfo set username=#{username},password=#{password},boo=#{boo} where id=#{id} </update> <delete id="deltUser" parameterType="Integer"> delete from uesrinfo where order=#{id} </delete> </mapper>
你的 Mapper XML 文件中 namespace 属性值为 `org.pojo.UesrinfoMapper`,而不是 `org.pojo.UserinfoMapper`。请检查你的代码中是否有拼写错误,应该修改为正确的 Mapper 文件路径:`<mapper namespace="org.pojo.UesrinfoMapper">`。同时,你的 SQL 语句中的表名也有一个拼写错误,`uesrinfo` 应该是 `userinfo`。修改后的 Mapper XML 文件如下:
```
<?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="org.pojo.UserinfoMapper">
<select id="froUser" parameterType="Integer" resultType="org.pojo.Uesrinfo">
select * from userinfo
</select>
<insert id="intoUser" parameterType="org.pojo.Uesrinfo">
insert into userinfo(username,password,boo) values (#{username},#{password},#{boo})
</insert>
<update id="updtUser" parameterType="org.pojo.Uesrinfo">
update userinfo set username=#{username},password=#{password},boo=#{boo} where id=#{id}
</update>
<delete id="deltUser" parameterType="Integer">
delete from userinfo where id=#{id}
</delete>
</mapper>
```
请注意检查 Mapper 文件路径和 SQL 语句是否都正确。
阅读全文
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)