3.2 链式API 多表查询

JOIN

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

INNER_JOIN 语句

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

OUTER_JOIN

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

LEFT_OUTER_JOIN

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

RIGHT_OUTER_JOIN

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

原文: https://github.com/xphsc/easyjdbc/wiki/4.2-multi-table-query