Spring Boot+MiniUI CRUD操作
後臺及資料庫請看另一篇文章https://blog.csdn.net/Tom_kobe/article/details/109741374
專案結構
1.建立index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<!--jQuery js-->
<script src="../static/jquery.min.js" type="text/javascript"></script>
<!--MiniUI-->
<link href="../static/demo.css" rel="stylesheet" type="text/css" />
<link href="../static/miniui/themes/default/miniui.css" rel="stylesheet" type="text/css" />
<script src="../static/miniui/miniui.js" type="text/javascript"></script>
<script src="../static/boot.js" type="text/javascript"></script>
<script src="../static/ColumnsMenu.js" type="text/javascript"></script>
</head>
<body>
<div class="mini-toolbar">
<a class="mini-button" iconCls="icon-add" onclick="addRow()">增加</a>
<a class="mini-button" iconCls="icon-edit" onclick="editRow()">修改</a>
<a class="mini-button" iconCls="icon-remove" onclick="removeRow()">刪除</a>
<a class="mini-button" iconCls="icon-save" onclick="saveData()" plain="true">儲存</a>
<span class="separator"></span>
<input id="idFilter" property="filter" class="mini-textbox" style="width: 150px;;"
onvaluechanged="onFilterChanged" emptyText="過濾名字關鍵字" />
</div>
<div id="datagrid1" class="mini-datagrid" style="width:700px;height:250px;"
url="http://localhost:8080/springboot/student/list"
allowResize="true" pageSize="20"
allowCellEdit="true" allowCellSelect="true" multiSelect="true"
editNextOnEnterKey="true" editNextRowCell="true">
<div property="columns">
<div field="id" width="120" headerAlign="center" allowSort="true">id</div>
<div field="name" width="120" headerAlign="center" allowSort="true">學生姓名
<input property="editor" class="mini-textbox" style="width:100%;" minWidth="200" />
</div>
<div field="address" width="120" headerAlign="center" allowSort="true">地址
<input property="editor" class="mini-textbox" style="width:100%;" minWidth="200" />
</div>
<div field="age" width="100" allowSort="true" >年齡</div>
<div field="birthday" width="100" headerAlign="center" dateFormat="yyyy-MM-dd" allowSort="true">建立日期
<input property="editor" class="mini-datepicker" style="width:100%;"/>
</div>
</div>
</div>
</body>
</html>
<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid1");
grid.load();
//刪除選中行
function removeRow(){
var rows=grid.getSelecteds();
if(rows.length>0){
mini.confirm("確定刪除記錄?","警告",function(action){//confirm返回Boolean,mini.confirm()返回警告框,必須加回撥函式
if(action=="ok"){
romve(rows);
}
})
}else{
mini.alert("請選中一條記錄");
}
};
function romve(rows){
var id = rows[0].id;
$.ajax({
type: "GET",
url: "http://localhost:8080/springboot/student/del?id="+id,
dataType: "json",
success: function(data){
if (data.code == 200){
grid.removeRows(rows);
} else{
mini.alert("刪除失敗");
}
}
});
}
//彈出子頁面新增一條資料
function addRow(){
mini.open({
targetWindow: window,url:"http://localhost:8080/springboot/index/edit",title:"新增記錄",width:600,height:200,showMaxButton: true,
onload: function () {
var iframe = this.getIFrameEl();
},
ondestroy: function (action) {
if(action=="ok"){
var iframe = this.getIFrameEl();
var data = iframe.contentWindow.GetData();
var stu = {"name":data.name,
"address":data.address,
"age":data.age,
"birthday":mini.formatDate(data.birthday, "yyyy-MM-dd")};
$.ajax({
type: "POST",
url: "http://localhost:8080/springboot/student/insert",
data: stu,
dataType: "json",
success: function(data){
if (data.code == 200){
grid.load();
} else{
mini.alert("新增失敗");
}
}
});
}
}
})
};
//編輯選中行,id不能修改
function editRow(){
var row=grid.getSelected();
if(row){
mini.open({
targetWindow:window,url:"http://localhost:8080/springboot/index/edit",title:"修改資訊",width:600,height:200,showMaxButton:true,
onload:function(){
var iframe = this.getIFrameEl();
var data = {action: "edit",edit_item:row};
console.log(data);
iframe.contentWindow.SetData(data);
},
ondestroy:function(action){
if(action=="ok"){
var iframe=this.getIFrameEl();
var data=iframe.contentWindow.GetData();
console.log(data);
var stu = {"id":data.id,
"name":data.name,
"address":data.address,
"age":data.age,
"birthday":mini.formatDate(data.birthday, "yyyy-MM-dd")};
console.log(stu);
$.ajax({
type: "POST",
url: "http://localhost:8080/springboot/student/update",
data: stu,
dataType: "json",
success: function(data){
if (data.code == 200){
grid.load();
} else{
mini.alert("修改失敗");
}
}
});
}
}
})
}else{
mini.alert("請選中一條記錄");
}
};
//模糊查詢輸入框裡的記錄
function onFilterChanged(e) {
var idbox = mini.get("idFilter");
var id = idbox.getValue().toLowerCase();
grid.filter(function (row) {
var r1 = true;
if (id) {
//有關鍵字即可查詢,精準查詢為String(row.name).toLowerCase().indexOf(name) != -1
r1 = String(row.id).toLowerCase().indexOf(id) != -1;
return r1;
}
return r1;
});
}
</script>
2.建立edit.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!--jQuery js-->
<script src="../static/jquery.min.js" type="text/javascript"></script>
<!--MiniUI-->
<link href="../static/demo.css" rel="stylesheet" type="text/css" />
<link href="../static/miniui/themes/default/miniui.css" rel="stylesheet" type="text/css" />
<script src="../static/miniui/miniui.js" type="text/javascript"></script>
<script src="../static/boot.js" type="text/javascript"></script>
<script src="../static/ColumnsMenu.js" type="text/javascript"></script>
</head>
<body>
<form id="form1">
<fieldset style="border:solid 1px #aaa;padding:3px;">
<legend >基本資訊</legend>
<div style="padding:5px;">
<table>
<tr>
<input class="mini-hidden" name="id" visible="false" />
<td style="width:80px;">姓名:</td>
<td style="width:150px;">
<input name="name" class="mini-textbox" required="true"/>
</td>
<td style="width:80px;">年齡:</td>
<td style="width:150px;">
<input name="age" class="mini-textbox" required="true"/>
</td>
</tr>
<tr>
<td style="width:80px;">地址:</td>
<td style="width:150px;">
<input name="address" class="mini-textbox" required="true"/>
</td>
<td style="width:80px;">生日:</td>
<td style="width:150px;">
<input name="birthday" class="mini-datepicker" required="true"/>
</td>
</tr>
</table>
</div>
</fieldset>
<div style="text-align:center;padding:10px;">
<a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">確定</a>
<a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>
</div>
</form>
</body>
</html>
<script type="text/javascript">
mini.parse();
var form = new mini.Form("form1");
function GetData() {
var o = form.getData();
return o;
}
function SetData(data){
var fields = form.getFields();
var c=fields[0];
if(data.action="edit"){
data=$.extend(true,data,data);
if(c.setReadOnly){ //設定控制元件只讀
c.setReadOnly(true);
}
form.setData(data.edit_item);
}
}
//關閉子頁面
function closeWindow(action) {
if (window.CloseOwnerWindow){
return window.CloseOwnerWindow(action,GetData);
}else{
window.close();
}
}
function onOk() {
closeWindow("ok");
}
function onCancel() {
closeWindow("cancel");
}
</script>
這個crud純屬練習miniUI的基本操作,如有什麼疑問可以在評論區討論
相關文章
- Spring Boot Crud操作示例 | Java Code GeeksSpring BootJava
- Spring Boot整合Mybatis完成級聯一對多CRUD操作Spring BootMyBatis
- go操作mongo CRUDGo
- Elasticsearch CRUD基本操作Elasticsearch
- MyBatis 的簡單 CRUD 操作MyBatis
- Mybatis:CRUD操作及配置解析MyBatis
- 使用PreparedStatement實現CRUD操作
- 07-SpringBoot+MyBatis+Spring 技術整合實現商品模組的CRUD操作Spring BootMyBatis
- JPA工程的建立和CRUD操作
- MongoDB 4.X CRUD基本操作MongoDB
- MybatisPlus入門(三)MybatisPlus CRUD操作MyBatis
- JPA之使用JPQL進行CRUD操作
- 使用Spring Boot反應式R2DBC實現PostgreSQL的CRUD操作原始碼 - RajeshSpring BootSQL原始碼
- 使用go在mongodb中進行CRUD操作MongoDB
- 二叉排序樹BST及CRUD操作排序
- MyBatis-Plus:簡化 CRUD 操作的藝術MyBatis
- ES 筆記四:文件的基本 CRUD 與批量操作筆記
- 使用“純”Servlet做一個單表的CRUD操作Servlet
- Spring04——Spring操作JdbcTemplate進行JDBC操作SpringJDBC
- 教程:如何在.NET中使用MongoDB以及基本的CRUD操作MongoDB
- 【MongoDB學習筆記】-使用 MongoDB 進行 CRUD 操作(下)MongoDB筆記
- 【MongoDB學習筆記】-使用 MongoDB 進行 CRUD 操作(上)MongoDB筆記
- CRUD更要知道的Spring事務傳播機制Spring
- 如何基於COLA架構快速實現一個CRUD操作架構
- Spring Data JPA + QueryDSL實現CRUD和複雜查詢案例Spring
- 推薦一個Dapper擴充套件CRUD基本操作的開源庫APP套件
- Spring Boot的基本操作Spring Boot
- Spring Cloud Gateway 限流操作SpringCloudGateway
- CRUD搬磚兩三年了,怎麼閱讀Spring原始碼?Spring原始碼
- Spring Boot (五)Spring Data JPA 操作 MySQL 8Spring BootMySql
- 你可以 CRUD,但你不是 CRUD 程式設計師!程式設計師
- Spring Boot中快速操作MongodbSpring BootMongoDB
- spring-data-mongodb常用操作SpringMongoDB
- MyBatis-03(CRUD)MyBatis
- Mybatis-02 CRUDMyBatis
- mysql CRUD筆記MySql筆記
- Spring Boot整合Redis實戰操作Spring BootRedis
- testng + mockito + spring boot test 基本操作MockitoSpring Boot