在jeecgboot中制作查詢報(bào)表非常方便,可以在online報(bào)表配置中快速完成。
在數(shù)據(jù)庫(kù)中可以看到對(duì)應(yīng)的兩張表存放這些配置,一張是onl_cgreport_head,存放查詢表的頭部信息。
另一張是明細(xì)表onl_cgreport_item,存放查詢報(bào)表的字段信息。
在開發(fā)數(shù)據(jù)大屏?xí)r需要很多查詢數(shù)據(jù),可以先在online報(bào)表中配置查詢SQL,通過報(bào)表查看需要的數(shù)據(jù),然后用VBA通過數(shù)據(jù)庫(kù)中的這兩張表可以生成jeecgboot后端接口代碼。
首先在MySQL 官網(wǎng)上下載 Excel 連接 MySQL 數(shù)據(jù)庫(kù)的工具,連接為: https://dev.mysql.com/downloads/windows/excel/
連接mysql的方法
查詢SQL數(shù)據(jù)并顯示到listview的方法
將上面方法放到類模塊中,就可以實(shí)例化對(duì)象來使用方法。
如連接數(shù)據(jù)庫(kù),將編碼以"sql_"開頭的的SQL報(bào)表顯示到listview1中
msql.OpenMySQLConnection IP, PORT, DATABASE, USERNAME, PASSWORD msql.dataToListView?"select?*?from?onl_cgreport_head?where?left(code,4)=""sql_""",?ListView1
選擇SQL報(bào)表,顯示明細(xì)到listview2中。
Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem) ? ? msql.dataToListView "select * from onl_cgreport_item where cgrhead_id=""" & Item.Text & """", ListView2 End Sub
一鍵生成文件夾、java和xml文件
If ListView1.SelectedItem Is Nothing Then Else ? ? folderPath = ThisWorkbook.Path & "\api" ? ? entity = Replace(ListView1.SelectedItem.SubItems(1), "sql_", "") ? ? desc = ListView1.SelectedItem.SubItems(2) ? ? cf.MakeFolder folderPath ? ? cf.MakeFolder folderPath & "\" & entity ? ? cf.MakeFolder folderPath & "\" & entity & "\controller" ? ? createController ? ? cf.MakeFolder folderPath & "\" & entity & "\entity" ? ? createEntity ? ? cf.MakeFolder folderPath & "\" & entity & "\mapper" ? ? cf.MakeFolder folderPath & "\" & entity & "\mapper\xml" ? ? createXML ? ? createMapper ? ? cf.MakeFolder folderPath & "\" & entity & "\service" ? ? createService ? ? cf.MakeFolder folderPath & "\" & entity & "\service\impl" ? ? createImpl End If
其中生成實(shí)體類的代碼
Dim cf As New CFileAction With cf ? ? .Clear ????.WriteText?"package?org.jeecg.modules.demo.api."?&?entity?&?".entity;"?&?vbCrLf ????.WriteText?"import?lombok.Data;"?&?vbCrLf ? ? .WriteText "@Data" & vbCrLf ? ? .WriteText "public class " & entity & " {" & vbCrLf ? ? For i = 1 To ListView2.ListItems.Count ? ? ? ? .WriteText " ? ?private " & ListView2.ListItems(i).SubItems(5) & " " & ListView2.ListItems(i).SubItems(2) & ";" & vbCrLf ? ? Next i ? ? .WriteText "}" & vbCrLf ? ? WriteUTF8File .txt, folderPath & "\" & entity & "\entity\" & entity & ".java" End With Set cf = Nothing
生成java代碼時(shí)需要的是沒有BOM的UTF-8編碼,一開始使用ADODB.Stream對(duì)象來保存java文件,IDEA打開后每個(gè)文件都要切換GBK再換回UTF-8編碼才能正常使用。后來用以下api函數(shù)來保存java文件,默認(rèn)bBOM為false,生成的代碼可以直接運(yùn)行使用。
Public Declare PtrSafe Function MultiByteToWideChar Lib "kernel32" ( _ ByVal CodePage As Long, _ ByVal dwFlags As Long, _ ByRef lpMultiByteStr As Any, _ ByVal cchMultiByte As Long, _ ByVal lpWideCharStr As Long, _ ByVal cchWideChar As Long) As Long Public Declare PtrSafe Function WideCharToMultiByte Lib "kernel32" ( _ ByVal CodePage As Long, _ ByVal dwFlags As Long, _ ByVal lpWideCharStr As LongPtr, _ ByVal cchWideChar As Long, _ ByRef lpMultiByteStr As Any, _ ByVal cchMultiByte As Long, _ ByVal lpDefaultChar As String, _ ByVal lpUsedDefaultChar As Long) As Long Public Const CP_UTF8 = 65001 ' 將輸入文本寫進(jìn)UTF8格式的文本文件 ' 輸入 ' strInput:文本字符串 ' strFile:保存的UTF8格式文件路徑 ' bBOM:True表示文件帶"EFBBBF"頭,F(xiàn)alse表示不 Public Sub WriteUTF8File(strInput As String, strFile As String, Optional bBOM As Boolean = False) ? ? Dim bByte As Byte ? ? Dim ReturnByte() As Byte ? ? Dim lngBufferSize As Long ? ? Dim lngResult As Long ? ? Dim TLen As Long ? ? ' 判斷輸入字符串是否為空 ? ? If Len(strInput) = 0 Then Exit Sub ? ? 'On Error GoTo errHandle ? ? ' 判斷文件是否存在,如存在則刪除 ? ? If Dir(strFile) <> "" Then Kill strFile ? ? TLen = Len(strInput) ? ? lngBufferSize = TLen * 3 + 1 ? ? ReDim ReturnByte(lngBufferSize - 1) ? ? lngResult = WideCharToMultiByte(CP_UTF8, 0, StrPtr(strInput), TLen, ReturnByte(0), lngBufferSize, vbNullString, 0) ? ? If lngResult Then ? ? ? ? lngResult = lngResult - 1 ? ? ? ? ReDim Preserve ReturnByte(lngResult) ? ? ? ? Open strFile For Binary As #1 ? ? ? ? ? ? If bBOM = True Then ? ? ? ? ? ? ? ? bByte = 239 ? ? ? ? ? ? ? ? Put #1, , bByte ? ? ? ? ? ? ? ? bByte = 187 ? ? ? ? ? ? ? ? Put #1, , bByte ? ? ? ? ? ? ? ? bByte = 191 ? ? ? ? ? ? ? ? Put #1, , bByte ? ? ? ? ? ? End If ? ? ? ? ? ? Put #1, , ReturnByte ? ? ? ? Close #1 ? ? End If End Sub
api接口測(cè)試成功。
本文使用 文章同步助手 同步
標(biāo)簽: