2023年10月24日 星期二

從資料庫產生entity&mapper

mybatis-plus的generatort生成工具 
生成 PO類、Mapper接口、Mapper的xml文件 

來源
 https://github.com/baomidou/generator 

將xuecheng-plus-generator.zip解壓後複製到專案的根目錄 如下














在專案中找到pom檔案, 點選右鍵add as maven project
才能使用















在這包中找到ContentCodeGenerator類別














TABLE_NAMES後面可以指定要生成的數據表











資料庫連線, 則是在下面程式碼中做配置








然後就可以run這個application, 產生結果會在和generator同層的包 content中
裡面包含controller, mapper, model 還有service







2023年10月17日 星期二

全局date time

 當回應的日期格式中有T還有毫秒的時候














或許我們會思考如何改它的格式

有一個方法, 可以做全局的統一



@Configuration
public class LocalDateTimeConfig {

    /*
     * 序列化内容
     *   LocalDateTime -> String
     * 服务端返回给客户端内容
     * */
    @Bean
    public LocalDateTimeSerializer localDateTimeSerializer() {
        return new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }

    /*
     * 反序列化内容
     *   String -> LocalDateTime
     * 客户端传入服务端数据
     * */
    @Bean
    public LocalDateTimeDeserializer localDateTimeDeserializer() {
        return new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }


    // 配置
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        return builder -> {
            builder.serializerByType(LocalDateTime.class, localDateTimeSerializer());
            builder.deserializerByType(LocalDateTime.class, localDateTimeDeserializer());
        };
    }

}

透過上面的方式, 就能統一格式

結果:

2023年8月11日 星期五

linux note-2

分辨文件 文件夾

ls -l

其中d開頭為文件夾, -開頭為文件

cat 支持看文件

但是當文件太長的時候, 變得難以閱讀

ex

cat /etc/services


而 翻頁查看 可以方便看長文件

ex

 more /etc/services

翻頁 按 空白鍵

退出 按 q


小結

1. touch命令

用于创建一个新的文件

语法:touch linux 路徑

参数必填,表示要创建的文件的路径,相对、绝对、特殊路径符都可以使用

2. cat命令

用于查看文件内容

语法:cat linux 路徑

参数必填,表示要查看的文件的路径,相对、绝对、特殊路径符都可以使用

3. more命令

用于查看文件内容,可翻页查看

语法:more linux路徑

参数必填,表示要查看的文件的路径,相对、绝对、特殊路径符都可以使用

使用空格进行翻页,使用q退出查看


2023年6月29日 星期四

linux note-1

計算機 由硬件和軟件組成, 而操作系統就是軟件

連線查詢
ifconifig




然後打開finalshell



輸入連線資訊




ls 
顯示目錄

cd
change directory
回到home

cd/
回到根目錄

pwd
print work directory
查看當前工作目錄

cd ..
切換到上一層

cd ../..
切換到上上層

cd ~
切換到home == cd home

cd ~/Desktop
進到home下的Desktop目錄

範例>>>>>>>>>>>>>>>>>>
当前工作目录内有一个test文件夹,文件夹内有一个文件hello.txt,请描述文件的相对路径
test/hello.txt
在当前工作目录的上级目录有一个test文件夹,文件夹内有一个文件hello.txt,请描述文件的相对路径
../test/hello.txt
在HOME目录内有一个test文件夹,文件夹内有一个文件hello.txt,请描述文件的路径,需要使用符号~
~/test/hello.txt

mkdir [-p] linux路徑
make directory

-p 自動創建不存在父目錄, 是連續層級父目錄

一次創建多個層級時, 是會報錯的
需要加上-p
另外
ctrl + L 可以清空頻目

注意:创建文件夹需要修改权限,请确保操作均在HOME目录内,不要在HOME外操作
涉及到权限问题,HOME外无法成功
后续我们会讲解权限管控的知识







2022年10月23日 星期日

面試紀錄

雲海岸
---------
問get post的差異-其中有說明post在資安上是比較安全
使用 GET 的時候我們直接將要傳送的資料以 Query String(一種Key / Vaule的編碼方式)加在我們要寄送的地址( URL )後面,然後交給郵差傳送。使用 POST 的時候則是將寄送地址( URL )寫在信封上,另外將要傳送的資料寫在另一張信紙後,將信紙放到信封裡面,交給郵差傳送。
 POST 是將表單的內容放在 body 裡面,在不看封包的情況下似乎較為安全,此外在傳送檔案時會用到 multi-part 編碼,將檔案與其他表單一併放在 body 中傳送
https://medium.com/kurt/%E7%B6%B2%E9%A0%81get-%E8%88%87-post-%E5%B7%AE%E7%95%B0-%E7%A7%91%E6%99%AE%E5%A3%B9%E9%BB%9E%E9%80%9A-94cbaa666fdb

問spring IOC
主程式中所需要的輔助物件,並不是在自己的類別中建立,而是由外部控制的。建立好後,將其傳遞給主程式,這個動作稱為依賴注入(dependency injection,DI),是控制反轉的實現方式。
在Spring啟動時,這兩個類別會被建立成元件,存放在容器中。其中計算器使用了 @Autowired標記,因此框架會從容器中找出對應類別的元件,自動注入到計算器中。
一般來說,元件預設是「單例」的。意即在整個應用程式運行期間只會存在唯一一個。如此可避免產生不必要的重複物件。
Spring Boot透過容器,達到元件的控制反轉。而開發者透過用類別、介面甚至元件名稱來宣告輔助元件,讓容器得以完成依賴注入。在撰寫元件的程式碼時,我們可透過介面提供的方法來使用其他元件,以便在替換時,仍能保持一致的使用方式。而進行單元測試時,能夠自行傳遞不同屬性或實作類別的物件,提高了可測試性。
https://medium.com/chikuwa-tech-study/spring-boot%E8%88%87%E6%8E%A7%E5%88%B6%E5%8F%8D%E8%BD%89%E7%9A%84%E9%97%9C%E4%BF%82-ac1bd4b82ed5

在你專案中有用到什麼設計模式?
使用itext和POI的時候, 用Template樣板模式, 使其中重複用到的功能寫於抽象父類別, 而不同的generate report功能由各報表類別來實作, 合適的滿足開閉原則的要求

--------------
博彥
有考IOC AOP

AOP
AOP 的本質 — 改變程式碼的流程
以 Web Server 開發場景為例,我們經常會需要在很多 end-point API 的方法執行前先執行權限驗證,或者是在這些 end-point 執行 transaction 失敗時可以 rollback。

這些在程式碼中會重複出現,它們是重要但是不屬於我們核心業務的操作,如果要重複複製貼上到專案中的各處會造成難以維護的窘境。因此 AOP 試圖讓這些常被複用的邏輯獨立出來,用特殊的機制包裝起來,讓我們的業務邏輯不需要去看到任何相關的程式碼。

這件事本質上聽起來跟呼叫函式沒有太大的區別,然而 AOP 本質上是屬於一種 Meta Programming 。具體來說,實現 AOP 的工具處理的是程式碼本身(或 bytecode本身) 或是 class (或 object ) 的資訊,是用來改變程式碼的流程或織入( weaving ) 新的程式碼,而非只是單純地「執行一段程式」。

AOP 只是種指導編程模式的原則而已,在不同的語言和生態系中,類似的概念都有不同的實作方式,然而共通點都是藉由改變程式碼的流程讓核心邏輯不會受到額外的切面邏輯的影響。

在靜態語言中,程式的流程在編譯時期就會被寫死了,要穿插切面在程式碼各處會需要有額外的工具來支持。而在動態語言中,因為程式的流程並不是在編譯時期就被決定了,而是可以動態更改的,所以通常原生語法就支持了 AOP 功能。
https://tech-blog.cymetrics.io/posts/maxchiu/aop/



問: 有無使用TDD?

TDD(Test-Driven Development)是一種開發流程,中文是「測試驅動開發」。用一句白話形容,就是「先寫測試再開發」。先寫測試除了能確保測試程式的撰寫,還有一個好處:有助於在開發初期釐清程式介面如何設計。

程式介面,或是常說的 API 介面,是內部封裝細節和外部元件的溝通橋樑。在實作時,我們通常會希望程式介面維持穩定,越少改動越好。但在開發初期憑空定義出來的介面,常常在開發完成實際使用時才發現不好用,導致介面需要頻繁改動。

測試程式的作用是「模擬外部如何使用目標程式,驗證目標程式的行為是否符合預期」。換句話說,在寫測試時,會去了解目標程式如何被使用,比起憑空定義介面,更有助於在實作目標程式之前釐清適合的介面設計,減少後續變動的次數。

具體來說,TDD 流程可以分成五個步驟:

步驟一:選定一個功能,新增測試案例

  • 重點在於思考希望怎麼去使用目標程式,定義出更容易呼叫的 API 介面。
  • 這個步驟會寫好測試案例的程式,同時決定產品程式的 API 介面。
  • 但尚未實作 API 實際內容

步驟二:執行測試,得到 Failed(紅燈)

  • 由於還沒撰寫 API 實際內容,執行測試的結果自然是 failed。
  • 確保測試程式可執行,沒有語法錯誤等等。

步驟三:實作「夠用」的產品程式

  • 這個階段力求快速實作出功能邏輯,用「最低限度」通過測試案例即可。
  • 不求將程式碼優化一步到位。

步驟四:再次執行測試,得到 Passed(綠燈)

  • 確保產品程式的功能邏輯已經正確地得到實作。
  • 到此步驟,將完成一個可運作且正確的程式版本,包含產品程式和測試程式。

步驟五:重構程式

  • 優化程式碼,包含產品程式和測試程式(測試程式也是專案需維護的一部份)。
  • 提升程式的可讀性、可維護性、擴充性。
  • 同時確保每次修改後,執行測試皆能通過。

每個功能重複上述步驟,就是 TDD 的開發流程。

https://tw.alphacamp.co/blog/tdd-test-driven-development-example


問 Java 8 特性

https://www.796t.com/p/570214.html

https://blog.51cto.com/u_15236724/5368640


---------
匯誠
Array和List差異
Array需要先宣告陣列的大小,且是固定的無法再做更動,元素可透過"陣列名[索引index]=元素內容;"來進行新增的動作,再之後陣列名[索引index]就保有資料了,而常見的array型態也包括String型態。
ArrayList的大小可以變化,透過add來將元素新增至列表的末端,目前已有三筆資料(a、b、ccc),接著就看到其他常用的方法。
List是有序集合,是ArrayList的一個介面,但是只能夠使用List包含的方法,且不能實例化(Object),其他大部分都與ArrayList相像。

2022年9月12日 星期一

Big O

Overview

Big O help us find out how well the problem is solved.

We use it to distinguish that code from good code, good code from great code.

->great developer

What is good code?

1. Readable

2. Scalable

Big O allow us to measure the idea of scalable code.

How can we make sure that there is a way for us to measure in terms of efficiency, what is good code, 

what is bad code, and what is code that can scale that as the number of arrays or inputs increases, 

it doesn't constantly slow down more and more.

We can compare it to different algorithms or in this case, function using big O and say which one is better than the other when it comes to scale. Regardless of our computer differences.

When we talk about Big O and scalability of code, we simply mean when we grow bigger and bigger with inputs, how much does the algorithm or functions slow down.

When the Elements increase, the number of operations increased over and over. Some increase much, some doesn't increase much.

Instead of using performance and using time to measure the efficiency of our function, we can just calculate how many operations a computer has to perform because each operation takes time on a computer.

O(n)









The picture describes that 4 item in an array.

We do the asking loop "is it the nemo ?" 4 times 4 operations


As the items increased, the operation increased.

This is linear. We can say this findNemo notation O(n).


As the item increased, we find the time scaled.

O(1)


This is O(1), what we called constant time.

It is how many items in boxes, we just grasping the first item in the array.


The number of operations just stay flat.

function funChallenge(input) {
  let a = 10; //O(1)
  a = 50 + 3; //O(1)

  for (let i = 0; i < input.length; i++) {
    anotherFunction(); //O(n)
    let stranger = true; //O(n)
    a++; //O(n)
  }
  return a; //O(1)
}

We can calculate the function which is BIG O(3+3n).
It can be simplify as O(n).

function anotherFunChallenge(input) {
  let a = 5;//O(1)
  let b = 10;//O(1)
  let c = 50;//O(1)
  for (let i = 0; i < input; i++) {
    let x = i + 1; //O(n)
    let y = i + 2; //O(n)
    let z = i + 3; //O(n)

  }
  for (let j = 0; j < input; j++) {
    let p = j * 2; //O(n)
    let q = j * 2; //O(n)
  }
  let whoAmI = "I don't know";//O(1)
}
BIG O(4+5n).-> O(n)
How to simplify? 4 rules

Rule 1: Worst Case

If the worst case happen, we just need to run all the case of it.
However, we can add break when the function find the target.
The effort time will decrease.
We can know that in the following situation.
It may be O(1), O(4) for us to find the nemo.
The worst situation is O(n).
















Rule 2: Remove Constants

O(n+1), O(n+10000) -> O(n)
Because we consider the scale, we omit the constants.
On the other example,
We don't really care about how steep the line is.
O(2n), O(n/1000) -> O(n)
We care about how the line moves as our inputs increase.

Rule 3: Different terms for inputs

When the function has two different arrays of inputs,
we say O of A plus B.











When the loops were actually nested and they are not one after another,
the big O is A times B.










Rule 4: Drop Non Dominants












if we call the function > printAllNumbersThenAllPairSums([1,2,3,4,5]),
the Big O will be O(n+n^2).
The n will be drop due to the insignificance in the function.
Hence, it the Big O should be O(n^2). It is quadratic.

2022年8月4日 星期四

swarm intelligence 群體智慧- 托福 聽力46-2 部分內容

Swarm intelligence is a collective behavior that emerges from a group of animals, like a colony of termites, a school of fish, or a flock of birds.

群體智能是一群動物的集體行為,如白蟻群、魚群或鳥群。

Let's first consider the principles behind swarm intelligence, and we'll use the ant as our model.

Now, an ant on its own is not that smart. When you have a group of ants, however, there you have efficiency in action.

You see, there's no leader running an ant colony.

讓我們首先考慮群體智能背後的原理,我們將使用螞蟻作為我們的模型。

現在,一隻螞蟻本身並不那麼聰明。 然而,當你有一群螞蟻時,你就有了行動的效率。你看,沒有領導者管理蟻群。

Each individual, each individual ant operates by instinctively following a simple set of rules when foraging for food.

Rule number 1: Deposit a chemical marker... called a pheromone. And rule 2: Follow the strongest pheromone path.

The strongest pheromone path is advantageous to ants seeking food.

So, for example, when ants leave the nest, they deposit a pheromone trail along the route they take.

If they find food, they return to the nest on the same path and the pheromone trail gets stronger—it's doubled in strength.

Because an ant that took a shorter path returns first, its pheromone trail is stronger, and other ants will follow it, according to rule 2.

And as more ants travel that path, the pheromone trail gets even stronger.

每個個體,每個個體的螞蟻在覓食時都本能地遵循一套簡單的規則。規則 1:存放一種化學標記物……稱為信息素。 規則 2:遵循最強的信息素路徑。最強的信息素路徑有利於螞蟻尋找食物。因此,例如,當螞蟻離開巢穴時,它們會沿著它們所走的路線放置一條信息素軌跡。如果它們找到食物,它們會沿著同一條路徑返回巢穴,並且信息素痕跡會變得更強——它的強度會增加一倍。因為根據規則 2,走較短路徑的螞蟻首先返回,它的信息素軌跡更強,其他螞蟻會跟隨它。隨著越來越多的螞蟻在這條路上旅行,信息素的踪跡變得更加強大。

So, what's happening here?

Each ant follows two very basic rules, and each ant acts on information it finds in its immediate local environment.

And it's important to note: Even though none of the individual ants is aware of the bigger plan, they collectively choose the shortest path between the nest and a food source because it's the most reinforced path.

By the way, a-a few of you have asked me about the relevance of what we're studying to everyday life.

And swarm intelligence offers several good examples of how concepts in biology can be applied to other fields.

Well, businesses have been able to use this approach of following simple rules when designing complex systems, for instance, in telephone networks.

When a call is placed from one city to another, it has to connect through a number of nodes along the way.

那麼,這裡發生了什麼?

每隻螞蟻都遵循兩條非常基本的規則,每隻螞蟻都根據在其直接本地環境中找到的信息採取行動。重要的是要注意:即使沒有一隻螞蟻知道更大的計劃,它們也會集體選擇巢穴和食物來源之間的最短路徑,因為它是最堅固的路徑。順便說一句,你們中的一些人問過我我們正在學習的內容與日常生活的相關性。群體智能提供了幾個很好的例子,說明生物學中的概念如何應用於其他領域。好吧,在設計複雜系統時,例如在電話網絡中,企業已經能夠使用這種遵循簡單規則的方法。當從一個城市向另一個城市撥打電話時,它必須通過沿途的多個節點進行連接。

At each point, a decision has to be made: Which direction does the call go from here?

Well, a computer program was developed to answer this question based on rules that are similar to the ones that ants use to find food.

Remember, individual ants deposit pheromones, and they follow the path that is most reinforced.

Now, in the phone network, a computer monitors the connection speed of each path, and identifies the paths that are currently the fastest—the least crowded parts of the network.

And this information, converted into a numeric code, is deposited at the network nodes.

This reinforces the paths that are least crowded at the moment.

The rule the telephone network follows is to always select the path that is most reinforced.

So, similar to the ant's behavior, at each intermediate node, the call follows the path that is most reinforced.

This leads to an outcome which is beneficial to the network as a whole, and calls get through faster.

在每一點上,都必須做出決定:呼叫從這裡往哪個方向進行?

嗯,開發了一個計算機程序來回答這個問題,其規則類似於螞蟻用來尋找食物的規則。請記住,個體螞蟻會沉積信息素,它們會遵循最強化的路徑。現在,在電話網絡中,計算機監控每條路徑的連接速度,並識別當前最快的路徑——網絡中最不擁擠的部分。這些信息,轉換成數字代碼,存放在網絡節點上。這加強了目前最不擁擠的路徑。電話網絡遵循的規則是始終選擇最強化的路徑。因此,類似於螞蟻的行為,在每個中間節點,調用遵循最強化的路徑。這導致對整個網絡有利的結果,並且呼叫更快地通過。

量身訂做建議(37 歲,6 年 Java 後端工程師)from chatgpt

🎯 量身訂做建議(37 歲,6 年 Java 後端工程師) 1️⃣ 先看你的條件 年齡 37 屬於「中高年資」工程師,履歷上的 深度 / 系統設計能力 會比「語言多寡」更重要。 6 年 Java 後端 代表你在 Spring Boot、資料庫、API 設計...