Files
py-enjoy/README.md
2026-02-28 11:22:00 +08:00

45 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# py-enjoy
jfinal-enjoy 5.2.2 的python 3.9.0 实现基于jpype1实现。
python port by mrzhou@miw.cn
### 使用样例
```python
from enjoy import Enjoy
if __name__ == "__main__":
# 1. 配置参数(必须修改为你的实际路径)
JAR_PATH = "enjoy-5.2.2.jar" # enjoy-5.2.2.jar的绝对/相对路径
TEMPLATE_BASE_PATH = "./templates" # 模板文件所在目录如index.html放在这个目录下
# 2. 创建Enjoy实例初始化Engine
try:
enjoy = Enjoy(
jar_path=JAR_PATH,
template_base_path=TEMPLATE_BASE_PATH
)
# 3. 准备模板参数
render_data = {
"name": "JFinal Enjoy 5.2.2测试",
"hobbies": ["Python调用Java", "模板渲染", "跨语言开发"],
"user": {"age": 25, "gender": ""}
}
# 4. 渲染模板tempStr是模板文件名相对于TEMPLATE_BASE_PATH
result = enjoy.render(
tempStr="index.html", # 模板文件:./templates/index.html
data=render_data # 渲染数据Python字典
)
# 5. 输出结果
print("\n=== 模板渲染结果 ===")
print(result)
except RuntimeError as e:
print(f"\n执行失败: {e}")
finally:
# 6. 关闭资源
if 'enjoy' in locals():
enjoy.close()
```