Jfinal支持mysql表里面的中文字段吗

把demo 中blog表里面的title字段名改成中文“标题”,然后把blog.html中的id.title改成”id.标题“运行后eclipse 立即报错。

2019-05-20 06:41:40

[ERROR]-[Thread: XNIO-1 task-2]-[com.jfinal.core.ActionHandler.handle()]: /blog/

com.jfinal.template.stat.ParseException: # parameter exists illegal char: '标'

Template: "/blog/blog.html". Line: 18

at com.jfinal.template.stat.Lexer.scanPara(Lexer.java:278)

at com.jfinal.template.stat.Lexer.scanDire(Lexer.java:110)

at com.jfinal.template.stat.Lexer.scan(Lexer.java:60)

at com.jfinal.template.stat.Parser.parse(Parser.java:74)

at com.jfinal.template.Engine.buildTemplateBySourceFactory(Engine.java:164)

at com.jfinal.template.Engine.getTemplate(Engine.java:145)

at com.jfinal.render.TemplateRender.render(TemplateRender.java:61)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:106)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:89)

at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)

at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)

at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)

at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)

at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)

at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)

at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)

at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)

at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)

at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)

at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)

at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)

at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

at io.undertow.servlet.handlers.SessionRestoringHandler.handleRequest(SessionRestoringHandler.java:119)

at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)

at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)

at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)

at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)

at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)

at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)

at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)

at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)

at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)

at io.undertow.server.Connectors.executeRootHandler(Connectors.java:364)

at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)


评论区

JFinal

2019-05-21 10:43

enjoy 模板引擎暂不支持 中文 field 取值,例如下面的是不允许的:
#(obj.中文)

但可以调用方法,例如:
#(obj.get("中文"))

如果未来有很多这方面的需求,会考虑改这里。目前你非得要使用这个功能,可以适当改改 enjoy 源码,实现起来并不难,开放表达式的字符类型检测即可

最后,强烈建议不要使用中文字段名,先不说正不正确,起码让内行人一看就会怀疑设计者的水平

这个就跟变量名使用拼音类似

RichardHe

2019-05-22 08:27

程序里写拼音连中国人都看不懂写的是啥,中国人的英语也不敢恭维。数据库里写汉字就可以稍微防一下外国黑客,也可以让越来越多的中国菜鸟学会写程序。写程序并不是很难,只是英语让很多人望而却步了。我们要想想为国人和周围的人做些什么。有人在不自觉地维持门槛,有人却想打破他。

RichardHe

2019-05-22 11:19

多谢詹大侠指导

热门反馈

扫码入社