@jfinal jfinal Bean 继承 Model,无法扩展自己的属性

发布于 2021-12-04 21:32:36 字数 10710 浏览 678 评论 2

@jfinal

public class Station extends Model<Station>{
    public static Station dao = new Station();
}
public class Line extends Model<Line> {
    public static Line dao = new Line();

    private List<Station> stations;

    public List<Station> getStations() {
        return stations;
    }

    public void setStations(List<Station> stations) {
        this.stations = stations;
    }

}
public class BusController extends BaseController {
    public void search() {
        SqlPara sqlPLine = new SqlPara();
        StringBuffer sqlLine = new StringBuffer();
        sqlLine.append("select * from ").append(ModelConfigBus.TABLE_Line);
        sqlLine.append(" where 1=1 ");
        // 条件
        String bus_name = getPara("line_name", "");
        if (StringUtils.isNotEmpty(bus_name)) {
            sqlLine.append(" and name like ?");
            sqlPLine.addPara("%" + bus_name + "%");
        }
        //
        sqlPLine.setSql(sqlLine.toString());
        List<Line> lines = Line.dao.find(sqlPLine);
        if (lines == null || lines.size() == 0) {
            renderJson("[]");
        }
        for (Line line : lines) {
            //
            SqlPara sqlPStation = new SqlPara();
            StringBuffer sqlStation = new StringBuffer();
            sqlStation.append("select a.* from ");
            sqlStation.append(ModelConfigBus.TABLE_Station).append(" a ,");
            sqlStation.append(ModelConfigBus.TABLE_Line_Station_Relation).append(" b ");
            sqlStation.append(" where a.id = b.station_id ");
            sqlStation.append(" and b.line_id =  ");
            sqlStation.append(line.getInt("id"));
            sqlPStation.setSql(sqlStation.toString());
            List<Station> stations = Station.dao.find(sqlStation.toString());
            if (stations != null && stations.size() > 0) {
                line.setStations(stations);
            }
        }
        renderJson(lines);
    }
}

 

报错

java.lang.RuntimeException: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class com.koomii.model.bus.Station and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.ArrayList[0]->com.koomii.model.bus.Line["stations"]->java.util.ArrayList[0])
    at com.jfinal.json.Jackson.toJson(Jackson.java:82)
    at com.jfinal.kit.JsonKit.toJson(JsonKit.java:28)
    at com.jfinal.render.JsonRender.<init>(JsonRender.java:124)
    at com.jfinal.render.RenderFactory.getJsonRender(RenderFactory.java:103)
    at com.jfinal.core.Controller.renderJson(Controller.java:1057)
    at com.koomii.controller.bus.BusController.search(BusController.java:47)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.jfinal.aop.Invocation.invoke(Invocation.java:73)
    at com.jfinal.ext.interceptor.SessionInViewInterceptor.intercept(SessionInViewInterceptor.java:44)
    at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
    at com.jfinal.ext.plugin.shiro.ShiroInterceptor.intercept(ShiroInterceptor.java:49)
    at com.jfinal.aop.Invocation.invoke(Invocation.java:67)
    at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74)
    at com.koomii.common.HtmlHandler.handle(HtmlHandler.java:16)
    at com.jfinal.plugin.druid.DruidStatViewHandler.handle(DruidStatViewHandler.java:75)
    at com.jfinal.ext.handler.ContextPathHandler.handle(ContextPathHandler.java:48)
    at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:74)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
    at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
    at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
    at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
    at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
    at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
    at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
    at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
    at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
    at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
    at org.eclipse.jetty.server.Server.handle(Server.java:365)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635)
    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:628)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
    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(Thread.java:745)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class com.koomii.model.bus.Station and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.ArrayList[0]->com.koomii.model.bus.Line["stations"]->java.util.ArrayList[0])
    at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:59)
    at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:26)
    at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:100)
    at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:21)
    at com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:183)
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:503)
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:639)
    at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:152)
    at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:100)
    at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:21)
    at com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:183)
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:114)
    at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:2866)
    at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:2323)
    at com.jfinal.json.Jackson.toJson(Jackson.java:80)
    ... 55 more

 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱你是孤单的心事 2021-12-06 07:21:57

引用来自“JFinal”的评论

用 jfinal 的 model 生成器搞定一切。手册上有说明,官网的 jfinal demo 中有现成的代码可用

网名女生简单气质 2021-12-05 19:53:11

用 jfinal 的 model 生成器搞定一切。手册上有说明,官网的 jfinal demo 中有现成的代码可用

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文