在Eclipse內寫程式時,可以為自創的Function加上適當的註解,也可以自動產生一般方法而免去手動撰寫。
例如先創造一個Bean:
再用滑鼠右鍵選單選擇【Generate Element Commet】和【Generate Getters and Setters】,便會有相對應的結果出現:
在點擊【Generate Getters and Setters】後,會出現要針對哪些變數來自動產生方法:
註解寫好後,以後只要將滑鼠移動到該程式碼上,便會出現一般我們所常看到的Tip了:
2016年6月30日 星期四
2016年6月29日 星期三
PostgreSQL的更改欄位類型方式
話說PostgreSQL的Console讓我覺得有一些地方不方便,創造欄位後便不可以介面式的移動位置、更改欄位類型等諸多限制,尤其是當我想要二次更改時,就只好刪除重建,但是這樣一來位置又會走掉,所以常常會為了更改一個欄位,就毀掉大半表格又重建(當然,實際上欄位位置不重要,一樣可以使用,但我就是希望看得舒服@@)。
所以搜尋和嘗試了一小段時間,找到了可以用SQL語法變更欄位類型的方式。
例如,在名為"test"的schema內,將一個名為"check_time"的欄位更改為"時間且不含時區"的格式:
ALTER TABLE msoc.test
ALTER COLUMN check_time TYPE timestamp without time zone
USING check_time::timestamp without time zone
例如,在名為"test"的schema內,將一個名為"id"的欄位更改為"字串"的格式:
ALTER TABLE msoc.test
ALTER COLUMN id TYPE varchar
USING id::varchar
主要是參考下列網址內的資訊:
https://www.postgresql.org/docs/9.1/static/sql-altertable.html
TYPE的部分,有時會和在介面內創造時的名稱不一樣,例如在介面內是"character varying",在SQL語法內是"varchar",所以要改變類別時,最好去上列網址內看看想要改變的類別在TYPE處該怎麼寫。
所以搜尋和嘗試了一小段時間,找到了可以用SQL語法變更欄位類型的方式。
例如,在名為"test"的schema內,將一個名為"check_time"的欄位更改為"時間且不含時區"的格式:
ALTER TABLE msoc.test
ALTER COLUMN check_time TYPE timestamp without time zone
USING check_time::timestamp without time zone
例如,在名為"test"的schema內,將一個名為"id"的欄位更改為"字串"的格式:
ALTER TABLE msoc.test
ALTER COLUMN id TYPE varchar
USING id::varchar
主要是參考下列網址內的資訊:
https://www.postgresql.org/docs/9.1/static/sql-altertable.html
TYPE的部分,有時會和在介面內創造時的名稱不一樣,例如在介面內是"character varying",在SQL語法內是"varchar",所以要改變類別時,最好去上列網址內看看想要改變的類別在TYPE處該怎麼寫。
2016年6月27日 星期一
Java的現在時間取法,和延遲用法
首先是我需要使用Java來取得現在時間,Java裡和時間相關的Class有好幾個,看了看網上的資訊後我決定使用java.time來實作。
要注意的是,currentDateTime只是儲存了LocalDateTime.now()所取得的時間值,故一會兒後再使用currentDateTime的話,裡面的時間值可不會自動改變喔。每次要取得最新的"現在時間值"的話,就必須反覆使用LocalDateTime.now()。
LocalDateTime的結果並不包含時區,如果要直接取得時間 + 時區的結果,可以使用ZonedDateTime的Class。
如果是想要單純取得時區,可以使用ZonedDateTime下的一些方法,通常可以取得的結果有兩種:時區的區域名稱,和時區的時差數值。
然後是如果執行程式時需要延遲一會兒,有Thread.sleep()和TimeUnit.sleep這兩個用法,這邊我選擇TimeUnit.sleep,因為有比較完整的用法,還可分為從TimeUnit.DAYS到TimeUnit.NANOSECONDS各種不同時間單位的使用方式,這邊使用TimeUnit.SECONDS來實作。
- import java.time.*;
- public class MainProcess{
- public static void main(String[] args)
- {
- LocalDateTime currentDateTime = LocalDateTime.now();
- System.out.println( currentDateTime );
- }
- }
要注意的是,currentDateTime只是儲存了LocalDateTime.now()所取得的時間值,故一會兒後再使用currentDateTime的話,裡面的時間值可不會自動改變喔。每次要取得最新的"現在時間值"的話,就必須反覆使用LocalDateTime.now()。
LocalDateTime的結果並不包含時區,如果要直接取得時間 + 時區的結果,可以使用ZonedDateTime的Class。
- import java.time.*;
- public class MainProcess{
- public static void main(String[] args)
- {
- ZonedDateTime currentDateTime = currentZoneTime.now();
- System.out.println( currentZoneTime );
- }
- }
如果是想要單純取得時區,可以使用ZonedDateTime下的一些方法,通常可以取得的結果有兩種:時區的區域名稱,和時區的時差數值。
- import java.time.*;
- public class MainProcess{
- public static void main(String[] args)
- {
- ZonedDateTime currentDateTime = currentZoneTime.now();
- System.out.println( currentZoneTime.getZone() );
- System.out.println( currentZoneTime.getOffset() );
- }
- }
然後是如果執行程式時需要延遲一會兒,有Thread.sleep()和TimeUnit.sleep這兩個用法,這邊我選擇TimeUnit.sleep,因為有比較完整的用法,還可分為從TimeUnit.DAYS到TimeUnit.NANOSECONDS各種不同時間單位的使用方式,這邊使用TimeUnit.SECONDS來實作。
- import java.time.*;
- import java.util.*;
- import java.util.concurrent.*;
- public class MainProcess{
- public static void main(String[] args) throws InterruptedException
- {
- for( int i = 0; i < 10; i++ )
- {
- TimeUnit.SECONDS.sleep( 1 );
- System.out.println( LocalDateTime.now() );
- }
- }
- }
2016年6月16日 星期四
在Eclipse內使用PostgreSQL資料庫
最近工作需要在Eclipse內和PostgreSQL資料庫相連,因此這邊記錄一下使用方式,免得自己以後要用時又得東找西找的。
首先將PostgreSQL的JAR檔匯入到Eclipse內:

接著在Eclipse內撰寫:
首先將PostgreSQL的JAR檔匯入到Eclipse內:

接著在Eclipse內撰寫:
- import java.sql.*;
- public class MainProcess {
- public static void main(String[] args)
- {
- Connection tempConnection = null;
- Statement tempStatement = null;
- ResultSet tempResultSet = null;
- String tempAction = "";
- String tempSentence = "";
- switch( tempAction )
- {
- case "Select":
- tempSentence = "SELECT * FROM Schemas.Tables WHERE account = 'Kimdick' AND password = '123'";
- break;
- case "Insert":
- tempSentence = "INSERT INTO Schemas.Tables ( account, password ) VALUES ( 'Kimdick', '123' )";
- break;
- case "Update":
- tempSentence = "Update Schemas.Tables SET password = '123', email = 'Kimdick@mail' WHERE account = 'Kimdick'";
- break;
- case "Delete":
- tempSentence = "DELETE FROM Schemas.Tables WHERE account = 'Kimdick'";
- break;
- }
- try
- {
- Class.forName( "org.postgresql.Driver" );
- tempConnection = DriverManager.getConnection( "jdbc:postgresql://127.0.0.1:5432/datastream", "postgres", "1234" );
- tempStatement = tempConnection.createStatement();
- tempStatement.executeQuery( tempSentence );
- if( tempResultSet != null )
- {
- tempResultSet.close();
- tempResultSet = null;
- }
- if( tempStatement != null )
- {
- tempStatement.close();
- tempStatement = null;
- }
- if( tempConnection != null )
- {
- tempConnection.close();
- tempConnection = null;
- }
- }
- catch( Exception e )
- {
- e.printStackTrace();
- }
- }
- }
- DriverManager.getConnection( "jdbc:postgresql://127.0.0.1:5432/datastream", "postgres", "1234" );
這裡是DriverManager.getConnection( "jdbc:postgresql://資料庫IP:Port/Database", 帳號, 密碼 );
2016年6月14日 星期二
C#的拆解字串
在Unity內、使用C#時,有時會需要拆解字串和重組字串,字串的拆解通常都是訂定拆解字元來執行,但有時也會需要訂定拆解字串來執行。
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class MainProcess : MonoBehaviour {
- private string data = "ABCDEFGH";
- private string[] splitSeparators = new string[]{ "DEF" };
- void Start ()
- {
- Debug.Log( data.split( 'D' )[0] );
- Debug.Log( data.split( 'D' )[1] );
- Debug.Log( data.split( splitSeparators, System.StringSplitOptions.None )[0] );
- Debug.Log( data.split( splitSeparators, System.StringSplitOptions.None )[1] );
- }
- }
2016年6月13日 星期一
C#的Dictionary之取得資料
Dictionary是類似Hashtable的架構,用Key和Value的方式來相對應。
而要來依序取得裡面的資料時,foreach裡引用的架構和一般有點不同,主要是keyValuePair。
而要來依序取得裡面的資料時,foreach裡引用的架構和一般有點不同,主要是keyValuePair。
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class MainProcess : MonoBehaviour {
- private Dictionary<int, string> tempDictionary = new Dictionary<int, string>();
- void Start ()
- {
- tempDictionary.Add( 1, "XXX" );
- tempDictionary.Add( 2, "YYY" );
- tempDictionary.Add( 3, "ZZZ" );
- foreach( KeyValuePair<int, string> x in tempDictionary )
- {
- Debug.Log( x.Key + " = " + x.Value );
- }
- }
- }
Unity內轉換Direction和EulerAngles為Quaternion
一般在3D間內有三種可表現方向的方式:
Direction:向量方式,例如( 1, 0, 0 )表示面向正左方。
EulerAngles:尤拉角(由拉角、歐拉角)方式,例如( 0, 180, 0 )表示面向正後方。
Qaternion:四元數。
Direction和EulerAngles都很好理解,而Qaternion即使我能理解它的原理,但還是不擅使用。
偏偏有不少關於方向的使用都得是Qaternion型式,所以轉換就很重要。
Direction轉換成Qaternion,可以使用Qaternion.LookRotation:
EulerAngles轉換成Qaternion,可以使用Qaternion.Euler:
這樣當需要使用Quaternion時,我就可以用這些方式去轉換了。
Direction:向量方式,例如( 1, 0, 0 )表示面向正左方。
EulerAngles:尤拉角(由拉角、歐拉角)方式,例如( 0, 180, 0 )表示面向正後方。
Qaternion:四元數。
Direction和EulerAngles都很好理解,而Qaternion即使我能理解它的原理,但還是不擅使用。
偏偏有不少關於方向的使用都得是Qaternion型式,所以轉換就很重要。
Direction轉換成Qaternion,可以使用Qaternion.LookRotation:
例如Qaternion rotation = Qaternion.LookRotation( new Vector3( 1, 0, 0 ), Vector3.up );
- Qaternion LookRotation( Vector3 forward, Vector3 upwards = Vector3.up );
EulerAngles轉換成Qaternion,可以使用Qaternion.Euler:
例如Quaternion rotation = Quaternion.Euler( 0, 30, 0 );
- Quaternion Euler( float x, float y, float z );
這樣當需要使用Quaternion時,我就可以用這些方式去轉換了。
2016年6月8日 星期三
Unity內偵測有否點擊到UGUI作出來的介面
Unity現在可使用方便的UGUI功能作介面,而當要操控2D介面或是作3D物件控制時,都是使用滑鼠左鍵;所以一般邏輯為當滑鼠初次點擊在2D介面上時,就不會啟動3D物件控制功能,因此需要偵測滑鼠是否點擊在任何UGUI作出來的2D介面上。
UGUI在創建時,會自動在【Hierarchy】下產生『Canvas』和『EventSystem』兩個物件,『EventSystem』便是用來處理點擊等事件的存在,所以會使用它來得知是否有滑鼠點擊任何UGUI物件,並可取得所點擊的介面物件。
UGUI在創建時,會自動在【Hierarchy】下產生『Canvas』和『EventSystem』兩個物件,『EventSystem』便是用來處理點擊等事件的存在,所以會使用它來得知是否有滑鼠點擊任何UGUI物件,並可取得所點擊的介面物件。
- using UnityEngine;
- using System.Collections;
- using UnityEngine.EventSystems;
- public class MainProcess : MonoBehaviour {
- void Update ()
- {
- if( Input.GetMouseButtonDown( 0 ) )
- {
- if( EventSystem.current.IsPointerOverGameObject() )
- {
- Debug.Log( "有介面被點擊到!" );
- Debug.Log( EventSystem.current.currentSelectedGameObject );
- }
- }
- }
- }
2016年6月7日 星期二
C#的尋找在List內之Structure資料
在Unity內、使用C#時,創造包含Structure的List,然後用條件尋找的方式。
先在List內找到符合條件的該筆資料Index,再用Index去調出要尋找的該筆資料其他部分:
先在List內找到符合條件的該筆資料Index,再用Index去調出要尋找的該筆資料其他部分:
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class MainProcess : MonoBehaviour {
- private List<tempStructure> tempStructureList = new List<tempStructure>();
- private struct tempStructure
- {
- public int tempNumber;
- public string tempName;
- }
- void Start ()
- {
- tempStructure xxx = new tempStructure();
- tempStructure yyy = new tempStructure();
- xxx.tempNumber = 1;
- xxx.tempName = "XXX";
- yyy.tempNumber = 2;
- yyy.tempName = "YYY";
- tempStructureList.Add( xxx );
- tempStructureList.Add( yyy );
- tempIndex = tempStructureList.FindIndex( z => z.tempName == "XXX" );
- Debug.log( tempStructureList[tempIndex].tempNumber );
- }
- }
C#的Structure
在Unity內、使用C#時,創造並使用Structure的方式:
- using UnityEngine;
- using System.Collections;
- public class MainProcess : MonoBehaviour {
- private struct tempStructure
- {
- public int tempIndex;
- public string tempName;
- }
- void Start ()
- {
- tempStructure xxx = new tempStructure();
- xxx.tempIndex = 1;
- xxx.tempName = "Name";
- Debug.log( xxx.tempIndex );
- Debug.log( xxx.tempName );
- }
- }
這就是Google的Blogger @@
在很久很久以前,有使用過Yahoo的部落格,玩了一下就沒繼續了。
過了很久,現在是個程式工程師的我,常常會在網路上尋找很多資訊。有自己會用到的資訊時,便會把網頁給整個儲存起來,可是東西一多了之後,往往會很不好找。
這時靈光一閃,有看過一些人會把自己使用到的資訊,記錄在網誌上,讓我萌起了這個也想做看看的念頭。
接下來,就看我有沒有恆心來玩囉......
過了很久,現在是個程式工程師的我,常常會在網路上尋找很多資訊。有自己會用到的資訊時,便會把網頁給整個儲存起來,可是東西一多了之後,往往會很不好找。
這時靈光一閃,有看過一些人會把自己使用到的資訊,記錄在網誌上,讓我萌起了這個也想做看看的念頭。
接下來,就看我有沒有恆心來玩囉......
訂閱:
文章 (Atom)