Java异常与调优一站式解决方案

113 阅读1分钟

download:Java异常与调优一站式解决方案

项目异常不断,找不到问题所在?百度、Google搜个遍,也找不到答案?本课程针对Java开发中常见的各种异常,从日志、堆栈再深入到JVM,带你发现问题、定位问题、解决问题,最后在实战中搭建开箱即用的SpringBoot脚手架,强化巩固所学,助力你提升开发技能!

技术要求
基本的Java语法
理解Spring的思想和理念

环境参数
JDK 1.8、
SpringBoot 2.1.4.RELEASE
函數操作
對條件字段做函數操作走不了索引。

select * from t1 where date© =‘2019-05-21’;
優化:改成範圍查询

select * from t1 where c>=‘2019-05-21 00:00:00’ and c<=‘2019-05-21 23:59:59’;
隱式轉換
操作符與不同類型的操作對象一同運用時,就會發作類型轉換以使操作兼容。

select user_name,tele_phone from user_info where tele_phone =11111111111; /

tele_phone varchar

/
實践會做函數操作:

select user_name,tele_phone from user_info where cast(tele_phone as singed int) =11111111111;
優化:類型統一

select user_name,tele_phone from user_info where tele_phone =‘11111111111’;
含糊查询
通配符在前面

select * from t1 where a like ‘%1111%’;
優化:含糊查询必需包含條件字段前面的值

select * from t1 where a like ‘1111%’;
範圍查询
範圍查询數據量太多,需求回表,因而不走索引。

select * from t1 where b>=1 and b <=2000;
優化:降低單次查询範圍,分屢次查询。(實践可能速度沒得快太多,倡議走索引)

select

from t1 where b>=1 and b <=1000;
show profiles;
±---------±-----------±-----------------------------------------+
| Query_ID | Duration | Query |
±---------±-----------±-----------------------------------------+
| 1 | 0.00534775 | select

from t1 where b>=1 and b <=1000 |
| 2 | 0.00605625 | select * from t1 where b>=1 and b <=2000 |
±---------±-----------±-----------------------------------------+
2 rows in set, 1 warning (0.00 sec)
計算操作
即便是简單的計算

explain select * from t1 where b-1 =1000;
優化:將計算操作放在等號後面

explain select * from t1 where b =1000 + 1;

翻了很多题解,只能看懂这种解法,够直观够暴力。

class Solution {
public:
vector restoreIpAddresses(string s) {
vector res;

    for (int a = 1; a < 4; a ++ )
        for (int b = 1; b < 4; b ++ )
            for (int c = 1; c < 4; c ++ )
                for (int d = 1; d < 4; d ++ )           //abcd分别表示四段ip地址长度
                {
                    if (a + b + c + d == s.size())      //四段长度刚好
                    {
                        string s1 = s.substr(0, a);     //分别截取四段ip地址
                        string s2 = s.substr(a, b);
                        string s3 = s.substr(a + b, c);
                        string s4 = s.substr(a + b + c);

                        if (check(s1) && check(s2) && check(s3) && check(s4))
                        {
                            string ip = s1 + '.' + s2 + '.' + s3 + '.' + s4;
                            res.push_back(ip);
                        }
                    }
                }

    return res;
}

bool check(string s)        //判断ip地址每段的第一位不为0,或只有一位且该位为0
{
    if (stoi(s) <= 255)
        if (s[0] != '0' || (s[0] == '0' && s.size() == 1)) return true;

    return false;
}