⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 categoryitemeditaction.java

📁 工厂版本管理系统,STRUTS2框架,用于管理商品的版本,便于有效的控制版本
💻 JAVA
字号:
package com.bluesky.elecall.web.struts.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import com.bluesky.elecall.domain.CategoryItem;
import com.opensymphony.xwork2.Preparable;

public class CategoryItemEditAction extends BaseAction implements Preparable {

	
	private Long categoryItemId;
	private CategoryItem categoryItem;
	private File image;
	private String imageContentType;
	private String imageFileName;

	public CategoryItemEditAction() {
		categoryItem = new CategoryItem();
		categoryItem.setParent(new CategoryItem());
	}
	public void prepare() throws Exception {
	}

	@Override
	public String input() throws Exception {
		if (categoryItemId != null)
			categoryItem = (CategoryItem) reposity.get(CategoryItem.class,
					categoryItemId);
		
		

		return super.input();
	}

	public String delete(){
		reposity.delete(CategoryItem.class, categoryItemId);
		
		return SUCCESS;
	}
	
	public String save() throws Exception {

		Long imageFileId =null;

		// save image to DB
		if (image != null) {
			InputStream is = new FileInputStream(image);
			byte[] buffer = new byte[1023 * 1024 * 10];
			int len = is.read(buffer);
			is.close();

			byte[] data = new byte[len];
			for (int i = 0; i < len; i++)
				data[i] = buffer[i];

			com.bluesky.system.File file = new com.bluesky.system.File();
			file.setContentType(imageContentType);
			file.setData(data);

			reposity.save(file);
			
			imageFileId = file.getId();			
		}

		if (categoryItem.getId() == null) {
			CategoryItem parentEntity = productCategory
					.getCategoryItem(categoryItem.getParent().getId());

			CategoryItem newItem = new CategoryItem();

			newItem.setName(categoryItem.getName().trim());
			
			newItem.setParent(parentEntity);
			newItem.setLevel(parentEntity.getLevel() + 1);
			
			newItem.setImageFileId(imageFileId);

			productCategory.save(newItem);
			
		} else {
			CategoryItem entity = (CategoryItem) reposity.get(CategoryItem.class,
					categoryItem.getId());
			entity.setName(categoryItem.getName());
			
			if(imageFileId!=null){
				if(entity.getImageFileId()!=null)
					reposity.delete(com.bluesky.system.File.class, entity.getImageFileId());
				
				entity.setImageFileId(imageFileId);
			}
			
			reposity.update(entity);
		}
		return SUCCESS;
	}

	public Long getCategoryItemId() {
		return categoryItemId;
	}

	public void setCategoryItemId(Long categoryItemId) {
		this.categoryItemId = categoryItemId;
	}

	public CategoryItem getCategoryItem() {
		return categoryItem;
	}

	public void setCategoryItem(CategoryItem categoryItem) {
		this.categoryItem = categoryItem;
	}

	public File getImage() {
		return image;
	}

	public void setImage(File image) {
		this.image = image;
	}

	public String getImageContentType() {
		return imageContentType;
	}

	public void setImageContentType(String imageContentType) {
		this.imageContentType = imageContentType;
	}

	public String getImageFileName() {
		return imageFileName;
	}

	public void setImageFileName(String imageFileName) {
		this.imageFileName = imageFileName;
	}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -