面试资料整理汇总
这些面试题是我朋友进阿里前狂刷七遍以上的面试资料,由于面试文档很多,内容更多,没有办法一一为大家展示出来,所以只好为大家节选出来了一部分供大家参考。
面试的本质不是考试,而是告诉面试官你会做什么,所以,这些面试资料中提到的技术也是要学会的,不然稍微改动一下你就凉凉了
在这里祝大家能够拿到心仪的offer!
close(conn,ps,rs);
}
return null;
}
/**
-
关闭资源的通用方法
-
*/
public static void close(Connection conn,Statement stat,ResultSet rs){
try{
if(rs!=null){
rs.close();
}
if(stat!=null){
stat.close();
}
if(conn!=null){
conn.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
}
自定义配置文件版
public class BaseDao {
// 配置集合
public static Properties properties = new Properties();
// 加载驱动
static {
// 集合对象加载数据
InputStream is = BaseDao.class.getResourceAsStream(“data.properties”);
try {
properties.load(is);
} catch (IOException e) {
e.printStackTrace();
}
// 获取配置中的数据,从集合中获取
String driver = properties.getProperty(“driver”);
// 加载jdbc驱动
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
// 获取连接对象
public Connection getConnection() {
// 获取配置中的数据,从集合中获取
String url = properties.getProperty(“url”);
String user = properties.getProperty(“user”);
String pwd = properties.getProperty(“pwd”);
// 获取连接对象
Connection connection = null;
try {
connection = DriverManager.getConnection(url, user, pwd);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
// 返回连接对象
return connection;
}
// 关闭资源
public void closeAll(Connection connection, Statement statement, ResultSet resultSet) {
// 按顺序删除
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
//通用的增删改
public int commonUpdate(String sql, Object[] objects) {
// 获取连接对象
Connection connection = getConnection();
// 构建执行者
PreparedStatement preparedStatement = null;
try {
preparedStatement = connection.prepareStatement(sql);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
// 填入数据
for (int i = 0; i < objects.length; i++) {
try {
preparedStatement.setObject(i + 1, objects[i]);
// preparedStatement.setNull(位置, Types.INTEGER);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
// 执行语句
int i = 0;
try {
i = preparedStatement.executeUpdate();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
// 返回受景响的行数
return i;
}
// 通用查询
public ResultSet commonSelect(String sql, Object[] objects) {
// 定义一个返回值
ResultSet resultSet = null;
// 获取连接对象
Connection connection = getConnection();
// 获得安全执行者
PreparedStatement preparedStatement = null;
try {
preparedStatement = connection.prepareStatement(sql);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
for (int i = 0; i < objects.length; i++) {
try {
assert preparedStatement != null;
preparedStatement.setObject(i + 1, objects[i]);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
// 安全执行者执行
try {
assert preparedStatement != null;
resultSet = preparedStatement.executeQuery();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
// 处理结果集
return resultSet;
}
}
MyBatisUtils
/**
- MyBatis工具类
*/
public class MyBatisUtils {
//创建SqlSession
private static SqlSession sqlSession;
//初始化创建SqlSession
static {
//工厂构建者
SqlSessionFactoryBuilder ssfb = new SqlSessionFactoryBuilder();
//MyBatis配置文件名称
String configName = “sqlMapConfig.xml”;
//定义输入流
InputStream is = null;
try {
//读取配置文件
is = Resources.getResourceAsStream(configName);
} catch (IOException e) {
e.printStackTrace();
}
//通过配置文件构建出工厂类
SqlSessionFactory ssf = ssfb.build(is);
//通过工厂类获取sqlSession
sqlSession = ssf.openSession(true);
}
//获取sqlSession
public static SqlSession getSqlsession(){
return sqlSession;
}
//归还sqlSession
public static void closeSqlsession(SqlSession sqlSession){
if (sqlSession!=null){
sqlSession.close();
}
}
}
MyBatisUtils
public class GeneratorSqlmap {
public void generator() throws Exception{
List warnings = new ArrayList();
boolean overwrite = true;
//指定 逆向工程配置文件
File configFile = new File(“generatorConfig.xml”);
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
callback, warnings);
myBatisGenerator.generate(null);
}
public static void main(String[] args) throws Exception {
try {
GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
generatorSqlmap.generator();
} catch (Exception e) {
e.printStackTrace();
}
}
}
配置文件generatorConfig.xml
<?xml version="1.0" encoding="UTF-8"?><jdbcConnection driverClass=“com.mysql.cj.jdbc.Driver”
connectionURL=“jdbc:mysql://localhost:3306/demo1?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true”
userId=“root”
password=“root”>
<javaModelGenerator targetPackage=“com.demo.pojo”
targetProject=“.\src”>
<sqlMapGenerator targetPackage=“com.demo.mapper”
targetProject=“.\src”>
<javaClientGenerator type=“XMLMAPPER”
targetPackage=“com.demo.mapper”
targetProject=“.\src”>
public class DateUtil {
写在最后
还有一份JAVA核心知识点整理(PDF):JVM,JAVA集合,JAVA多线程并发,JAVA基础,Spring原理,微服务,Netty与RPC,网络,日志,Zookeeper,Kafka,RabbitMQ,Hbase,MongoDB,Cassandra,设计模式,负载均衡,数据库,一致性哈希,JAVA算法,数据结构,加密算法,分布式缓存,Hadoop,Spark,Storm,YARN,机器学习,云计算…
ext>
public class DateUtil {
写在最后
还有一份JAVA核心知识点整理(PDF):JVM,JAVA集合,JAVA多线程并发,JAVA基础,Spring原理,微服务,Netty与RPC,网络,日志,Zookeeper,Kafka,RabbitMQ,Hbase,MongoDB,Cassandra,设计模式,负载均衡,数据库,一致性哈希,JAVA算法,数据结构,加密算法,分布式缓存,Hadoop,Spark,Storm,YARN,机器学习,云计算…
[外链图片转存中…(img-EXCYhKaT-1715312726767)]