多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
### 修改UserMapper ```java package com.gosuncn.dao; public interface UserMapper { void deleteUser(Integer id); } ``` ### 修改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="deleteUser" parameterType="java.lang.Integer"> delete from user where id = #{id} </update> </mapper> ``` > 只有一个参数的情况,`#{id}`中什么都可以写,不仅仅局限于`id`,因为它是没有意义的。 ### 修改MainTest ```java package com.gosuncn; import com.gosuncn.dao.UserMapper; 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); userMapper.deleteUser(1); sqlSession.commit(); sqlSession.close(); inputStream.close(); } } ```