Mybatis in an easy to use annotations

  1. Notes on UserMapper interface, do not write a Mapper.xml

    @Select(value = "select * from user")
    List<User> getUsers();
    
  2. Bind the interface to the core configuration file!

    <!--绑定接口-->
    <mappers>
        <mapper class="com.tt.dao.UserMapper"/>
    </mappers>
    
  3. test

	public class UserMapperTest {
	    @Test
	    public void test(){
	        SqlSession sqlSession = MyBatisUtils.getSqlSession();
	        //底层主要应用反射
	        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
	        List<User> users = mapper.getUsers();
	        for (User user : users) {
	            System.out.println(user);
	        }
	        sqlSession.close();
	    }
	}

Notes that the nature of reflection

Published 32 original articles · won praise 53 · views 2218

Guess you like

Origin blog.csdn.net/qq_41256881/article/details/105370708