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 在配置文件中指明框架的属性配置
- 咱们在框架外面指明要扫描的配置文件是config/helloframework-config.properties,所以咱们框架的相干配置都须要在这个配置文件外面写,框架在启动的时候会主动从这个配置文件外面读取相干的属性值
1.5 放入动态资源
- 动态资源必须放在static/目录下,咱们在框架源码外面有阐明
1.6 编写jsp页面
- 同样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. 将来打算瞻望
- 这个从零写一个具备IOC-AOP-MVC性能的框架专栏是我的学习笔记,当然代码不是我原创的啦,不过我在整顿笔记的过程中,因为是从新依据代码写的解说,所以在解说过程中未免掺杂了我集体的了解,并且在原有的代码根底上做了一部分改良。
- 在不远的将来,我会依据我对Spring源码的了解水平,会在这个helloframework框架上再次进行优化,这个优化可能是对目前已有的IOC-AOP-MVC性能再进行加强,也有可能会减少一些与Spring相似的性能
- 最初,打算在这个笔记实现之后,我会对helloframework写一份简略的应用文档, 文档内容可能会放在github上,这个具体看状况把。
- 加油!
github地址:https://github.com/wuyiccc/he…
发表回复