Skip to content

4.2 multi table query

xphsc edited this page Jul 9, 2018 · 1 revision

3.2 链式API 多表查询

JOIN

 List<User> users = easyJdbcTemplate.selector()
        .SELECT("u.user_name")
        .FROM("t_user   u")
        .JOIN("t_user1 u1 on u1.uid = u.id")//JOIN语句
        .WHERE("u.user_name=?")
        .entityClass(User.class)
        .parameters("张三")
        .list();

INNER_JOIN 语句

 List<User> users = easyJdbcTemplate.selector()
        .SELECT("u.user_name")
        .FROM("t_user   u")
        .INNER_JOIN("t_user1 u1 on u1.uid = u.id")//innerJoin语句
        .WHERE("u.user_name=?")
        .entityClass(User.class)
        .parameters("张三")
        .list();

OUTER_JOIN

 List<User> users = easyJdbcTemplate.selector()
        .SELECT("u.user_name")
        .FROM("t_user   u")
        .OUTER_JOIN("t_user1 u1 on u1.uid = u.id") //OUTER_JOIN语句
        .WHERE("u.user_name=?")
        .entityClass(User.class)
        .parameters("张三")
        .list();

LEFT_OUTER_JOIN

List<User> users = easyJdbcTemplate.selector()
        .SELECT("u.user_name")
        .FROM("t_user   u")
        .LEFT_OUTER_JOIN("t_user1 u1 on u1.uid = u.id")//LEFT_OUTER_JOIN语句
        .WHERE("u.user_name=?")
        .entityClass(User.class)
        .parameters("张三")
        .list();

RIGHT_OUTER_JOIN

List<User> users = easyJdbcTemplate.selector()
        .SELECT("u.user_name")
        .FROM("t_user   u")
        .RIGHT_OUTER_JOIN("t_user1 u1 on u1.uid = u.id")//RIGHT_OUTER_JOIN语句
        .WHERE("u.user_name=?")
        .entityClass(User.class)
        .parameters("张三")
        .list();