public void attachments(String belongid) { DALBase.delete("attachement", MessageFormat.format( " where belongid=''{0}'' and belongtable=''album'' ", belongid)); String[] photos = request.getParameterValues("fileuploaded"); if (photos == null) return; for (int i = 0; i < photos.length; i++) { Attachement a = new Attachement(); a.setType("images"); a.setPubtime(new Date()); a.setBelongfileldname("id"); a.setFilename(photos[i]); a.setBelongid(belongid); a.setBelongtable("album"); a.setUrl(SystemParam.getSiteRoot() + "/upload/temp/" + a.getFilename()); a.setTitle(a.getFilename()); DALBase.save(a); } }解释这段代码
时间: 2024-04-01 12:37:08 浏览: 96
这段代码是Java语言编写的,它的作用是上传图片附件到指定的相册。具体来说,该函数首先从数据库中删除相册中的所有附件,然后获取HTTP请求中上传的图片文件名,接着将每个文件名生成一个附件对象,设置其相关属性(如类型、上传时间、所属ID、所属表格等),最后将附件保存到数据库中。该函数使用了一个名为 DALBase 的对象,该对象是对数据库的访问进行了封装的工具类。
相关问题
public void update() { String forwardurl = request.getParameter("forwardurl"); String id = request.getParameter("id"); if (id == null) return; Album album = (Album) DALBase.load(Album.class, new Integer(id)); if (album == null) return; String name = request.getParameter("name"); String des = request.getParameter("des"); String xtype = request.getParameter("xtype"); String privilege = request.getParameter("privilege"); String pubren = request.getParameter("pubren"); String pubtime = request.getParameter("pubtime"); String tupian = request.getParameter("tupian"); SimpleDateFormat sdfalbum = new SimpleDateFormat("yyyy-MM-dd"); album.setName(name); album.setDes(des); album.setXtype(xtype); album.setPrivilege(privilege); album.setPubren(pubren); if (pubtime != null) { try { album.setPubtime(sdfalbum.parse(pubtime)); } catch (ParseException e) { e.printStackTrace(); } } album.setTupian(tupian); DALBase.update(album); // attachments(new Integer(album.getId()).toString()); if (forwardurl == null) { forwardurl = "/admin/albummanager.do?actiontype=get"; } try { response.sendRedirect(SystemParam.getSiteRoot() + forwardurl); } catch (Exception e) { e.printStackTrace(); } }翻译这段代码
这段代码是Java语言编写的,其作用是更新相册信息。该函数首先获取HTTP请求中的相关参数(如相册ID、名称、描述、类型、权限等),然后根据相册ID从数据库中加载相册对象。接着,将获取的参数设置到相册对象的属性中。如果有发布时间参数,将其转换为日期格式并设置到相册对象的属性中。最后,将更新后的相册对象保存到数据库中,并将用户重定向到指定的页面(如相册管理页面)。如果重定向地址未指定,则默认跳转到相册管理页面。
public class SupplyorAction extends PageActionBase{ @Override public void onLoad() { String actiontype = request.getParameter("actiontype"); System.out.println("actiontype=" + actiontype); if (actiontype == null) return ; } /******************************************************** 信息注销监听支持*********** *********************************************************/ public void delete() { String id=request.getParameter("id"); DALBase.delete("supplyor", " where id="+id); binding(); }public void save() { String forwardurl=request.getParameter("forwardurl"); //验证错误url String errorurl=request.getParameter("errorurl"); String sname=request.getParameter("sname"); String tel=request.getParameter("tel"); String lxren=request.getParameter("lxren"); String email=request.getParameter("email"); String address=request.getParameter("address"); String fax=request.getParameter("fax"); String des=request.getParameter("des"); SimpleDateFormat sdfsupplyor=new SimpleDateFormat("yyyy-MM-dd"); Supplyor supplyor=new Supplyor(); supplyor.setSname(sname==null?"":sname); supplyor.setTel(tel==null?"":tel); supplyor.setLxren(lxren==null?"":lxren); supplyor.setEmail(email==null?"":email); supplyor.setAddress(address==null?"":address); supplyor.setFax(fax==null?"":fax); supplyor.setDes(des==null?"":des); //产生验证 Boolean validateresult=saveValidate( "where sname='"+sname+"'"); if(validateresult){ try { request.setAttribute("errormsg","<label class='error'>已存在的供应商</label>"); request.setAttribute("supplyor", supplyor); request.setAttribute("actiontype", "save"); request.getRequestDispatcher(errorurl).forward(request, response); } catch (Exception e) { e.printStackTrace(); } return; } DALBase.save(supplyor); //保存附件 // attachments(request,response,new Integer(supplyor.getId()).toString()); if(forwardurl==null){ forwardurl="/admin/supplyormanager.do?actiontype=get"; } try { response.sendRedirect(SystemParam.getSiteRoot()+forwardurl); } catch (Exception e) { e.printStackTrace(); } } //新增验证 private boolean saveValidate(String filter){ return DALBase.isExist("supplyor解释每一行代码
这段代码是一个 Java 类,名为 SupplyorAction,它继承了 PageActionBase 类。在 onLoad() 方法中,它获取了一个名为 actiontype 的请求参数,并将其打印出来。如果 actiontype 为 null,则直接返回。在类中还定义了 delete() 和 save() 两个方法,分别用于删除和保存供应商信息。其中,save() 方法中进行了一些输入验证,并将供应商信息保存到数据库中。在 saveValidate() 方法中,它通过调用 DALBase.isExist() 方法来判断是否已经存在同名的供应商。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)