分类列表中编辑和油画列表中编辑的问题

分类列表中编辑和油画列表中编辑的问题

  1. 分类列表中编辑问题


  1. E:\apacheTomcat\apache-tomcat-8.5.39\bin\catalina.bat run

  2. [2019-10-19 10:39:20,892] Artifact canvas:war exploded: Waiting for server connection to start artifact deployment...

  3. Using CATALINA_BASE:   "C:\Users\28627\.IntelliJIdea2019.2\system\tomcat\Unnamed_canvas"

  4. Using CATALINA_HOME:   "E:\apacheTomcat\apache-tomcat-8.5.39"

  5. Using CATALINA_TMPDIR: "E:\apacheTomcat\apache-tomcat-8.5.39\temp"

  6. Using JRE_HOME:        "C:\Program Files\Java\jdk1.8.0_144"

  7. Using CLASSPATH:       "E:\apacheTomcat\apache-tomcat-8.5.39\bin\bootstrap.jar;E:\apacheTomcat\apache-tomcat-8.5.39\bin\tomcat-juli.jar"

  8. 19-Oct-2019 22:39:22.370 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.39

  9. 19-Oct-2019 22:39:22.376 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Mar 14 2019 11:24:26 UTC

  10. 19-Oct-2019 22:39:22.376 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.39.0

  11. 19-Oct-2019 22:39:22.376 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 10

  12. 19-Oct-2019 22:39:22.376 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            10.0

  13. 19-Oct-2019 22:39:22.376 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64

  14. 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

  15. 19-Oct-2019 22:39:22.377 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_144-b01

  16. 19-Oct-2019 22:39:22.377 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation

  17. 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

  18. 19-Oct-2019 22:39:22.377 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         E:\apacheTomcat\apache-tomcat-8.5.39

  19. 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

  20. 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

  21. 19-Oct-2019 22:39:22.377 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=

  22. 19-Oct-2019 22:39:22.378 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099

  23. 19-Oct-2019 22:39:22.378 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false

  24. 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

  25. 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

  26. 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

  27. 19-Oct-2019 22:39:22.379 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048

  28. 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

  29. 19-Oct-2019 22:39:22.379 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=

  30. 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

  31. 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

  32. 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

  33. 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].

  34. 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].

  35. 19-Oct-2019 22:39:22.380 淇℃伅 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]

  36. 19-Oct-2019 22:39:22.384 淇℃伅 [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1a  20 Nov 2018]

  37. 19-Oct-2019 22:39:22.509 淇℃伅 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]

  38. 19-Oct-2019 22:39:22.529 淇℃伅 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read

  39. 19-Oct-2019 22:39:22.538 淇℃伅 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]

  40. 19-Oct-2019 22:39:22.540 淇℃伅 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read

  41. 19-Oct-2019 22:39:22.541 淇℃伅 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 450 ms

  42. 19-Oct-2019 22:39:22.563 淇℃伅 [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]

  43. 19-Oct-2019 22:39:22.563 淇℃伅 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.39

  44. 19-Oct-2019 22:39:22.574 淇℃伅 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]

  45. 19-Oct-2019 22:39:22.584 淇℃伅 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]

  46. 19-Oct-2019 22:39:22.586 淇℃伅 [main] org.apache.catalina.startup.Catalina.start Server startup in 45 ms

  47. Connected to server

  48. [2019-10-19 10:39:22,966] Artifact canvas:war exploded: Artifact is being deployed, please wait...

  49. 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.

  50. [2019-10-19 10:39:23,986] Artifact canvas:war exploded: Artifact is deployed successfully

  51. [2019-10-19 10:39:23,986] Artifact canvas:war exploded: Deploy took 1,020 milliseconds

  52. 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]

  53. 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

  54. java.lang.reflect.InvocationTargetException

  55. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

  56. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

  57. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

  58. at java.lang.reflect.Method.invoke(Method.java:498)

  59. at com.vincent.canvas.global.GlobalController.service(GlobalController.java:54)

  60. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

  61. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

  62. at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

  63. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

  64. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

  65. at com.vincent.canvas.global.LoginFilter.doFilter(LoginFilter.java:19)

  66. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

  67. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

  68. at com.vincent.canvas.global.EncodingFilter.doFilter(EncodingFilter.java:21)

  69. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

  70. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

  71. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)

  72. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)

  73. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)

  74. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)

  75. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)

  76. at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)

  77. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)

  78. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)

  79. at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)

  80. at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

  81. at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)

  82. at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)

  83. at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

  84. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

  85. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

  86. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

  87. at java.lang.Thread.run(Thread.java:748)

  88. Caused by: org.apache.ibatis.exceptions.PersistenceException: 

  89. ### Error updating database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [collection, list]

  90. ### The error may involve com.vincent.canvas.dao.CategoryDao.update-Inline

  91. ### The error occurred while setting parameters

  92. ### SQL: update category set name=?,description=? where id=?

  93. ### Cause: org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [collection, list]

  94. at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)

  95. at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)

  96. at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)

  97. at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)

  98. at com.sun.proxy.$Proxy19.update(Unknown Source)

  99. at com.vincent.canvas.biz.impl.CategoryBizImpl.edit(CategoryBizImpl.java:17)

  100. at com.vincent.canvas.controller.CategoryController.edit(CategoryController.java:81)

  101. ... 33 more

  102. Caused by: org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [collection, list]

  103. at org.apache.ibatis.session.defaults.DefaultSqlSession$StrictMap.get(DefaultSqlSession.java:343)

  104. at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:45)

  105. at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)

  106. at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:79)

  107. at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:93)

  108. at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:64)

  109. at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)

  110. at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49)

  111. at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)

  112. at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)

  113. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

  114. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

  115. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

  116. at java.lang.reflect.Method.invoke(Method.java:498)

  117. at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)

  118. at com.sun.proxy.$Proxy17.update(Unknown Source)

  119. at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)

  120. ... 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>&nbsp;&nbsp;&nbsp;
           </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>&nbsp;&nbsp;&nbsp;
           </div>
       </div>
   </form>
</div>
<footer class="text-center" >
   copy@vincent
</footer>
</body>
</html>

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
好帮手慕阿满 2019-10-20 15:42:07

同学你好,建议同学在数据库中,使用update category set name=?,description=? where id=?的语法格式修改一下数据,查看是否可以正确修改。

祝:学习愉快~

好帮手慕阿满 2019-10-20 12:01:07

同学你好,报错信息提示参数name没有找到,如:

http://img1.sycdn.imooc.com//climg/5dabd9f609e8d9c808230226.jpg

建议同学查看一下数据库中的字段名是否是name,如果不是,建议修改sql语句中的字段再试试。

关于油画列表中编辑的问题,建议查看一下表名,字段名等是否和数据库的一致。

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

  • 提问者 浮生Y一梦 #1
    字段名称全部都是正确的
    2019-10-20 14:06:44
  • 提问者 浮生Y一梦 #2
    还有别的解决办法吗
    2019-10-20 14:07:12
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
Java数据库开发与实战应用2018版
  • 参与学习           人
  • 提交作业       277    份
  • 解答问题       4297    个

Java数据库开发的必备技能,从流行的MySQL数据库开始,到Java原生的数据库管理接口JDBC的使用,再到常用的数据持久化框架MyBatis,让你向Java工程师的目标又迈进了一步!

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师