test.java public static void main(String[] args) throws Exception{String resource="mybatis.xml";InputStream inputStream=Resources.getResourceAsStream(resource);SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputSt
public static void main(String[] args) throws Exception{ String resource="mybatis.xml"; InputStream inputStream=Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream); SqlSession session=sqlSessionFactory.openSession(); System.out.println(session); UserInfo info=session.selectOne("user.getUsersById",101); info.setPwd("a"); session.update("user.update",info); System.out.println(info); UserInfo info2=new UserInfo(105,"abc","123",2); session.insert("user.add",info2); session.update("user.update",info); session.delete("user.deleteById",105); // Mapmapper.xmlmap=new HashMap (); // map.put("id", 104); // map.put("name", "aaa"); // map.put("pwd", "123"); // map.put("rolesid", 2); //// session.insert("user.add",map); // System.out.print(session.insert("user.selectBySql",map)); System.out.println(session.selectOne("user.getUsersById",104)); // Map map=new HashMap (); map.put("sql", "select * from userinfo"); List list=session.selectList("user.selectBySql", map); for (UserInfo userInfo : list) { System.out.println(userInfo); } session.commit(); session.close(); } }
insert into userinfo values(#{id},#{name},#{pwd},#{rolesid}) delete userinfo where id=#{id} update userinfo set name=#{name},pwd=#{pwd},rolesid=#{rolesid} where id=#{id}