package cn.jbolt.api;
import java.util.List;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import cn.jbolt.common.service.CouponGoodsService;
public class CouponController extends Controller {
/**
* 首页Action
*/
@Inject
CouponGoodsService service;
public void index() {
try {
setAttr("list", service.paginate(1, 10));
}catch(Exception e ) {
renderText(e.getMessage());
}
//render("/WEB-INF/view/index/list.html");
}
}
service层
package cn.jbolt.common.service;
import java.util.List;
import com.jfinal.plugin.activerecord.Page;
import cn.jbolt.common.model.CouponGoods;
public class CouponGoodsService {
/**
* 所有的 dao 对象也放在 Service 中
*/
private static final CouponGoods dao = new CouponGoods().dao();
public Page<CouponGoods> paginate(int pageNumber, int pageSize) {
return dao.paginate(pageNumber, pageSize, "select *", "from coupon_goods order by id asc");
}
public CouponGoods findById(int id) {
return dao.findById(id);
}
public void deleteById(int id) {
dao.deleteById(id);
}
public List<CouponGoods> find() {
return dao.find("select * from coupon_goods order by id asc");
}
}
model层
package cn.jbolt.common.model;
import cn.jbolt.common.model.base.BaseCouponGoods;
/**
* Generated by JFinal.
*/
@SuppressWarnings("serial")
public class CouponGoods extends BaseCouponGoods<CouponGoods> {
public static final CouponGoods dao = new CouponGoods().dao();
}
用maven jetty run出现的异常
[ERROR]-[Thread: qtp665512315-24]-[com.jfinal.core.JFinalFilter.doFilter()]: /api/coupon/index
java.lang.IllegalStateException: WRITER
at org.eclipse.jetty.server.Response.getOutputStream(Response.java:667)
at com.jfinal.render.ErrorRender.render(ErrorRender.java:58)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:125)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:89)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1476)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Unknown Source)