JdbcTemplate /** * 判断表是否存在 * * @param tableName 表名 * @return {@link boolean} 结果(true=存在,false=不存在) * @author yunnuo */ public boolean existsTable(String tableName) { String isTableSql = String.format("SELECT COUNT(*) as count FROM information_schema.TABLES WHERE " + "table_name = '%s'", tableName); Map<String, Object> map = jdbctemplate.queryForMap(isTableSql); return Integer.parseInt(map.get("count").toString()) > 0; } MyBatis mapper.java /** * 判断表是否存在 * * @param tableName 表名称 * @return 结果 * @author yunnuo */ Integer existsTable(@Param("tableName") String tableName); mapper.xml <!-- 判断表是否存在 --> <select id="existsTable" parameterType="string" resultType="java.lang.Integer"> SELECT COUNT(*) as count FROM information_schema.TABLES WHERE table_name = #{tableName} </select> Service.java /** * 判断表是否存在 * * @param tableName 表名 * @return {@link boolean} 结果(true=存在,false=不存在) * @author yunnuo */ public Boolean existsTable(String tableName) { Integer tableNumber = reportMapper.existsTable(tableName); return tableNumber > 0; }