JFinal Controller中不能设定全局变量

kxf327 发布于 2013/11/10 13:20
阅读 710
收藏 0

    因为JFinal 把Dao去掉了,于是我开发中大量使用了Db模式,很方便。

    今天想设定个全局变量SQL,其它action调用时候可以拼接SQL语句,访问这个action就报错了,而且没有进入action。


       public class UserController{
         /**     
           * 三表联接
	 */
	StringBuffer sql = new StringBuffer("SELECT * " +
			" FROM teacher t, m_teacher_student m, student s " +
			" WHERE t.id = m.teacher AND m.student = s.id ");
    public void showExamStudents(){
       this.sql.append(" and s.id = '" + getUserId() + "' ");
    }

}


报错信息:

[ERROR]-[Thread: qtp5778967-24]-[com.jfinal.core.ActionHandler.handle()]: /teacher/showExamStudents
java.lang.NullPointerException
at com.jfinal.core.Controller.getCookieObject(Controller.java:454)
at com.jfinal.core.Controller.getCookie(Controller.java:407)
at com.jfinal.core.Controller.getCookie(Controller.java:415)
at com.bdschool.evaluate.controler.TeacherController.<init>(TeacherController.java:123)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:68)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)
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:724)

    估计是@JFinal不允许有那么些额外的参数吧!那个可以加上吗?

加载中
0
cwledit
cwledit
你这个没看懂要干什么
kxf327
kxf327
不好意思,偷了个懒,刚修改了下代码,现在能看清了吧
0
JFinal
JFinal
sql 有错误,例如这样的都有错误:" WHERE t.id = m.teacher AND m.student = s.id ", 用引号将 s.id 这样的值引起来了,那么这就是常量,而应该这样:" WHERE t.id = ? AND m.student = ? "
0
stu51
stu51

用and写关联查询。。

返回顶部
顶部