Write a framework with ioc-aop-mvc function from scratch – learning notes – 12 hellofframework introduction + future plan outlook

Time:2021-1-24

1. Use of frame function

Write a framework with ioc-aop-mvc function from scratch - learning notes - 12 hellofframework introduction + future plan outlook

1.1 write controller class

1.1.1 the controller code to be completed is as follows:
package test.demo.controller;

import com.wuyiccc.helloframework.core.annotation.Controller;
import com.wuyiccc.helloframework.injection.annotation.Autowired;
import com.wuyiccc.helloframework.mvc.annotation.RequestMapping;
import com.wuyiccc.helloframework.mvc.annotation.RequestParam;
import com.wuyiccc.helloframework.mvc.annotation.ResponseBody;
import com.wuyiccc.helloframework.mvc.type.ModelAndView;
import com.wuyiccc.helloframework.mvc.type.RequestMethod;
import test.demo.pojo.Book;
import test.demo.service.BookService;

import java.util.List;

/**
 * @author wuyiccc
 * @date 2020/7/15 22:16
 *Do you say that you have no clothes, and you are in the same robe with your son~
 */
@Controller
@RequestMapping(value = "/book")
public class BookController {


    @Autowired
    private BookService bookService;

    @RequestMapping(value = "/all", method = RequestMethod.GET)
    @ResponseBody
    public List<Book> getAllBooksInfo() {
       return bookService.getAllBooksInfo();
    }


    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ModelAndView addBook(
            @RequestParam(value = "bookName") String bookName,
            @RequestParam(value = "author") String author
    ){

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setView("addSuccess.jsp").addViewData("bookName", bookName).addViewData("author", author);

        return modelAndView;
    }


}

Write a framework with ioc-aop-mvc function from scratch - learning notes - 12 hellofframework introduction + future plan outlook

1.2 writing service class

1.2.1 code for service:
package test.demo.service;

import com.wuyiccc.helloframework.core.annotation.Service;
import test.demo.pojo.Book;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wuyiccc
 * @date 2020/7/15 22:18
 *Do you say that you have no clothes, and you are in the same robe with your son~
 */

@Service
public class BookService {


    public List<Book> getAllBooksInfo() {

        List<Book> booksInfo = new ArrayList<>();
        booksInfo.add(new Book("book1", "wuyiccc1"));
        booksInfo.add(new Book("book2", "wuyiccc2"));

        return booksInfo;
    }

}

Write a framework with ioc-aop-mvc function from scratch - learning notes - 12 hellofframework introduction + future plan outlook

1.3 write POJO class

Write a framework with ioc-aop-mvc function from scratch - learning notes - 12 hellofframework introduction + future plan outlook

1.4 specify the property configuration of the framework in the configuration file

  1. We indicate in the framework that the configuration file to be scanned is config / hellofframework- config.properties Therefore, the relevant configuration of our framework needs to be written in this configuration file. When the framework starts, it will automatically read the relevant attribute values from this configuration file

Write a framework with ioc-aop-mvc function from scratch - learning notes - 12 hellofframework introduction + future plan outlook

1.5 static resources

  1. Static resources must be placed in the static / directory. We have instructions in the framework source code

Write a framework with ioc-aop-mvc function from scratch - learning notes - 12 hellofframework introduction + future plan outlook

1.6 write JSP page

  1. Similarly, the JSP page must also be in the templates / directory, which we have explained in the framework source code

Write a framework with ioc-aop-mvc function from scratch - learning notes - 12 hellofframework introduction + future plan outlook

Write a framework with ioc-aop-mvc function from scratch - learning notes - 12 hellofframework introduction + future plan outlook

1.7 framework function test

1.7.1 configure Tomcat first and then run it

Write a framework with ioc-aop-mvc function from scratch - learning notes - 12 hellofframework introduction + future plan outlook

1.7.2 accessing static resources

Write a framework with ioc-aop-mvc function from scratch - learning notes - 12 hellofframework introduction + future plan outlook

1.7.3 visit JSP page

Write a framework with ioc-aop-mvc function from scratch - learning notes - 12 hellofframework introduction + future plan outlook

1.7.4 test controller returns JSON data

Write a framework with ioc-aop-mvc function from scratch - learning notes - 12 hellofframework introduction + future plan outlook

1.7.5 test data forwarding of controller

Write a framework with ioc-aop-mvc function from scratch - learning notes - 12 hellofframework introduction + future plan outlook

2. Future plan

  1. thisWrite a framework with ioc-aop-mvc function from scratchThe column is my study notes, of course, the code is not my original, but in the process of sorting out the notes, because I write the explanation according to the code again, so in the process of explanation, I inevitably mixed my personal understanding, and made some improvements on the basis of the original code.
  2. In the near future, according to my understanding of spring source code, I will optimize the hellofframework again. This optimization may be to enhance the existing ioc-aop-mvc function, or to add some functions similar to spring
  3. Finally, I plan to write a simple usage document for Hello framework after this note is completed. The content of the document may be put on GitHub. It depends on the situation.
  4. come on.

GitHub address: https://github.com/wuyiccc/he…