fw4jREST是以REST风格设计的MVC框架,可以使用Java和Groovy写Controller,使用Java注解声明Controller层。
fw4jREST是基于fw4j编写的,去掉了springmvc的框架注解命名方式,增加使用Groovy语言编写Controller的支持,去掉配置文件的编写,框架启动后会扫描项目下所有目录。
fw4jREST包括的注解有:
Fw4jController
GET
POST
PUT
DELETE
代码示例:
java:
@Fw4jController("/admin")publicclassAdminController{@GET("/index")publicStringindex(OutParamout){JSHelperjs=newJSHelper("nav/nav.js");Stringa=js.getMethod("nav").invoke();System.out.println(a);out.put("nav",a);return"request:index";}}groovy:
@Fw4jController("/websitetype")classWebsiteTypeController{WebsiteTypeServicewebsiteTypeService=null@Fw4jSpringIoc("WebsiteTypeService")voidsetWebsiteService(WebsiteTypeServicewebsiteTypeService){this.websiteTypeService=websiteTypeService}@POST("/add")Stringadd(InParaminParam){WebsiteTypewst=newWebsiteType()wst.name=inParam['name']websiteTypeService.save(wst)"redirect:/WebRoot/websitetype/show"}@GET("/del")Stringdel(InParaminParam){defid=Integer.parseInt(inParam['id'])websiteTypeService.del(id)"redirect:/WebRoot/websitetype/show"}@PUT("/total")StringtotalAdd(InParaminParam){defid=inParam['id']WebsiteTypewst=this.websiteTypeService.get(id)wst.websiteTotalNum++this.websiteTypeService.save(wst)"redirect:/WebRoot/websitetype/show"}}web.xml:<?xmlversion="1.0"encoding="UTF-8"?><web-appxmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"xmlns="https://java.sun.com/xml/ns/javaee"xmlns:web="https://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="https://java.sun.com/xml/ns/javaeehttps://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"id="WebApp_ID"version="3.0"><display-name>fw4j</display-name><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list><servlet-mapping><servlet-name>fw4j</servlet-name><url-pattern>/</url-pattern></servlet-mapping><servlet><servlet-name>fw4j</servlet-name><servlet-class>com.cn.fw4j.mvc.servlet.DispatcherServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet><servlet-name>static</servlet-name><servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class></servlet><servlet-mapping><servlet-name>static</servlet-name><url-pattern>/static/*</url-pattern></servlet-mapping><servlet-mapping><servlet-name>static</servlet-name><url-pattern>*.html</url-pattern></servlet-mapping></web-app>
评论