从零写一个具备IOC-AOP-MVC功能的框架-学习笔记-12 helloframework框架初步使用介绍+将来计划展望

1. 框架功能的使用

在这里插入图片描述

1.1 编写controller类

1.1.1 须要完成的controller代码以下:
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
 * 岂曰无衣,与子同袍~
 */
@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;
    }


}

在这里插入图片描述

1.2 编写service类

1.2.1 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
 * 岂曰无衣,与子同袍~
 */

@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;
    }

}

在这里插入图片描述

1.3 编写pojo类

在这里插入图片描述

1.4 在配置文件中指明框架的属性配置

  1. 咱们在框架里面指明要扫描的配置文件是config/helloframework-config.properties,因此咱们框架的相关配置都须要在这个配置文件里面写,框架在启动的时候会自动从这个配置文件里面读取相关的属性值

在这里插入图片描述

1.5 放入静态资源

  1. 静态资源必须放在static/目录下,咱们在框架源码里面有说明

在这里插入图片描述

1.6 编写jsp页面

  1. 一样jsp页面也必须在templates/目录下,咱们也在框架源码中有说明

在这里插入图片描述

在这里插入图片描述

1.7 框架功能测试

1.7.1 先配置tomcat而后运行

在这里插入图片描述

1.7.2 访问静态资源

在这里插入图片描述

1.7.3 访问jsp页面

在这里插入图片描述

1.7.4 测试controller返回json数据

在这里插入图片描述

1.7.5 测试controller的数据转发

在这里插入图片描述

2. 将来计划展望

  1. 这个从零写一个具备IOC-AOP-MVC功能的框架专栏是个人学习笔记,固然代码不是我原创的啦,不过我在整理笔记的过程当中,因为是从新根据代码写的讲解,因此在讲解过程当中难免掺杂了我我的的理解,而且在原有的代码基础上作了一部分改进。
  2. 在不远的将来,我会根据我对Spring源码的理解程度,会在这个helloframework框架上再次进行优化,这个优化多是对目前已有的IOC-AOP-MVC功能再进行加强,也有可能会增长一些与Spring相似的功能
  3. 最后,计划在这个笔记完成以后,我会对helloframework写一份简单的使用文档, 文档内容可能会放在github上,这个具体看状况把。
  4. 加油!

github地址:https://github.com/wuyiccc/he...java

相关文章
相关标签/搜索