(9)示例:TestController:
package com.xiaopengwei.demo.xcontroller; import com.xiaopengwei.demo.xservice.ITestXService; import com.xiaopengwei.xspring.annotation.XAutowired; import com.xiaopengwei.xspring.annotation.XController; import com.xiaopengwei.xspring.annotation.XRequestMapping; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; /** * <p> * 前置控制器 * * @author XiaoPengwei * @since 2019-07-19 */ @XController @XRequestMapping("/test") public class TestController { @XAutowired ITestXService testXService; /** * 测试方法 /test/query * * @param req 请求体 * @param resp 响应体 */ @XRequestMapping("/query") public void query(HttpServletRequest req, HttpServletResponse resp) { if (req.getParameter("username") == null) { try { resp.getWriter().write("param username is null"); } catch (IOException e) { e.printStackTrace(); } } else { String paramName = req.getParameter("username"); try { resp.getWriter().write("param username is " + paramName); } catch (IOException e) { e.printStackTrace(); } System.out.println("[INFO-req] New request param username-->" + paramName); } } /** * 测试方法 /test/listClassName * * @param req 请求体 * @param resp 响应体 */ @XRequestMapping("/listClassName") public void listClassName(HttpServletRequest req, HttpServletResponse resp) { String str = testXService.listClassName(); System.out.println("testXService----------=-=-=>" + str); try { resp.getWriter().write(str); } catch (IOException e) { e.printStackTrace(); } } }手写 Spring (2)
内容版权声明:除非注明,否则皆为本站原创文章。