Idea項目中常見錯誤及筆記(Old)


1、Idea基礎設置:

File-->settings-->

1>修改字體:Font

2>修改編碼格式:File Encodings(全部UTF-8,右下方復選框勾中--防止程序中的漢字轉為ASCII)

3>修改行號:Appearanceshow line numbers

show method separators(方法與方法間的分隔符)

4>格式化代碼:code style --> java (全部改成2)

5>代碼提示:Editor --> General --> Code Complet ;

6>修改背景顏色:Editor --> General --> Scheme;

2、更改idea中的代碼顏色:

網址:「intellij-idea-tutorial下載需要的jar包;

導入jar包import Settings,重啟idea啟用-->修改字體。

3、安裝Tomcat的時候:

出現這個錯誤---java.lang.UnsatisfiedLinkError: D:\apache-tomcat-7.0.69\bin\tcnative-1.dll: Can't load IA 32-bit .dl

我嫌麻煩找個最簡單的辦法,就是找到tomcat的bin目錄下的 tcnative-1.dll,將其刪除就好

4、集合中-套用-集合:

String str="abcdefg";

//外層集合(List)定義:

List<List<String>> list1 = new ArrayList<List<String>>();

for(int i=0;i<=5;i++){

//內層集合(普通)定義;

List<String> list2 = new ArrayList<String>();

for(int j=0;j<=str.length();j++){

String s = str.valueOf(j);

list2.add(s);

}

list1.add(list2);

}

System.out.println(list1.toString());

一個集合調用另一個集合:

List list1 = Arrays.asList(list2);

 

5、*****根據文件上傳路徑----解析文件:*****解析Excel;

網站:https://www.jianshu.com/p/3798a78303f8

 

POI的API文檔網址:

http://poi.apache.org/apidocs/index.html

 

public static void main(String[] args) throws FileNotFoundException,IOException {
    List<List<String>> list = readFile("C:\\Users\\Administrator\\Desktop\\資產-test.xlsx");
    System.out.println(list);
}
// 讀取文件;
private static Workbook getReadFile(String filePath) throws FileNotFoundException,IOException {

    try(FileInputStream fis = new FileInputStream(filePath)) {
        if(filePath.toLowerCase().endsWith("xlsx")) {
            return new XSSFWorkbook(fis);
        }else if(filePath.toLowerCase().endsWith("xls")) {
            return new XSSFWorkbook(fis);
        }else {
            throw new RuntimeException("文件格式錯誤!");
        }
    }
}
// 解析文件;
private static List<List<String>> readFile(String filePath) throws FileNotFoundException, IOException {
    try(Workbook workbook = getReadFile(filePath)){
        List<List<String>> contents = new ArrayList<List<String>>();
        Sheet sheet = workbook.getSheetAt(0);         // 這里應該改成循環每一個excel里的sheet
        for(int i=0;i<=sheet.getLastRowNum();i++) {     // 從第一列開始取值;
            List l1=new ArrayList();
            for(int rowNum=2;rowNum<=sheet.getLastRowNum();rowNum++) { // 從第一行開始取值;
                Row row = sheet.getRow(rowNum);
                Cell cell = row.getCell(i);
                if (cell != null) {
                    l1.add(getCellValue(cell).trim());
                }
            }
            contents.add(l1);
        }
        return contents;
    }
}
private static String getCellValue(Cell cell) {
    CellType cellType = cell.getCellTypeEnum();
    switch(cellType) {
        case NUMERIC:
            return String.valueOf(Math.round(cell.getNumericCellValue()));

// 此處浮點型轉換成Integer類型(Math.round());
        case STRING:
            return cell.getStringCellValue();
        case BOOLEAN:
            return String.valueOf(cell.getBooleanCellValue());
        case FORMULA:
            return cell.getCellFormula();
        case BLANK:
            return "";
        case ERROR:
            return String.valueOf(cell.getErrorCellValue());
        default:
            return "StringUtils.EMPTY"; // commons-lang3包的方法,和List一樣
    }
}

6、Integer.parseInt(String s)、Integer.getInteg(String s)和Integer.valueOf(String s)的區別:

parseInt(s)-----只是將是數字的字符串轉成數字,注意他返回的是int型變量不具備方法和屬性;

getInteger(s)---是讀取s的系統屬性,然后把該系統屬性的值轉換成一個數字,一般結果是null;

valueOf(s)------將數字型的字符串轉成數字,返回的是Integer類型具備方法和屬性;

 

Math.round(4.0);---s是浮點型,四舍五入成整型4;

 

7、操作git中有時候會提示Unlink of file '......' failed. Should I try again?

網址:

https://www.cnblogs.com/wormday/p/git_unlink_of_file_failed_should_i_try_again.html

原因是你工作目錄有某些文件正在被程序使用,這個程序多半是Idea,VS或者eclipse,當然也可能是其他程序

解決方案不是簡單的選擇y或者n,而是關閉IDE,讓IDE把這些文件釋放掉

 

 

8、idea中回車的符號: \r\n

//定義分隔符類型;

String[] ss=new String[]{"\r\n", ",", ";", ",", ";", "、"};

// 判斷是哪種類型分隔符:

ipList = ips.split(ss);

 

9、用命令提示符導出數據庫中某幾個表:

mysqldump -u用戶名 -p密碼 數據庫 表一 表二 表三> 保存路徑

例如:

mysqldump -uroot -p123456 batsir bus_groupandtask bus_scanasset bus_scanportflaw> e:\bus_ssg.sql

用命令提示符向數據庫中導入表:

mysql -uroot -p123456 batsir<C:\Users\Administrator\Desktop\bus_ssg.sql(出現 '\' 錯誤,沒有影響----可以根據ID去查詢測試)

1Mysql -uroot -p123456 --default-character-set=utf8 數據庫名 <sql文件路徑;

2Mysql -uroot -p123456

User 數據庫名

Source 文件路徑

10、HashMap集合中的元素解析到.txt文本中:

HashMap<Integer, String> result = new HashMap<>();

// 遍歷集合中的元素;<key,value>

for (Integer key : result.keySet()) {
   String value = result.get(key);
   logger.info("Key = " + key + ", Value = " + value);
}
try {
   String line = System.getProperty("line.separator");
   StringBuffer str = new StringBuffer();
   FileWriter fw = new FileWriter("C:\\Users\\Administrator\\Desktop\\1.txt", true);//保存到本地桌面上了;
   Set set = result.entrySet();
   Iterator iter = set.iterator();
   while(iter.hasNext()){
      Map.Entry entry = (Map.Entry)iter.next();
      str.append(entry.getKey()+" : "+entry.getValue()).append(line);
   }
   fw.write(str.toString());
   fw.close();
} catch (IOException e) {
   e.printStackTrace();
}

9Idea啟動服務器報錯:--系統找不到指定路徑;

 

 

10SpringMVC的測試demo中無法正確引入JQueryjs;可能是js文件夾放錯位置:

Js文件夾放在web下面而不是WEB-INF下。

11、發送Ajax請求:

前台JQuery發送Ajax請求:

$.ajax({
   type: "Get",
   url: "/data",
   data: {
      appId:appid,
      key:key,
      dateTime:datetime
   },
   dataType: "json",
   success: function (data) {
      $("#token").val(data.content);//將值填寫到id為token的文本框中;
   },
   error: function (e) {
      alert("請求錯誤:"+e.reponseText);
   }
});

后台接收請求:

@RequestMapping("/data")
@ResponseBody

public String getToken(RequestJson json) throws IOException {
   String appId = json.getAppId();
   String key = json.getKey();
   String dt = json.getDateTime();//如果dt為null時:dt=DateFormatUtils.format(new Date(), "yyyyMMddHHmmss")
   String token = TokenBuilder.buildToken(appId, key, dt);
   return token;
}

 

12、@Controller@RestController的區別

 

@RestController

(1)返回的是return中的內容,不會返回jsp、html頁面;

@Controller

(1)可以返回jsp、html,  

(2)要是返回json,在對應的方法上加上@ResponseBody注解;

 

13、多行文本框的值顯示在另一個textarea框中:

觸發點擊事件---onclick

function request() {

$("#show").text("AppId:"+$("#appId").val()+"\n"+"DataTime:"+$("#today").val()+"\n"+"Token:"+data.content);

}

14、點擊copy文本框,復制到粘貼板(點擊就成功復制):

<textarea rows="5" cols="30" id="show" readonly="readonly" onclick="myCopy()"></textarea><br/>
<font color="red"><div id="success"></div></font>

 

<script type="text/javascript">

function myCopy() {
   var ele = document.getElementById("show");
   ele.select();
   document.execCommand("Copy");
   $("#success").text("Copied to clipboard!");
}

</script>

 

 

15、修改table中表格間距:

Table中添加:style="border-collapse:separate; border-spacing:15px;"

Table中合並一行中的兩列:<td colspan="2">

合並一列中的幾行:<tr rowspan=xx >

 

16、存儲過程(MySQL游標的使用):==重點+難點

 

 

17、IP字段192.168.2.0/24

 

192.168.2.0換成32位二進制,四組,每組8位;

可分配的范圍是24位不變,后8位由“00000001”變化為“11111110”的范圍;

即:192.168.2.1--192.168.2.254

 

18、SpringBoot的項目如果有maven的時候打jar包操作:

Maven中直接clean,之后直接install;

生成的jar包在target文件夾下

 

19、idea中將Java項目打成jar包:

(1)打開Project Structure,選中Artifacts;

(2)點擊加號,選中jar ,然后from modules with dependencies;

 

(3)main方法就添加對應的類,點擊 ok;

 

(4)接下來,選擇copy to ...路徑為MANIFEST.MF的路徑,點擊OK;

 

(5)點擊 Build ,選中 Build artifacts-->build,就會出現對應的jar包。

 

xftp工具將**.jar 文件夾上傳到Linux服務器上,用命令運行項目jar包 例如:java -jar **.jar)

20、Oracle的sql語句轉換成Mysql的sql語句:

需要下載軟件:PowerDesigner

具體操作網址:https://www.cnblogs.com/xinxin1994/p/6961572.html

 

21、java中獲取當前生成文件的路徑:

System.out.println("生成文件路徑:"+System.getProperty("user.dir")+File.separator);

結果:  生成文件路徑:E:\spring-boot-basewebapp\

 

22、java中移動當前文件夾下的文件到另一文件夾下:

// 文件當前路徑;

String startPath = System.getProperty("user.dir")+File.separator+path+fileName;
// 文件目標路徑;

String endPath = "D:\\aaa\\";

File startFile = new File(startPath);
File tmpFile = new File(endPath);//獲取文件夾路徑
if(!tmpFile.exists()){//判斷文件夾是否創建,沒有創建則創建新文件夾
   tmpFile.mkdirs();
}
System.out.println("目標文件路徑:"+endPath + startFile.getName());
if (startFile.renameTo(new File(endPath + startFile.getName()))) {
   System.out.println("File is moved successful!");
} else {
   System.out.println("File is failed to move!");
}

 

23、SpringBoot修改當前工具的端口號:

直接在resources下創建application.yml或者application.properties文件;

 

 

24、formatter格式化,屬性;

editoptions給屬性賦值選擇時需要加上格式化標簽formatter。

formatter + editoptions 共同存在

 

 

25、formatter屬性,后面加上formatimage;

 

可以將后台獲取的值替換成圖片

 

26、Duplicate entry 'XXX' for key 'bgu_bgat_key' 是什么原因?

代表數據表中 字段xxx中 已經有1的這個數據了,xxx字段應該是主鍵,不能為重復,數據庫將bgu_bgat_key索引類型改為:Normal

 

27、【主機/Web關聯】回顯和編輯需要同步:

if(PlatformEnum.WEB==WebUtils.getPlatform(request)){
   List<GroupRelationDTO> hostList = groupAndTaskService.getHostGroupIds(Arrays.asList(ud.getGroupId()));
   if(hostList!=null && hostList.size()>0){
      Integer groupId = hostList.get(0).getHostGroupId();
      ud.setGroupId(groupId);
   }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM