Add a Product Type Maintenance module under Basic Management (7-31)

Source: Internet
Author: User
Tags dateformat

A validation cannot be NULL operation:

    1. Add code @notempty in form (field= "Product Type", message= "{errors.required}")

    2. Add a location in the controller that cannot be empty

if (Results.haserrors ())

return "Manager/commoditytype/addcommoditytype";

3. Cannot be empty format: <td style= "Background-color: #f9f9f9;" > Product Name </td>

<td><form:input path= "Commoditytypename" cssclass= "Form-control" csserrorclass= "Form-control Error" Value= "${commoditytypeform.commoditytypename}"/></td>

Two Add commodity type module

  1. Click on the Item Type Management button to enter a list interface to display the list of commodity types that already exist in the database, the function of this module is edit, delete, append and cancel.

  2. Click the Edit button to enter the product type of the edit, the input content is empty or add the product type and the existing type of the same prompt error message.

  3. When you click the Append button to add to the Append page, the input content is empty or the product type is added with the existing type to prompt the error message.

  4. Backstage Build addcommoditytype.jsp

    commoditytypelist.jsp

    Editcommoditytype.jsp these three pages, add ID, product name and remark:commodity_type_id,commodity_type_name,commodity_ Type_note

  5. Important code in Commoditytypeform:

    for the need to Vail u dation Properties Add the appropriate label for example, the name here needs to be set to not be empty or to be duplicated with data already in the database:

    public class Commoditytypeform {

    Private String Commoditytypeid;

    Validation cannot be null

    @NotEmpty (field= "Product Type", message= "{errors.required}")

    Private String Commoditytypename;

    Private String Commoditytypenote;

    Private String UpdateTime;

    Private String UpdateUser;

    }

3. Important code in COMMODITYTYPESQLMAP: Some of the operations in the database, such as querying, inserting, updating the data statement

<sqlmap namespace= "Commodity_type" ><select id= "Selectcommoditytypelist" parameterClass= " Cn.agriculture.web.form.CommodityTypeForm "resultclass=" Cn.agriculture.web.form.CommodityTypeForm ">select  commodity_type.commodity_type_id as commoditytypeid,commodity_type.commodity_type_name as  commoditytypename,commodity_type.commodity_type_note as commoditytypenotefrom commodity_ Type</select><select id= "Selectcommoditytype" parameterclass= " Cn.agriculture.web.form.CommodityTypeForm "resultclass=" Cn.agriculture.web.form.CommodityTypeForm ">select  commodity_type_id as commoditytypeid,commodity_type_name as commoditytypename, commodity_type_note as commoditytypenotefrom commodity_typewhere commodity_type_id =   #commodityTypeId #</select><select id= "Getseq"  resultclass= "Java.lang.Integer" > Select _nextval (' Commoditytypeid ') </select><insert&nbSp;id= "Addcommoditytype"  parameterclass= "Cn.agriculture.web.form.CommodityTypeForm" >insert into  commodity_type (commodity_type_id, commodity_type_name,commodity_type_note) VALUES (#commodityTypeId #,   #commodityTypeName #, #commodityTypeNote #) </insert><update id= "Editcommoditytype"   parameterclass= "Cn.agriculture.web.form.CommodityTypeForm" >UPDATE commodity_type SET  commodity_type_name =  #commodityTypeName #,commodity_type_note =  #commodityTypeNote #where  commodity_type_id =  #commodityTypeId #</update><delete id= "Delcommoditytype"  parameterclass= "Cn.agriculture.web.form.CommodityTypeForm" >delete from commodity_typewhere  commodity_type_id =  #commodityTypeId #</delete></sqlmap>

4. important code in Commoditytypeservice: Some methods of calling data in a database

@Servicepublic  class commoditytypeservice {@AutowiredQueryDAO  queryDao; @AutowiredUpdateDAO  updatedao;public list<commoditytypeform> searchcommoditytypelist ()  {List< Commoditytypeform> result = querydao.executeforobjectlist ("Commodity_ Type.selectcommoditytypelist ",  null); return result;} Public commoditytypeform searchcommoditytype (COMMODITYTYPEFORM&NBSP;FRM)  {CommodityTypeForm  result = querydao.executeforobject ("Commodity_type.selectcommoditytype", frm,  Commoditytypeform.class); return result;} Public boolean addcommoditytype (COMMODITYTYPEFORM&NBSP;FRM)  {Integer sequee =  Querydao.executeforobject ("Commodity_type.getseq",  null, integer.class); String commoditytypeid = frm.getupdatetime (). substring (0, 4)  + string.format ("%0 11d ",  sequee); Frm.setcommoditytypeid (Commoditytypeid); int result =&nBsp;updatedao.execute ("Commodity_type.addcommoditytype",  frm);if  (result == 1)  { Return true;} Return false;} Public commoditytypeform geteditcommoditytype (COMMODITYTYPEFORM&NBSP;FRM)  {return  Querydao.executeforobject ("Commodity_type.selecteditcommoditytype",  frm,commoditytypeform.class);} Public boolean editcommoditytype (COMMODITYTYPEFORM&NBSP;FRM)  {int result =  Updatedao.execute ("Commodity_type.editcommoditytype",  frm);if  (result == 1)  {return  true;} Return false;} Public boolean delcommoditytype (COMMODITYTYPEFORM&NBSP;FRM)  {int result =  Updatedao.execute ("Commodity_type.delcommoditytype",  frm);if  (result == 1)  {return  true;} Return false;}}

5. Important code in Commoditytypecontrollor: the main implementation of jump on each page and some features

@Slf4j @controller ("Commoditytypecontroller") @RequestMapping ("/") Public class commoditytypecontroller  {@AutowiredCommodityTypeService  commodityTypeService; @AutowiredItemListComponent   Itemlistcomponent, @Autowiredprivate  Environment env; @RequestMapping (value =  " Initcommoditytype ",  method = requestmethod.get) Public string initcommoditytype (Model  model)  {log.info ("Product type initialization"); Model.addattribute ("List", Commoditytypeservice.searchcommoditytypelist ( ));return  "Manager/commoditytype/commoditytypelist";} @RequestMapping (value =  "Initaddcommoditytype",  method = requestmethod.get) public  string initaddcommoditytype (Model model)  {log.info ("Additional Product type initialization"); Commoditytypeform commoditytypeform = new commoditytypeform (); Model.addAttribute (" Commoditytypeform ",  commoditytypeform);return " Manager/commoditytype/addcommoditytype ";} @RequestMapping (value =  "Addcommoditytype",  method = requestmethod.post) public string  Executeaddcommoditytype (model model,httpsession session, @Valid   @ModelAttribute (" Commoditytypeform ")  commoditytypeform commoditytypeform,bindingresult results)  throws  sqlexception, ioexception {//determine if the contents of the text box cannot be empty if (results.haserrors ())          return  "Manager/commoditytype/addcommoditytype"; Log.info ("Add Product type Information"); uvo uvo =  (UVO)  session.getattribute ("UVO"); Commoditytypeform.setupdateuser ( Uvo.getusername ());D ate date = new date (); Simpledateformat dateformat = new simpledateformat ("Yyyy-mm-dd hh:mm:ss"); Commoditytypeform.setupdatetime (Dateformat.format (date));boolean result =  Commoditytypeservice.addcommoditytype (Commoditytypeform);if  (!result)  {throw new  SQLException ("Product type information added failed! ");} Model.addattribute ("List", commOditytypeservice.searchcommoditytypelist ());return  "Manager/commoditytype/commoditytypelist";} @RequestMapping (value =  "Initeditcommoditytype",  method = requestmethod.get) public  string initeditcommoditytype (Model model,commoditytypeform commoditytypeform)  { Log.info ("Modification of product type information initialization"); Commoditytypeform result = commoditytypeservice.searchcommoditytype (CommodityTypeForm); Model.addattribute ("Commoditytypeform",  result);return  "Manager/commoditytype/editcommoditytype";} @RequestMapping (value =  "Editcommoditytype",  method = requestmethod.post) public  String executeeditcommoditytype (model model,httpsession session, @Valid   @ModelAttribute (" Commoditytypeform ")  commoditytypeform commoditytypeform,bindingresult results)  throws  sqlexception, ioexception {//determine if the contents of the text box cannot be empty if (results.haserrors ())          return  "Manager/commoditytype/editcommoditytype"; Log.info ("Modify product type information");                  //uvo statement is to determine the login time, login timeout will be re-login// uvo uvo  =  (UVO) session.getattribute ("UVO"),// commoditytypeform.setupdateuser (Uvo.getusername ());D ate  date = new date (); Simpledateformat dateformat = new simpledateformat ("Yyyy-mm-dd hh:mm:ss"); Commoditytypeform.setupdatetime (Dateformat.format (date));boolean result =  Commoditytypeservice.editcommoditytype (Commoditytypeform);if  (!result)  {throw new  SQLException ("Product type information update failed! ");} Model.addattribute ("List", Commoditytypeservice.searchcommoditytypelist ());return  "manager/commodityType/ Commoditytypelist ";} @RequestMapping (value =  "Delcommoditytype",  method = requestmethod.get) public  String executedelcommoditytype (Model model,commoditytypeform commOditytypeform)  throws sqlexception {log.info ("Delete product type information");boolean result =  Commoditytypeservice.delcommoditytype (Commoditytypeform);if  (!result)  {throw new  SQLException ("Product type information deletion failed!") ");} Model.addattribute ("List", Commoditytypeservice.searchcommoditytypelist ());return  "manager/commodityType/ Commoditytypelist ";}}


Add a Product Type Maintenance module under Basic Management (7-31)

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.