- package com.ajun.ts.dao;
- import java.util.ArrayList;
- import java.util.List;
- import com.ajunframework.beans.annotation.Dao;
- @Dao
- public class PersonDao{
- public List<String> findAll(){
- List<String> list = new ArrayList<String>();
- list.add("zhao");
- list.add("jun");
- list.add("liu");
- list.add("zhen");
- return list;
- }
- }
- package com.ajun.ts.service;
- import java.util.List;
- import com.ajun.ts.dao.PersonDao;
- import com.ajunframework.beans.annotation.Property;
- import com.ajunframework.beans.annotation.Service;
- @Service
- public class PersonService {
- @Property
- private PersonDao personDao;
- public List<String> findAll(){
- return personDao.findAll();
- }
- public PersonDao getPersonDao() {
- return personDao;
- }
- public void setPersonDao(PersonDao personDao) {
- this.personDao = personDao;
- }
- }
配置注入的扫描的包constant.properties
- package com.ajun.ts.controller;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.ajun.ts.service.PersonService;
- import com.ajunframework.beans.annotation.Action;
- import com.ajunframework.beans.annotation.Property;
- import com.ajunframework.servlet.annotation.RequestMapping;
- import com.ajunframework.servlet.view.View;
- import com.ajunframework.servlet.view.ViewData;
- @Action
- public class PersonAction {
- @Property
- private PersonService personService;
- @RequestMapping("person/list")//跳转路径
- public View personList(HttpServletRequest request, HttpServletResponse response){
- ViewData view = new ViewData();
- List<String> list = personService.findAll();
- view.put("list", list);//此处就是设置数据在request范围内了
- return new View("/jsp/person/list.jsp");
- }
- public PersonService getPersonService() {
- return personService;
- }
- public void setPersonService(PersonService personService) {
- this.personService = personService;
- }
- }
配置DispatchServlet在web.xml
- scan-package=com.ajun.ts//这个包先必须在classpath下,没有做路径的处理
页面请求
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="2.5"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
- <servlet>
- <servlet-name>DispatchServlet</servlet-name>
- <servlet-class>com.ajunframework.servlet.DispatchServlet</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>DispatchServlet</servlet-name>
- <url-pattern>*.ajun</url-pattern>
- </servlet-mapping>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
展现页面
- <a href="person/list.ajun">LSIT PERSON</a>
- <table border="1" align="center" width="80%">
- <tr>
- <td>Name</td>
- </tr>
- <c:forEach items="${list}" var="p">
- <tr>
- <td>${p}</td>
- </tr>
- </c:forEach>
- </table>