💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 修改UserMapper ```java package com.gosuncn.dao; import com.gosuncn.entity.User; public interface UserMapper { void updateUser(User user); } ``` ### 修改UserMapper.xml ```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="com.gosuncn.dao.UserMapper"> <update id="updateUser" parameterType="com.gosuncn.entity.User"> update user set name = #{name}, age = #{age}, address = #{address} where id = #{id} </update> </mapper> ``` ### 修改MainTest ```java package com.gosuncn; import com.gosuncn.dao.UserMapper; import com.gosuncn.entity.User; 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.InputStream; public class MainTest { public static void main(String[] args) throws Exception { InputStream inputStream = Resources.getResourceAsStream("SqlMapConfig.xml"); SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream); SqlSession sqlSession = sessionFactory.openSession(); UserMapper userMapper = sqlSession.getMapper(UserMapper.class); User user = new User(); user.setId(1); user.setName("ABC"); user.setAge(26); user.setAddress("BeiJin"); userMapper.updateUser(user); sqlSession.commit(); sqlSession.close(); inputStream.close(); } } ```