开发者社区> 问答> 正文

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

@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

 

展开
收起
爱吃鱼的程序员 2020-06-08 15:51:50 616 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

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

    引用来自“JFinal”的评论

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

    2020-06-08 15:52:02
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
introduction to Apache Bean 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载

相关实验场景

更多