分类列表中编辑和油画列表中编辑的问题
分类列表中编辑问题
E:\apacheTomcat\apache-tomcat-8.5.39\bin\catalina.bat run
[2019-10-19 10:39:20,892] Artifact canvas:war exploded: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE: "C:\Users\28627\.IntelliJIdea2019.2\system\tomcat\Unnamed_canvas"
Using CATALINA_HOME: "E:\apacheTomcat\apache-tomcat-8.5.39"
Using CATALINA_TMPDIR: "E:\apacheTomcat\apache-tomcat-8.5.39\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk1.8.0_144"
Using CLASSPATH: "E:\apacheTomcat\apache-tomcat-8.5.39\bin\bootstrap.jar;E:\apacheTomcat\apache-tomcat-8.5.39\bin\tomcat-juli.jar"
19-Oct-2019 22:39:22.370 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.39
19-Oct-2019 22:39:22.376 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Mar 14 2019 11:24:26 UTC
19-Oct-2019 22:39:22.376 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.39.0
19-Oct-2019 22:39:22.376 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 10
19-Oct-2019 22:39:22.376 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.0
19-Oct-2019 22:39:22.376 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
19-Oct-2019 22:39:22.377 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jdk1.8.0_144\jre
19-Oct-2019 22:39:22.377 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_144-b01
19-Oct-2019 22:39:22.377 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
19-Oct-2019 22:39:22.377 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\28627\.IntelliJIdea2019.2\system\tomcat\Unnamed_canvas
19-Oct-2019 22:39:22.377 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: E:\apacheTomcat\apache-tomcat-8.5.39
19-Oct-2019 22:39:22.377 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\28627\.IntelliJIdea2019.2\system\tomcat\Unnamed_canvas\conf\logging.properties
19-Oct-2019 22:39:22.377 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
19-Oct-2019 22:39:22.377 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
19-Oct-2019 22:39:22.378 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
19-Oct-2019 22:39:22.378 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
19-Oct-2019 22:39:22.378 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.password.file=C:\Users\28627\.IntelliJIdea2019.2\system\tomcat\Unnamed_canvas\jmxremote.password
19-Oct-2019 22:39:22.378 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.access.file=C:\Users\28627\.IntelliJIdea2019.2\system\tomcat\Unnamed_canvas\jmxremote.access
19-Oct-2019 22:39:22.379 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
19-Oct-2019 22:39:22.379 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
19-Oct-2019 22:39:22.379 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
19-Oct-2019 22:39:22.379 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
19-Oct-2019 22:39:22.379 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\28627\.IntelliJIdea2019.2\system\tomcat\Unnamed_canvas
19-Oct-2019 22:39:22.380 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=E:\apacheTomcat\apache-tomcat-8.5.39
19-Oct-2019 22:39:22.380 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=E:\apacheTomcat\apache-tomcat-8.5.39\temp
19-Oct-2019 22:39:22.380 淇℃伅 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.21] using APR version [1.6.5].
19-Oct-2019 22:39:22.380 淇℃伅 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
19-Oct-2019 22:39:22.380 淇℃伅 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
19-Oct-2019 22:39:22.384 淇℃伅 [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1a 20 Nov 2018]
19-Oct-2019 22:39:22.509 淇℃伅 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
19-Oct-2019 22:39:22.529 淇℃伅 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
19-Oct-2019 22:39:22.538 淇℃伅 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
19-Oct-2019 22:39:22.540 淇℃伅 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
19-Oct-2019 22:39:22.541 淇℃伅 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 450 ms
19-Oct-2019 22:39:22.563 淇℃伅 [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
19-Oct-2019 22:39:22.563 淇℃伅 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.39
19-Oct-2019 22:39:22.574 淇℃伅 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
19-Oct-2019 22:39:22.584 淇℃伅 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
19-Oct-2019 22:39:22.586 淇℃伅 [main] org.apache.catalina.startup.Catalina.start Server startup in 45 ms
Connected to server
[2019-10-19 10:39:22,966] Artifact canvas:war exploded: Artifact is being deployed, please wait...
19-Oct-2019 22:39:23.916 淇℃伅 [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
[2019-10-19 10:39:23,986] Artifact canvas:war exploded: Artifact is deployed successfully
[2019-10-19 10:39:23,986] Artifact canvas:war exploded: Deploy took 1,020 milliseconds
19-Oct-2019 22:39:32.581 淇℃伅 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [E:\apacheTomcat\apache-tomcat-8.5.39\webapps\manager]
19-Oct-2019 22:39:32.766 淇℃伅 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [E:\apacheTomcat\apache-tomcat-8.5.39\webapps\manager] has finished in [184] ms
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.vincent.canvas.global.GlobalController.service(GlobalController.java:54)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.vincent.canvas.global.LoginFilter.doFilter(LoginFilter.java:19)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.vincent.canvas.global.EncodingFilter.doFilter(EncodingFilter.java:21)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [collection, list]
### The error may involve com.vincent.canvas.dao.CategoryDao.update-Inline
### The error occurred while setting parameters
### SQL: update category set name=?,description=? where id=?
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [collection, list]
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy19.update(Unknown Source)
at com.vincent.canvas.biz.impl.CategoryBizImpl.edit(CategoryBizImpl.java:17)
at com.vincent.canvas.controller.CategoryController.edit(CategoryController.java:81)
... 33 more
Caused by: org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [collection, list]
at org.apache.ibatis.session.defaults.DefaultSqlSession$StrictMap.get(DefaultSqlSession.java:343)
at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:45)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)
at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:79)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:93)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:64)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)
at com.sun.proxy.$Proxy17.update(Unknown Source)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
... 38 more
package com.vincent.canvas.controller;
import com.vincent.canvas.biz.CategoryBiz;
import com.vincent.canvas.biz.impl.CategoryBizImpl;
import com.vincent.canvas.entity.Category;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
public class CategoryController {
private CategoryBiz categoryBiz=new CategoryBizImpl();
// /admin/Category/list.do
public void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Category> root= categoryBiz.getRoot();
request.setAttribute("root",root);
request.getRequestDispatcher("/WEB-INF/pages/admin/category_list.jsp").forward(request,response);
}
// /admin/Category/toAdd.do
public void toAdd(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
List<Category> root= categoryBiz.getRoot();
request.setAttribute("root",root);
request.getRequestDispatcher("/WEB-INF/pages/admin/category_add.jsp").forward(request,response);
}
// /admin/Category/add.do
public void add(HttpServletRequest request,HttpServletResponse response) throws IOException {
String[] name=request.getParameterValues("name");
String[] description=request.getParameterValues("description");
Category category=new Category();
List<Category> list=new ArrayList<Category>();
for(int i=0;i<name.length;i++){
category.setName(name[i]);
category.setDescription(description[i]);
list.add(category);
}
categoryBiz.add(list);
response.sendRedirect("list.do");
}
// /admin/Category/toEdit.do
public void toEdit(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
int id=Integer.parseInt(request.getParameter("id"));
Category category=categoryBiz.get(id);
request.setAttribute("category",category);
List<Category> root= categoryBiz.getRoot();
request.setAttribute("root",root);
request.getRequestDispatcher("/WEB-INF/pages/admin/category_update.jsp").forward(request,response);
}
// /admin/Category/edit.do
public void edit(HttpServletRequest request, HttpServletResponse response) throws IOException, FileUploadException {
// String[] name=request.getParameterValues("name");
// String[] description=request.getParameterValues("description");
// List<Category> list=new ArrayList<Category>();
// for(int i=0;i<name.length;i++){
// Category category=new Category();
// category.setName(name[i]);
// category.setDescription(description[i]);
// list.add(category);
// }
String name=request.getParameter("name");
String description=request.getParameter("description");
List<Category> list=new ArrayList<Category>();
Category category = new Category();
category.setName(name);
category.setDescription(description);
list.add(category);
categoryBiz.edit(list);
response.sendRedirect("list.do");
}
// /admin/Category/remove.do
public void remove(HttpServletRequest request,HttpServletResponse response) throws IOException {
int id=Integer.parseInt(request.getParameter("id"));
categoryBiz.remove(id);
response.sendRedirect("list.do");
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta charset="UTF-8">
<title>更新</title>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/add.css">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">
油画管理系统
</a>
</div>
</div>
</nav>
<div class="container">
<div class="jumbotron">
<h1>Hello, admin!</h1>
<p>请小心的更新油画分类。。。</p>
</div>
<div class="page-header">
<h3><small>编辑</small></h3>
</div>
<form class="form-horizontal" action="/admin/Category/edit.do" method="post">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">名称 :</label>
<div class="col-sm-8">
<input type="hidden" name="id" class="form-control" id="id" value="${category.id}">
<input name="name" class="form-control" id="name" value="${category.name}">
</div>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">描述 :</label>
<div class="col-sm-8">
<input type="text" name="description" class="form-control" id="description" value="${category.description}">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">保存</button>
</div>
</div>
</form>
</div>
<footer class="text-center" >
copy@vincent
</footer>
</body>
</html>
package com.vincent.canvas.dao;
import com.vincent.canvas.entity.Category;
import org.apache.ibatis.annotations.*;
import java.util.List;
public interface CategoryDao {
@Insert("<script>"+
"insert into category(name,description) values"+
"<foreach collection='list' item='category' separator=','>"+
"(#{category.name},#{category.description})"+
"</foreach>"+
"</script>")
@Options(useGeneratedKeys = true,keyProperty = "id")
void batchInsert(List<Category> list);
@Update("update category set name=#{name},description=#{description} where id=#{id}")
void update(List<Category> list);
@Delete("delete from category where id=#{id}")
void delete(int id);
@Select("select * from category where id=#{id}")
@Results(id="all",value = {
@Result(column = "id",property = "id",id = true),
@Result(column = "name",property = "name"),
@Result(column = "createName",property = "createName"),
@Result(column = "createTime",property = "createTime"),
@Result(column = "updateTime",property = "updateTime"),
@Result(column = "description",property = "description")
})
Category select(int id);
@Select("select * from category")
@ResultMap("all")
List<Category> selectAll();
}
2.油画列表中编辑的问题
编辑保存之后页面跳转到油画列表list.do界面,但是被修改的数据却没有变化,也没有任何报错信息
package com.vincent.canvas.dao;
import com.vincent.canvas.entity.Canvas;
import org.apache.ibatis.annotations.*;
import java.util.List;
public interface CanvasDao {
//添加商品
@Insert("insert into canvas (name,creator,categoryId,price,smallImg,createTime,description) values (#{name},#{creator},#{categoryId},#{price},#{smallImg},#{createTime},#{description})")
@Options(useGeneratedKeys = true,keyProperty = "id")
void insert(Canvas canvas);
//编辑商品,createTime=#{createTime}
@Update("update canvas set name=#{name},categoryId=#{categoryId},price=#{price},smallImg=#{smallImg},description=#{description} where id=#{id}")
void update(Canvas canvas);
//删除商品
@Delete("delete from canvas where id=#{id}")
void delete(int id);
//查询单个商品
@Select("select c.*,ca.name cname from canvas c inner join category ca on c.categoryId=ca.id where c.id=#{id}")
@Results(id = "all",value = {
@Result(column = "id",property = "id",id = true),
@Result(column = "categoryId",property = "categoryId"),
@Result(column = "name",property = "name"),
@Result(column = "creator",property = "creator"),
@Result(column = "price",property = "price"),
@Result(column = "smallImg",property = "smallImg"),
@Result(column = "createTime",property = "createTime"),
@Result(column = "updateTime",property = "updateTime"),
@Result(column = "description",property = "description"),
@Result(column = "details",property = "details"),
@Result(column = "cname",property = "category.name")
})
Canvas select(int id);
//查询全部商品
@Select("select c.*,ca.name cname from canvas c inner join category ca on c.categoryId=ca.id order by c.id desc")
@ResultMap("all")
List<Canvas> selectAll();
//前台页面展示
@Select("select c.*,ca.name cname from canvas c inner join category ca on c.categoryId=ca.id")
@ResultMap("all")
List<Canvas> selectShow();
}
package com.vincent.canvas.controller;
import com.vincent.canvas.biz.CanvasBiz;
import com.vincent.canvas.biz.CategoryBiz;
import com.vincent.canvas.biz.impl.CanvasBizImpl;
import com.vincent.canvas.biz.impl.CategoryBizImpl;
import com.vincent.canvas.entity.Canvas;
import com.vincent.canvas.entity.Category;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
public class CanvasController {
private CanvasBiz canvasBiz = new CanvasBizImpl();
private CategoryBiz categoryBiz=new CategoryBizImpl();
// /admin/canvas/list.do
public void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Canvas> list=canvasBiz.getAll();
request.setAttribute("list",list);
request.getRequestDispatcher("/WEB-INF/pages/admin/canvas_list.jsp").forward(request,response);
}
// /admin/canvas/toAdd.do 打开添加界面
public void toAdd(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
List<Category> list = categoryBiz.getRoot();
request.setAttribute("list",list);
request.getRequestDispatcher("/WEB-INF/pages/admin/canvas_add.jsp").forward(request,response);
}
// /admin/canvas/add.do 添加完成提交
public void add(HttpServletRequest request,HttpServletResponse response) throws IOException, FileUploadException {
Canvas canvas=builder(request);
canvasBiz.add(canvas);
response.sendRedirect("list.do");
}
// /admin/canvas/toUpdate.do
public void toUpdate(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
int id=Integer.parseInt(request.getParameter("id"));
Canvas canvas=canvasBiz.get(id);
request.setAttribute("canvas",canvas);
List<Category> list= categoryBiz.getRoot();
request.setAttribute("list",list);
request.getRequestDispatcher("/WEB-INF/pages/admin/canvas_update.jsp").forward(request,response);
}
// /admin/canvas/update.do
public void update(HttpServletRequest request,HttpServletResponse response) throws IOException, FileUploadException {
Canvas canvas=builder(request);
canvasBiz.edit(canvas);
response.sendRedirect("list.do");
}
// /admin/Canvas/remove.do
public void remove(HttpServletRequest request,HttpServletResponse response) throws IOException {
int id=Integer.parseInt(request.getParameter("id"));
canvasBiz.remove(id);
response.sendRedirect("list.do");
}
private Canvas builder(HttpServletRequest request) throws FileUploadException, UnsupportedEncodingException {
Canvas canvas = new Canvas();
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding("UTF-8");
List<FileItem> list = upload.parseRequest(request);
for(FileItem item:list){
//判断是表单项还是文件上传项
if(item.isFormField()){
//表单项
if(item.getFieldName().equals("id")){
canvas.setId(Integer.parseInt(item.getString("UTF-8")));
}
if(item.getFieldName().equals("categoryId")){
canvas.setCategoryId(Integer.parseInt(item.getString("UTF-8")));
}
if(item.getFieldName().equals("name")){
canvas.setName(item.getString("UTF-8"));
}
if (item.getFieldName().equals("price")){
canvas.setPrice(Integer.parseInt(item.getString("UTF-8")));
}
if(item.getFieldName().equals("description")){
canvas.setDescription(item.getString("UTF-8"));
}
if(item.getFieldName().equals("smallImg")&&canvas.getSmallImg()==null){
canvas.setSmallImg(item.getString("UTF-8"));
}else{
//文件上传项
if(item.getFieldName().equals("smallImg")){
if(item.getSize()<=100) continue;
String rootPath=request.getServletContext().getRealPath("/");
String path=item.getName();
String type=".jpg";
if(path.indexOf(".")!=-1){
type=path.substring(path.lastIndexOf("."));
}
path="/download/images/"+System.currentTimeMillis()+type;
try {
item.write(new File(rootPath+path));
canvas.setSmallImg(path);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
return canvas;
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<html>
<head>
<meta charset="UTF-8">
<title>编辑</title>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/add.css">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">
油画管理系统
</a>
</div>
</div>
</nav>
<div class="container">
<div class="jumbotron">
<h1>Hello, admin!</h1>
<p>请小心的编辑油画记录</p>
</div>
<div class="page-header">
<h3><small>编辑</small></h3>
</div>
<form class="form-horizontal" action="/admin/Canvas/update.do" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="${canvas.id}">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">名称 :</label>
<div class="col-sm-8">
<input name="name" class="form-control" id="name" value="${canvas.name}">
<input type="hidden" name="id" class="form-control" id="id" value="001">
</div>
</div>
<div class="form-group">
<label for="categoryId" class="col-sm-2 control-label">分类 :</label>
<select id="categoryId" name="categoryId" class="col-sm-2 form-control" style="width: auto">
<c:forEach items="${list}" var="cat">
<option id="${cat.id}" value="${cat.id}">${cat.name}</option>
</c:forEach>
</select>
</div>
<div class="form-group">
<label for="price" class="col-sm-2 control-label">价格 :</label>
<div class="col-sm-8">
<input name="price" type="number" class="form-control" id="price" value="${canvas.price}">
</div>
</div>
<div class="form-group">
<label for="smallImg" class="col-sm-2 control-label">图片 :</label>
<div class="col-sm-8">
<input id="smallImg" name="smallImg" class="file-loading"
type="file" multiple accept=".jpg,.jpeg,.png" data-min-file-count="1"
data-show-preview="true" value="${canvas.smallImg}">
</div>
</div>
<div class="form-group">
<label for="description" class="col-sm-2 control-label">描述 :</label>
<div class="col-sm-8">
<input name="description" type="text" class="form-control" id="description" value="${canvas.description}">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">保存</button>
</div>
</div>
</form>
</div>
<footer class="text-center" >
copy@vincent
</footer>
</body>
</html>
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 277 份
- 解答问题 4297 个
Java数据库开发的必备技能,从流行的MySQL数据库开始,到Java原生的数据库管理接口JDBC的使用,再到常用的数据持久化框架MyBatis,让你向Java工程师的目标又迈进了一步!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星