美文网首页
2023-12-02 多表映射 lombok/BeforeEa

2023-12-02 多表映射 lombok/BeforeEa

作者: 大也 | 来源:发表于2023-12-08 10:20 被阅读0次

-- ---------------------- lombok
-- ---------------------- BeforeEach/AfterEach 使用

https://blog.csdn.net/weixin_45837888/article/details/123228086
Lombok requires enabled annotation processing

image.png

多表映射 的一些概念
实体类设计:对一关系下,类中只要包含单个对方对象类型属性即可!
实体类设计:对多关系下,类中只要包含对方类型集合属性即可!
只有真实发生多表查询时,才需要设计和修改实体类,否则不提前设计和修改实体类!
无论多少张表联查,实体类设计都是两两考虑!
在查询映射的时候,只需要关注本次查询相关的属性!例如:查询订单和对应的客户,就不要关注客户中的订单集合!

  1. lombok
    @Data
    public class User {
    private Integer id;
    private String username;
    private String password;
    }

/**

  • 插件市场 lombok
  • <dependency>
  • <groupId>org.projectlombok</groupId>
  • <artifactId>lombok</artifactId>
  • <version>RELEASE</version>
  • <scope>compile</scope>
  • </dependency>
  • <dependency>
  • <groupId>org.projectlombok</groupId>
  • <artifactId>lombok</artifactId>
  • <version>1.18.28</version>
  • </dependency>
    */

private SqlSession sqlSession;

@BeforeEach
public void test() throws IOException {
    /**
     *  1.获取 根据 配置地址 获取 io流
     *  2.获取 会话工厂创建者实体类 创建会话工厂 通过会话工厂 拿到会话实体类
     *  3.通过会话实体类 拿到模型代理对象
     *  4.调用代理方法
     *  5.提交关闭会话
     * */
    String resource = "com.atguigu/mybatis-config/mybatis-config.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    sqlSession = new SqlSessionFactoryBuilder().build(inputStream).openSession();

// EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class) ;
// Employee employee = employeeMapper.selectEmployee(1);
// System.out.println("employee"+ employee);
// sqlSession.close();
}

@AfterEach //每次走测试方法之后调用的方法!
public void clean(){
    sqlSession.commit();;
    sqlSession.close();
}

相关文章

网友评论

      本文标题:2023-12-02 多表映射 lombok/BeforeEa

      本文链接:https://www.haomeiwen.com/subject/qhdcgdtx.html