1、实体上新增字段类型为byteArray
2、对应的数据库表上增加字段数据类型为blob,跟实体上的字段绑定
3、UI界面上增加KDLabel
2、EditUI上增加实现代码
//双击选择图片
@Override
protected void lbphoto_mouseClicked(MouseEvent e) throws Exception {
int count = e.getClickCount();
if (count == 2) {
selectPhoto();
}
}
//选择图片
private void selectPhoto() throws Exception{
KDFileChooser fileChooser = new KDFileChooser();
fileChooser.setFileFilter(new PictureFilter());
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showOpenDialog(this);
if(result == 0) {
java.io.File file = fileChooser.getSelectedFile();
byte[] bt = HRUtil.convertFileTOBytes(file);
Image image = ImageIO.read(new ByteArrayInputStream(bt));
// ImageIcon icon = new ImageIcon(image);
KDImageIcon icon = new KDImageIcon(image);
lbphoto.setIcon(icon);
editData.setPhoto(bt);
}
}
//打开单据加载图片
@Override
public void onShow() throws Exception {
super.onShow();
if (UIRuleUtil.isNotNull(editData.getPhoto())) {
Image image = ImageIO.read(new ByteArrayInputStream(editData.getPhoto()));
lbphoto.setIcon(new KDImageIcon(image));
}
}
//删除图片代码
@Override
protected void btndelphoto_actionPerformed(ActionEvent e) throws Exception {
int i = MsgBox.showConfirm2(this, "是否确认删除图片?");
if (MsgBox.OK == i) {
lbphoto.setIcon(null);
editData.setPhoto(null);
}
}
//选择图片按钮
@Override
protected void btnupphoto_actionPerformed(ActionEvent e) throws Exception {
selectPhoto();
}