Java's new project learning online notes - day3(7)

3 modification page
To modify the page user operation process:
1. The user enters the modification page and displays the information of the modification page on the page
2. When the user modifies the content of the page, click "submit" to prompt "modification succeeded" or "modification failed". 3.1 modify the interface definition of the page
The API to be defined for modifying the page is as follows:

@ApiOperation("adopt ID Query page") public CmsPage findById(String id);   @ApiOperation("Modify page") public CmsPageResult edit(String id,CmsPage cmsPage);

Note: post and put can be used to submit data. Only according to the specification of http method, put method modifies the resources specified by the server, so put method is used here to modify the page. 3.2 modify page server development
Use the "ndById" method provided by Spring Data to complete the query based on the primary key.
Use the save method provided by Spring Data to save the data. 3.2.2Service

//Query page by id   
 public CmsPage getById(String id){   
    Optional<CmsPage> optional = cmsPageRepository.findById(id);      
      return optional.get();     
  //Return empty   
     return null;   
 }  //Update page information  
  public CmsPageResult update(String id,CmsPage cmsPage) {  
     //Query page information according to id     
    CmsPage one = this.getById(id);  
      if (one != null) {
           //Update template id
         //Update site      
    //Update page alias    
       //Update page name          
        //Update access path        
         //Update physical path
     //Execution update        
    CmsPage save =;         
   if (save != null) {     
          //Return to success       
         CmsPageResult cmsPageResult = new CmsPageResult(CommonCode.SUCCESS, save);    
            return cmsPageResult;   
   //Return failed   
     return new CmsPageResult(CommonCode.FAIL,null);  

1. Query the page according to id

 public CmsPage findById(@PathVariable("id") String id) {   
    return pageService.getById(id);    

2. Save page information

  @PutMapping("/edit/{id}")//The put method is used here. In the http method, put means to update the public CmsPageResult edit(@PathVariable("id") String id, @RequestBody CmsPage cmsPage){    
   return pageService.update(id,cmsPage);   

3.3 modify page front end development
3.3.1 page processing flow
The processing flow of the page is as follows:

1. Enter the page, request the server to obtain the page information through the hook method, and assign it to the data model object
2. The page information is displayed in the form through data binding
3. Click "submit" to request the server to modify the page information interface

Tags: Java Spring

Posted on Mon, 02 Dec 2019 18:42:03 -0800 by gregsmith