easystruts-1.0.0简单配置注解版,支持json、jsp

来源:互联网 发布:厦门书生商友软件 编辑:程序博客网 时间:2024/06/06 01:40

笔者一直倾向于filter → selvert 的开发模式,根据Springboot简单配置的优点,简化了struts的开发


web.xml配置

<!-- 加载struts2容器 --><listener><listener-class>com.xjcy.easystruts.web.ContextLoaderListener</listener-class></listener>

struts2.properties配置

package=com.xjcy.crownconAdminnotfilter=jpg,png,gif,jpeg,bmp,css,js

请将 struts2.properties文件放在src目录下,1.0.1版本已去除package配置,框架可自动获取当前项目的包名


使用方式

@RequestMapping("/user")public class UserController extends ActionSupport{@RequestMapping("/test")public String name(){return "hello";}@RequestMapping("/test1")public Map<?,?> name2(){Map<String,Object> map = new HashMap<>();map.put("aa", 1);map.put("bb", 2);map.put("cc", 3);return map;}@RequestMapping("/test2")public ModelAndView name3(){//getRequest();//getResponse();ModelAndView mav = new ModelAndView();mav.addObject("test", 123456);mav.setViewName("index");return mav;}@RequestMapping("/test3")@ResponseNone //自己处理responsepublic void test3() throws IOException{HttpServletResponse response = getResponse();PrintWriter pw = response.getWriter();pw.write("test3");pw.close();}/** * 此方法为上传回调,自己处理file.getInputStream() * 返回上传后的路径 * action通过getMultiparFiles("uploadName1")获取文件上传后路径 */@Overrideprotected String processMultipartFile(MultipartFile file){//file.getInputStream()return null;}}


源码下载:https://github.com/yydf/easystruts-xjcy

DEMO下载:https://github.com/yydf/easystruts-xjcy/blob/master/demo.zip

原创粉丝点击