需要增删改查
简单的页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>个人简历</title>
</head>
<style>
td{
width: 80px;
}
</style>
<body>
<table border="1" width="650" height="680" align="center" cellspacing="0">
<caption>个人简历</caption>
<tr align="center">
<td bgcolor="#ededed">姓名</td>
<td></td>
<td bgcolor="#ededed">年龄</td>
<td></td>
<td bgcolor="#ededed">性别</td>
<td></td>
<td colspan="2" rowspan="3"></td>
</tr>
<tr align="center">
<td bgcolor="#ededed">民族</td>
<td></td>
<td bgcolor="#ededed">政治面貌</td>
<td></td>
<td bgcolor="#ededed">婚姻状况</td>
<td></td>
</tr>
<tr align="center">
<td bgcolor="#ededed">毕业学校</td>
<td colspan="2"></td>
<td bgcolor="#ededed">所学专业</td>
<td colspan="2"></td>
</tr>
<tr align="center">
<td bgcolor="#ededed">专业能力</td>
<td colspan="7"></td>
</tr>
<tr align="center">
<td bgcolor="#ededed">求职意向</td>
<td colspan="7"></td>
</tr>
<tr align="center">
<td bgcolor="#ededed">获奖情况</td>
<td colspan="7"></td>
</tr>
<tr align="center">
<td bgcolor="#ededed">自我评价</td>
<td colspan="7"></td>
</tr>
</table>
</body>
</html>
si
package com.itheima.jdbc;
import java.awt.EventQueue;
import java.awt.Font;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import java.awt.Color;
/**
* @author lzg
* @date 2019年12月23日 下午9:18:18
* @Description
*/
@SuppressWarnings("serial")
public class InformationInput extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
private JTextField textField_5;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
InformationInput frame = new InformationInput();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public InformationInput() {
setFont(new Font("微软雅黑", Font.PLAIN, 14));
setTitle("个人信息的录入");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 556);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
setLocationRelativeTo(null);//将窗口居中
JLabel lblNewLabel = new JLabel("学 号:");
lblNewLabel.setForeground(Color.WHITE);
lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
lblNewLabel.setBounds(10, 10, 42, 15);
contentPane.add(lblNewLabel);
textField = new JTextField();
textField.setFont(new Font("微软雅黑", Font.PLAIN, 16));
textField.setBounds(62, 4, 271, 30);
contentPane.add(textField);
textField.setColumns(10);
JLabel label = new JLabel("姓 名:");
label.setForeground(Color.WHITE);
label.setFont(new Font("微软雅黑", Font.PLAIN, 16));
label.setBounds(10, 55, 47, 15);
contentPane.add(label);
textField_1 = new JTextField();
textField_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
textField_1.setColumns(10);
textField_1.setBounds(62, 49, 271, 30);
contentPane.add(textField_1);
JLabel label_1 = new JLabel("性 别:");
label_1.setForeground(Color.WHITE);
label_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
label_1.setBounds(10, 100, 47, 15);
contentPane.add(label_1);
JComboBox comboBox = new JComboBox();
comboBox.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "男", "女"}));
comboBox.setFont(new Font("微软雅黑", Font.PLAIN, 16));
comboBox.setToolTipText("");
comboBox.setBounds(62, 98, 89, 21);
contentPane.add(comboBox);
JLabel label_2 = new JLabel("生 日:");
label_2.setForeground(Color.WHITE);
label_2.setFont(new Font("微软雅黑", Font.PLAIN, 14));
label_2.setBounds(10, 139, 47, 15);
contentPane.add(label_2);
textField_2 = new JTextField();
textField_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
textField_2.setColumns(10);
textField_2.setBounds(62, 133, 271, 30);
contentPane.add(textField_2);
JLabel label_3 = new JLabel("年 龄:");
label_3.setForeground(Color.WHITE);
label_3.setFont(new Font("微软雅黑", Font.PLAIN, 16));
label_3.setBounds(10, 183, 47, 15);
contentPane.add(label_3);
textField_3 = new JTextField();
textField_3.setFont(new Font("微软雅黑", Font.PLAIN, 16));
textField_3.setColumns(10);
textField_3.setBounds(62, 177, 271, 30);
contentPane.add(textField_3);
JLabel label_4 = new JLabel("籍 贯:");
label_4.setForeground(Color.WHITE);
label_4.setFont(new Font("微软雅黑", Font.PLAIN, 16));
label_4.setBounds(10, 225, 47, 15);
contentPane.add(label_4);
JComboBox comboBox_1 = new JComboBox();
comboBox_1.setFont(new Font("微软雅黑", Font.PLAIN, 14));
comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "北京市 ", "天津市", "上海市 ", "重庆市", "河北省 ", "河南省 ", "云南省 ", "辽宁省 ", "黑龙江省 ", "湖南省", "安徽省", "山东省 ", "新疆维吾尔", "江苏省", "浙江省", "江西省", "湖北省", "广西壮族", "甘肃省", "山西省", "内蒙古", "陕西省", "吉林省", "福建省", "贵州省", "广东省", "青海省", "西藏", "四川省", "宁夏回族", "海南省"}));
comboBox_1.setBounds(62, 225, 89, 21);
contentPane.add(comboBox_1);
JLabel label_5 = new JLabel("院 系:");
label_5.setForeground(Color.WHITE);
label_5.setFont(new Font("微软雅黑", Font.PLAIN, 16));
label_5.setBounds(10, 264, 47, 15);
contentPane.add(label_5);
JComboBox comboBox_2 = new JComboBox();
comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "潇湘学院", "计算机学院", "软件学院", "教育学院", "体育科学学院", "医学院", "商学院,", "艺术学院", "政治学院", "管理学院,", "外国语学院,", "生命科学学院", "机械工程学院", "电子信息学院", "电气工程学院", "化学化工学院", "地理科学学院"}));
comboBox_2.setToolTipText("");
comboBox_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
comboBox_2.setBounds(62, 262, 89, 21);
contentPane.add(comboBox_2);
JComboBox comboBox_3 = new JComboBox();
comboBox_3.setModel(new DefaultComboBoxModel(new String[] {"-请选择-", "软件工程", "经济学", "统计学", "哲学", "材料成型及控制工程、", "市场营销", "会计学", "生物工程", "人力资源管", "机械设计制造及自动化、", "通信工程", "自动化", "计算机科学与技术", "信息工程", "电子信息工程", "测绘工程", "英语", "翻译", "化学工程与工艺、", "制药工程"}));
comboBox_3.setToolTipText("");
comboBox_3.setFont(new Font("微软雅黑", Font.PLAIN, 16));
comboBox_3.setBounds(62, 297, 89, 21);
contentPane.add(comboBox_3);
JLabel label_6 = new JLabel("专 业:");
label_6.setForeground(Color.WHITE);
label_6.setFont(new Font("微软雅黑", Font.PLAIN, 16));
label_6.setBounds(10, 301, 47, 15);
contentPane.add(label_6);
JLabel label_7 = new JLabel("班 级:");
label_7.setForeground(Color.WHITE);
label_7.setFont(new Font("微软雅黑", Font.PLAIN, 16));
label_7.setBounds(10, 341, 47, 15);
contentPane.add(label_7);
textField_4 = new JTextField();
textField_4.setFont(new Font("微软雅黑", Font.PLAIN, 16));
textField_4.setColumns(10);
textField_4.setBounds(62, 335, 271, 30);
contentPane.add(textField_4);
JLabel lblPhone = new JLabel("电 话:");
lblPhone.setForeground(Color.WHITE);
lblPhone.setFont(new Font("微软雅黑", Font.PLAIN, 16));
lblPhone.setBounds(10, 390, 90, 15);
contentPane.add(lblPhone);
textField_5 = new JTextField();
textField_5.setFont(new Font("微软雅黑", Font.PLAIN, 16));
textField_5.setColumns(10);
textField_5.setBounds(62, 384, 271, 30);
contentPane.add(textField_5);
JButton button = new JButton("确定");
button.setFont(new Font("微软雅黑", Font.BOLD, 18));
button.setBounds(22, 446, 93, 41);
contentPane.add(button);
button.addActionListener(new ActionListener() { //数据的插入
public void actionPerformed(ActionEvent e) {
String s1=textField.getText();
String s2=textField_1.getText();
String s3=(String)comboBox.getSelectedItem();
String s4=textField_2.getText();
String s5=textField_3.getText();
String s6=(String)comboBox_1.getSelectedItem();
String s7=(String)comboBox_2.getSelectedItem();
String s8=(String)comboBox_3.getSelectedItem();
String s9=textField_4.getText();
String s10=textField_5.getText();
if(s1 == null || s1.isEmpty()){
JOptionPane.showMessageDialog(null, "学号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
}else if(s2 == null || s2.isEmpty()) {
JOptionPane.showMessageDialog(null, "姓名不能为空", "警告", JOptionPane.ERROR_MESSAGE);
}else if(s3 == null || s3.isEmpty()) {
JOptionPane.showMessageDialog(null, "性别不能为空", "警告", JOptionPane.ERROR_MESSAGE);
}else if(s4 == null || s4.isEmpty()) {
JOptionPane.showMessageDialog(null, "生日不能为空", "警告", JOptionPane.ERROR_MESSAGE);
}else if(s5 == null || s5.isEmpty()) {
JOptionPane.showMessageDialog(null, "年龄不能为空", "警告", JOptionPane.ERROR_MESSAGE);
}else if(s6 == null || s6.isEmpty()) {
JOptionPane.showMessageDialog(null, "籍贯不能为空", "警告", JOptionPane.ERROR_MESSAGE);
}else if(s7 == null || s7.isEmpty()) {
JOptionPane.showMessageDialog(null, "院系不能为空", "警告", JOptionPane.ERROR_MESSAGE);
}else if(s8 == null || s8.isEmpty()) {
JOptionPane.showMessageDialog(null, "专业不能为空", "警告", JOptionPane.ERROR_MESSAGE);
}else if(s9 == null || s9.isEmpty()) {
JOptionPane.showMessageDialog(null, "班级不能为空", "警告", JOptionPane.ERROR_MESSAGE);
}else if(s10 == null || s10.isEmpty()) {
JOptionPane.showMessageDialog(null, "电话不能为空", "警告", JOptionPane.ERROR_MESSAGE);
}else {
String sql="insert into student(学号,姓名,性别,生日,年龄,籍贯 ,院系,专业,班级,电话) values(?,?,?,?,?,?,?,?,?,?)";
JDBCutil jdbc=new JDBCutil();
jdbc.testUpdate(sql, s1,s2,s3,s4,s5,s6,s7,s8,s9,s10);
JOptionPane.showMessageDialog(null, "信息录入成功!", "信息", JOptionPane.INFORMATION_MESSAGE);
}
}
});
JButton button_1 = new JButton("取消");
button_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
button_1.setBounds(300, 446, 93, 41);
contentPane.add(button_1);
JButton button_2 = new JButton("再次录入");
button_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField.setText("");
textField_1.setText("");
textField_2.setText("");
textField_3.setText("");
textField_4.setText("");
textField_5.setText("");
JOptionPane.showMessageDialog(null, "请再次录入信息!", "信息", JOptionPane.INFORMATION_MESSAGE);
}
});
button_2.setFont(new Font("微软雅黑", Font.BOLD, 18));
button_2.setBounds(158, 446, 111, 41);
contentPane.add(button_2);
JLabel lblNewLabel_1 = new JLabel("");
lblNewLabel_1.setIcon(new ImageIcon(InformationInput.class.getResource("/ico/653AD1ADFA0F5A89886F47B2C3C91595.jpg")));
lblNewLabel_1.setBounds(0, 0, 434, 517);
contentPane.add(lblNewLabel_1);
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "恭喜你已安全退出!", "信息", JOptionPane.INFORMATION_MESSAGE);
dispose();
}
});
}
}
需要增删改查 这不得搞后端?
你这个需要什么功能?是整个项目吗?
信息管理页(增删改查封装)
<template>
<div class="InfoLists">
<!-- 查询、重置 -->
<el-form
:inline="true"
:model="formInline"
class="demo-form-inline"
size="small"
>
<el-form-item>
<el-input
v-model="formInline.name"
prefix-icon="el-icon-search"
placeholder="请输入姓名"
></el-input>
</el-form-item>
<el-form-item>
<el-button
@click="find()"
type="primary"
icon="el-icon-search"
circle
size="small"
></el-button>
</el-form-item>
<el-form-item>
<el-button
type="success"
@click="addUser()"
circle
size="small"
icon="el-icon-circle-plus-outline"
></el-button>
</el-form-item>
<el-form-item>
<el-button
type="success"
plain
@click="refresh()"
circle
size="small"
icon="el-icon-refresh"
></el-button>
</el-form-item>
<el-form-item>
<el-button
type="danger"
plain
@click="delPitch()"
circle
size="small"
icon="el-icon-delete"
></el-button>
</el-form-item>
</el-form>
<!-- <el-table :data="
tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
" height="450" border style="width: 100%" :default-sort="{ prop: 'number', order: 'Ascending' }"> -->
<el-table
:data="compData"
height="450"
border
style="width: 100%"
:default-sort="{ prop: 'number', order: 'Ascending' }"
>
<!-- <el-table-column prop="id" label="序号" align="center"></el-table-column> -->
<el-table-column type="selection" width="55"> </el-table-column>
<el-table-column prop="name" label="姓名" align="center">
</el-table-column>
<el-table-column prop="sex_text" label="性别" align="center">
</el-table-column>
<el-table-column prop="age" label="年龄" align="center" sortable>
</el-table-column>
<el-table-column prop="father" label="父亲" align="center">
</el-table-column>
<el-table-column prop="mather" label="母亲" align="center">
</el-table-column>
<el-table-column prop="time" label="入校时间" align="center">
</el-table-column>
<el-table-column prop="address" label="家庭住址" align="center">
</el-table-column>
<el-table-column prop="phone" label="联系方式" align="center">
</el-table-column>
<el-table-column fixed="right" label="操作" width="100" align="center">
<template slot-scope="scope">
<el-button
@click="edit(scope.row)"
type="primary"
icon="el-icon-edit"
circle
size="mini"
></el-button>
<el-button
@click="del(scope.row)"
type="danger"
icon="el-icon-delete"
circle
size="mini"
></el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[5, 10, 20, 30, 50]"
:page-size="pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
>
</el-pagination>
<el-dialog
:title="compTitle"
:visible.sync="dialogFormVisible"
width="500px"
>
<el-form :model="newUserForm" :rules="rules" ref="newUserForm">
<el-form-item label="姓名" :label-width="formLabelWidth" prop="name">
<el-input v-model="newUserForm.name" autocomplete="off"></el-input>
</el-form-item>
<el-form-item
label="性别"
:label-width="formLabelWidth"
prop="sex"
icon="el-icon-male"
>
<el-radio v-model="newUserForm.sex" label="1"
><i class="el-icon-male"></i>男</el-radio
>
<el-radio v-model="newUserForm.sex" label="2"
><i class="el-icon-female"></i>女</el-radio
>
</el-form-item>
<el-form-item label="年龄" :label-width="formLabelWidth" prop="age">
<el-input v-model="newUserForm.age" autocomplete="off"></el-input>
</el-form-item>
<el-form-item
label="父亲姓名"
:label-width="formLabelWidth"
prop="father"
>
<el-input v-model="newUserForm.father" autocomplete="off"></el-input>
</el-form-item>
<el-form-item
label="母亲姓名"
:label-width="formLabelWidth"
prop="mather"
>
<el-input v-model="newUserForm.mather" autocomplete="off"></el-input>
</el-form-item>
<el-form-item
label="入校时间"
:label-width="formLabelWidth"
prop="time"
>
<el-date-picker
v-model="newUserForm.time"
align="right"
format="yyyy 年 MM 月 dd 日"
value-format="yyyy/MM/dd"
type="date"
placeholder="选择入校日期"
:picker-options="pickAfter"
>
</el-date-picker>
</el-form-item>
<el-form-item
label="家庭住址"
:label-width="formLabelWidth"
prop="address"
>
<el-input v-model="newUserForm.address" autocomplete="off"></el-input>
</el-form-item>
<el-form-item
label="联系方式"
:label-width="formLabelWidth"
prop="phone"
>
<el-input v-model="newUserForm.phone" autocomplete="off"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="closeForm('newUserForm')">取 消</el-button>
<el-button type="primary" @click="confirm('newUserForm')"
>确 定</el-button
>
</div>
</el-dialog>
</div>
</template>
<script>
import { getData, changeInfo, delData } from "@/utils/table.js";
import {
NotNullRule,
newUsernameRule,
ageRule,
phoneRule,
} from "@/utils/validate";
export default {
data() {
return {
tableData: [],
currentPage: 1, //当前页数
pageSize: 10, //每页显示条数
total: 0,
dialogFormVisible: false,
formInline: {
name: "",
},
newUserForm: {
name: "",
sex: "1",
age: "",
father: "",
mather: "",
time: "",
address: "",
phone: "",
},
pickAfter: {
disabledDate(time) {
return time.getTime() > Date.now(); // 如果没有后面的-8.64e7就是不可以选择今天的
},
},
rules: {
name: [{ validator: newUsernameRule, trigger: "blur", required: true }],
sex: [{ validator: NotNullRule, trigger: "blur", required: true }],
age: [{ validator: ageRule, trigger: "blur", required: true }],
time: [{ validator: NotNullRule, trigger: "blur", required: true }],
address: [{ validator: NotNullRule, trigger: "blur", required: true }],
phone: [{ validator: phoneRule, trigger: "blur", required: true }],
},
formLabelWidth: "80px",
formState: true,
};
},
created() {
getData(this, '/info');
},
computed: {
compData() {
return this.tableData.slice(
(this.currentPage - 1) * this.pageSize,
this.currentPage * this.pageSize
);
},
compTitle() {
return this.formState ? "修改用户信息" : "新增用户信息";
},
},
methods: {
addUser() {
this.formState = false;
this.dialogFormVisible = true;
this.newUserForm = {
name: "",
sex: "1",
age: "",
father: "",
mather: "",
time: "",
address: "",
phone: "",
};
},
edit(row) {
this.formState = true;
this.dialogFormVisible = true;
// this.newUserForm = row;
this.newUserForm = { ...row };
},
confirm(newUserForm) {
this.$refs[newUserForm].validate((valid) => {
if (valid) {
let methods = ''
this.formState ? methods = 'put' : methods = 'post'
changeInfo(this, methods, '/info', this.newUserForm, getData)
}
});
},
closeForm(newUserForm) {
this.$refs[newUserForm].resetFields();
this.dialogFormVisible = false;
},
find() {
this.getData(this.formInline);
},
refresh() {
this.formInline = {};
this.getData(this.formInline);
},
del(row) {
delData(this, '/info', row.id, getData)
},
handleSizeChange(val) {
this.pageSize = val;
this.currentPage = 1;
},
handleCurrentChange(val) {
this.currentPage = val;
},
},
};
</script>
<style lang="scss">
.InfoLists {
.demo-form-inline {
text-align: left;
}
.el-pagination {
text-align: left;
margin-top: 20x;
}
}
</style>
//获取表格数据
export function getData(root, url, params) {
root.service
.get(url, { params: params || {} })
.then((res) => {
if (res.data.status === 200) {
root.tableData = res.data.data;
root.total = res.data.total;
root.tableData.forEach((item) => {
item.sex === '1' ? (item.sex_text = "男") : (item.sex_text = "女");
});
}
})
.catch((error) => {
throw error;
});
}
//新增和修改
import qs from "qs";
export function changeInfo(root, method, url, form, callback) {
let data = qs.stringify(form);
root.service[method](url, data)
.then((res) => {
if (res.data.status === 200) {
callback(root, url); // = root.getData()
// root.$refs['form'].resetFields();
root.dialogFormVisible = false;
root.$message({ message: res.data.message, type: "success" });
}
})
.catch((error) => {
throw error;
});
}
//删除
export function delData(root, url, id, callback) {
root.$alert("你确定要删除吗?", "提示", {
confirmButtonText: "确定",
callback: () => {
root.service
.delete(`${url}/${id}`)
.then((res) => {
if (res.data.status === 200) {
callback(root, url); // = root.getData()
root.$message({ message: res.data.message, type: "success" });
}
})
.catch((error) => {
throw error;
});
},
});
}