"Springmvc+mybatis project" Jie Xin Trade-9. Manufacturer Delete + view

Source: Internet
Author: User

Last time we realized the manufacturer's modification, this time we realize the deletion of the manufacturer

Delete We are divided into two cases, one is to delete one, one is to delete more than one, we all implement

We first set the delete configuration statement in Factorymapper.xml:
<!--delete a--><delete id= "Deletebyid" parametertype= "string" >delete from Factory_cwhere Factory_id=#{id} </delete><!--Delete multiple (in the form of a one-dimensional string array)--><delete id= "Delete" parametertype= "string" >delete from Factory_ Cwhere factory_id  in <foreach collection= "array" item= "ID" open= "(" close= ")" separator= "," >#{id}</ Foreach></delete>

Then we'll write the DAO layer.
Since our Factorydaoimpl inherited the Basedaoimpl, there are two methods in it:
public void Deletebyid (Serializable id) {this.getsqlsession (). Delete (ns + ". Deletebyid", id);} public void Delete (serializable[] IDs) {this.getsqlsession (). Delete (ns + ". Delete", IDS);}

We don't have to write a delete method in Factorydaoimpl.

Let's see the service layer.
The implementation of the following two methods is included in the Factoryservice
@Overridepublic void Delete (serializable[] IDs) {factorydao.delete (IDS);} @Overridepublic void Deletebyid (Serializable id) {Factorydao.deletebyid (id);}


Next, look at our controller layer.
Write a method for delete in Factorycontroller
Delete a @requestmapping ("/basicinfo/factory/deletebyid.action") Public String Deletebyid (string id) { Factoryservice.deletebyid (ID); return "Redirect:/basicinfo/factory/list.action";} Delete multiple @requestmapping ("/basicinfo/factory/delete.action") public String Delete (@RequestParam ("id") string[] IDs) { Factoryservice.delete (IDs); return "Redirect:/basicinfo/factory/list.action";}

We've got the left. Deleted foreground interface entry
We added delete one and delete multiple buttons in web-inf/pages/baseinfo/factory/jfactorylist.jsp:
<li id= "Delete" ><a href= "#" onclick= "Formsubmit (' deletebyid.action ', ' _self '); This.blur ();" > Delete </a></li><li id= "delete" ><a href= "#" onclick= "Formsubmit (' delete.action ', ' _self '); This.blur (); " > Delete n</a></li>

Next we restart the server for testing
First click "Delete" to delete a message


Delete Success!


Then click "Delete N" and select multiple to delete



Delete Success!



Next, we'll write code that looks at the details of a particular manufacturer.
First of all our factorymapper.xml before we have written a query for a manufacturer's configuration statement:
<!--query for a--><select id= "get" parametertype= "string" resultmap= "Factoryrm" >select * from Factory_cwhere Factory_id=#{id}</select> then our DAO layer inherits the Basedaoimpl, so nature contains the following method public T get (Serializable ID) {return This.getsqlsession (). SelectOne (ns + ". Get", id);

Service layer We've written about this before.
@Overridepublic Factory get (Serializable ID) {return factorydao.get (ID);}

Next we write a method for viewing in the controller layer
View @requestmapping ("/basicinfo/factory/toview.action") public string Toview (String Id,model Model) {Factory obj= Factoryservice.get (ID); Model.addattribute ("obj", obj); return "/baseinfo/factory/jfactoryview.jsp";}

Finally, let's write the Jfactoryview.jsp view interface
<%@ page language= "java" pageencoding= "UTF-8"%><%@ include file= ". /.. /base.jsp "%>
We previously had a "view" button in the list jfactorylist.jsp interface:
<li id= "View" ><a href= "#" onclick= "Formsubmit (' toview.action ', ' _self '); This.blur ();" > View </a></li>

Restarting the server test
Click Query


Query results


Reprint Please specify source: http://blog.csdn.net/acmman/article/details/48318689

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Springmvc+mybatis project" Jie Xin Trade-9. Manufacturer Delete + view

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.