1、执行流程
(1)获取全局配置文件:
//加载核心配置文件 String resource = "sqlMapConfig.xml"; InputStream in = Resources.getResourceAsStream(resource);
(2)实例化sqlSessionFactory
//创建SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);
public SqlSessionFactory build(InputStream inputStream, String environment, Properties properties) { SqlSessionFactory var5; try { XMLConfigBuilder parser = new XMLConfigBuilder(inputStream, environment, properties); var5 = this.build(parser.parse()); } catch (Exception var14) { throw ExceptionFactory.wrapException("Error building SqlSession.", var14); } finally { ErrorContext.instance().reset(); try { inputStream.close(); } catch (IOException var13) { } } return var5; }
2、Lombok的使用
Lombok项目是一个Java库,它会自动插入您的编辑器和构建工具中,从而为您的Java增光添彩。
永远不要再编写另一个getter或equals方法,带有一个注释的类将具有功能全面的生成器,自动执行日志记录变量等等。
(1)IDEA中安装插件:
(2)导入jar包:
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.10</version> </dependency>
(3)使用(在实体类中加注解):
@Data:代替无参构造、get、set、toString、hashCode、equals
import java.io.Serializable; @Data public class Student implements Serializable { private static final long serialVersionUID = 1L; private String studentno; private String sname; private String sex; private String birthday; private String classno; private String point; private String phone; private String email; private Clas clas; }
@AllArgsConstructor:有参构造:
@NoArgsConstructor:无参构造
@ToString:生成ToString方法:
EqualsAndHashCode:生成Equals和HashCode方法:
@Getter和@Setter:生成get和set方法:
(4)优缺点:
优点:提高开发效率,使代码简洁
缺点:降低了代码的阅读的舒适性