3.创建Controller类

最后更新:2024-02-19 16:59:58 | 状态:未完成

如果是web项目还需要controller类
每个项目中一般要有一个基础的父类用来实现一些公用的方法
最好是继承org.anyline.controller.impl.AnylineController(在anyline-mvc中),因为AnylineController中提供了利用HttpRequest构造查询条件的方法
如果是JSP项目可以继承org.anyline.controller.impl.TemplateController会针对JSP有更多的支持

package org.anyline.simple.clear.controller;

import org.anyline.controller.impl.AnylineController;

/**
 * 这里一般要创建一个全局的base controller作为其他controller的父类
 * BasicController可以继承自AnylineController
 * AnylineController里已经注入了AnylineService
 */
public class BasicController extends AnylineController {
}
package org.anyline.simple.clear.controller;

import org.anyline.entity.DataSet;
import org.anyline.service.AnylineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller("web.home.DefaultController")
@RequestMapping("/")
public class DefaultController extends BasicController {
    //访问url
    // http://127.0.0.1:8080/list?id=1&id=2
    // 生成SQL SELECT * FROM crm_user WHERE( ID IN (?,?)) LIMIT 0,10

    // http://127.0.0.1:8080/list?n=A
    //生成SQL SELECT * FROM crm_user WHERE (NAME LIKE concat('%',?,'%')) LIMIT 0,10
    @RequestMapping("list")
    @ResponseBody
    public String list() {
        //这里的true表示 需要分页
        DataSet set = service.querys("crm_user", condition(true,"NAME:%n%","ID:[id]"));
        return success(set);
    }

}

到这里就结束了,没有下一步的service,dao,mapping也没有VO PO什么O也没有,
当然有也可以,但那不属于入门范畴,就不在这里说了.

最近更新 搜索 提交