/** 根据主键全更新 */ @Test public void testUpdateByPrimaryKey() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { UserLoginMapper mapper = sqlSession.getMapper(UserLoginMapper.class); Map<String, Object> key = new HashMap<String, Object>(); key.put("logid", 2); key.put("username", "test1"); UserLogin userLogin = mapper.selectByPrimaryKey(key); Assert.assertNotNull(userLogin); userLogin.setLoginip("1.1.1.1"); userLogin.setLogindate(null); // 不会更新username Assert.assertEquals(1, mapper.updateByPrimaryKey(userLogin)); userLogin = mapper.selectByPrimaryKey(userLogin); Assert.assertNull(userLogin.getLogindate()); Assert.assertEquals("1.1.1.1", userLogin.getLoginip()); } finally { sqlSession.close(); } }