步骤 1 : 先运行,看到效果,再学习 步骤 2 : 模仿和排错 步骤 3 : 效果截图 步骤 4 : 页面 步骤 5 : 为空判断 步骤 6 : CategoryService 步骤 7 : CategoryServiceImpl 步骤 8 : ImageUtil 步骤 9 : CategoryAction 步骤 10 : 中文问题
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@include file="../include/admin/adminHeader.jsp"%>
<%@include file="../include/admin/adminNavigator.jsp"%>
<script>
$(function(){
$("#addForm").submit(function(){
if(!checkEmpty("name","分类名称"))
return false;
if(!checkEmpty("categoryPic","分类上传图片"))
return false;
return true;
});
});
</script>
<title>分类管理</title>
<div class="workingArea">
<h1 class="label label-info" >分类管理</h1>
<br>
<br>
<div class="listDataTableDiv">
<table class="table table-striped table-bordered table-hover table-condensed">
<thead>
<tr class="success">
<th>ID</th>
<th>图片</th>
<th>分类名称</th>
<th>属性管理</th>
<th>产品管理</th>
<th>编辑</th>
<th>删除</th>
</tr>
</thead>
<tbody>
<c:forEach items="${categorys}" var="c">
<tr>
<td>${c.id}</td>
<td><img height="40px" src="img/category/${c.id}.jpg"></td>
<td>${c.name}</td>
<td><a href="admin_property_list?category.id=${c.id}"><span class="glyphicon glyphicon-th-list"></span></a></td>
<td><a href="admin_product_list?category.id=${c.id}"><span class="glyphicon glyphicon-shopping-cart"></span></a></td>
<td><a href="admin_category_edit?category.id=${c.id}"><span class="glyphicon glyphicon-edit"></span></a></td>
<td><a deleteLink="true" href="admin_category_delete?category.id=${c.id}"><span class=" glyphicon glyphicon-trash"></span></a></td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<div class="pageDiv">
<%@include file="../include/admin/adminPage.jsp" %>
</div>
<div class="panel panel-warning addDiv">
<div class="panel-heading">新增分类</div>
<div class="panel-body">
<form method="post" id="addForm" action="admin_category_add" enctype="multipart/form-data">
<table class="addTable">
<tr>
<td>分类名称</td>
<td><input id="name" name="category.name" type="text" class="form-control"></td>
</tr>
<tr>
<td>分类圖片</td>
<td>
<input id="categoryPic" type="file" name="img" />
</td>
</tr>
<tr class="submitTR">
<td colspan="2" align="center">
<button type="submit" class="btn btn-success">提 交</button>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<%@include file="../include/admin/adminFooter.jsp"%>
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<script>
$(function(){
$("#addForm").submit(function(){
if(!checkEmpty("name","分类名称"))
return false;
if(!checkEmpty("categoryPic","分类图片"))
return false;
return true;
});
});
</script>
<script> $(function(){ $("#addForm").submit(function(){ if(!checkEmpty("name","分类名称")) return false; if(!checkEmpty("categoryPic","分类图片")) return false; return true; }); }); </script>
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.service;
import java.util.List;
import com.how2java.tmall.pojo.Category;
import com.how2java.tmall.util.Page;
public interface CategoryService{
public List list();
public void save(Category category);
public int total();
public List<Category> listByPage(Page page);
}
package com.how2java.tmall.service; import java.util.List; import com.how2java.tmall.pojo.Category; import com.how2java.tmall.util.Page; public interface CategoryService{ public List list(); public void save(Category category); public int total(); public List<Category> listByPage(Page page); }
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.service.impl;
import java.util.List;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.how2java.tmall.dao.impl.DAOImpl;
import com.how2java.tmall.pojo.Category;
import com.how2java.tmall.service.CategoryService;
import com.how2java.tmall.util.Page;
@Service
public class CategoryServiceImpl implements CategoryService {
@Autowired DAOImpl dao;
@Override
public List list() {
DetachedCriteria dc = DetachedCriteria.forClass(Category.class);
dc.addOrder(Order.desc("id"));
return dao.findByCriteria(dc);
}
@Override
public int total() {
String hql = "select count(*) from Category ";
List<Long> l= dao.find(hql);
if(l.isEmpty())
return 0;
Long result= l.get(0);
return result.intValue();
}
@Override
public List<Category> listByPage(Page page) {
DetachedCriteria dc = DetachedCriteria.forClass(Category.class);
dc.addOrder(Order.desc("id"));
return dao.findByCriteria(dc,page.getStart(),page.getCount());
}
@Override
public void save(Category category) {
dao.save(category);
}
}
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.util;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferInt;
import java.awt.image.DirectColorModel;
import java.awt.image.PixelGrabber;
import java.awt.image.Raster;
import java.awt.image.RenderedImage;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ImageUtil {
public static BufferedImage change2jpg(File f) {
try {
java.awt.Image i = Toolkit.getDefaultToolkit().createImage(f.getAbsolutePath());
PixelGrabber pg = new PixelGrabber(i, 0, 0, -1, -1, true);
pg.grabPixels();
int width = pg.getWidth(), height = pg.getHeight();
final int[] RGB_MASKS = { 0xFF0000, 0xFF00, 0xFF };
final ColorModel RGB_OPAQUE = new DirectColorModel(32, RGB_MASKS[0], RGB_MASKS[1], RGB_MASKS[2]);
DataBuffer buffer = new DataBufferInt((int[]) pg.getPixels(), pg.getWidth() * pg.getHeight());
WritableRaster raster = Raster.createPackedRaster(buffer, width, height, width, RGB_MASKS, null);
BufferedImage img = new BufferedImage(RGB_OPAQUE, raster, false, null);
return img;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public static void resizeImage(File srcFile, int width,int height, File destFile) {
try {
Image i = ImageIO.read(srcFile);
i = resizeImage(i, width, height);
ImageIO.write((RenderedImage) i, "jpg", destFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Image resizeImage(Image srcImage, int width, int height) {
try {
BufferedImage buffImg = null;
buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
buffImg.getGraphics().drawImage(srcImage.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0, 0, null);
return buffImg;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.action;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import com.how2java.tmall.pojo.Category;
import com.how2java.tmall.service.CategoryService;
import com.how2java.tmall.util.ImageUtil;
import com.how2java.tmall.util.Page;
@Namespace("/")
@ParentPackage("basicstruts")
@Results(
{
/*分类管理*/
@Result(name="listCategory", location="/admin/listCategory.jsp"),
@Result(name="listCategoryPage", type = "redirect", location="/admin_category_list"),
})
public class CategoryAction {
@Autowired
CategoryService categoryService;
List<Category> categorys;
Category category;
File img;
Page page;
@Action("admin_category_list")
public String list() {
if(page==null)
page = new Page();
int total = categoryService.total();
page.setTotal(total);
categorys = categoryService.listByPage(page);
return "listCategory";
}
@Action("admin_category_add")
public String add() {
categoryService.save(category);
File imageFolder= new File(ServletActionContext.getServletContext().getRealPath("img/category"));
File file = new File(imageFolder,category.getId()+".jpg");
try {
FileUtils.copyFile(img, file);
BufferedImage img = ImageUtil.change2jpg(file);
ImageIO.write(img, "jpg", file);
} catch (IOException e) {
e.printStackTrace();
}
return "listCategoryPage";
}
public List<Category> getCategorys() {
return categorys;
}
public void setCategorys(List<Category> categorys) {
this.categorys = categorys;
}
public Page getPage() {
return page;
}
public void setPage(Page page) {
this.page = page;
}
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public File getImg() {
return img;
}
public void setImg(File img) {
this.img = img;
}
}
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<web-app>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<constant name="struts.objectFactory" value="spring"/>
<package name="basicstruts" extends="struts-default">
</package>
</struts>
HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
|