@jfinal jfinal Bean 继承 Model,无法扩展自己的属性
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
引用来自“JFinal”的评论
用 jfinal 的 model 生成器搞定一切。手册上有说明,官网的 jfinal demo 中有现成的代码可用
用 jfinal 的 model 生成器搞定一切。手册上有说明,官网的 jfinal demo 中有现成的代码可用