最近在看jfinal框架,然后记录下自己上手的知识。
有点像天下武功,唯快不破,来试下enjoy模板引擎
简单高效
为什么使用Jfinal Enjoy作为前端页面渲染?简单高效
1.引入Enjoy
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>enjoy</artifactId>
<version>4.5</version>
</dependency>
2.EnjoyConfig
代码如下:
package com.example.demo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.jfinal.template.ext.spring.JFinalViewResolver;
import com.jfinal.template.source.ClassPathSourceFactory;
@Configuration
public class EnjoyConfig {
@Bean
public JFinalViewResolver jFinalViewResolver() {
JFinalViewResolver jfr = new JFinalViewResolver();
jfr.setDevMode(false);
jfr.setSourceFactory(new ClassPathSourceFactory());
//设置模板根路径
jfr.setPrefix("/templates/");
//设置模板后缀
jfr.setSuffix(".html");
jfr.setContentType("text/html;charset=UTF-8");
jfr.setOrder(0);
return jfr;
}
}
现在还有点小问题,前端代码修改后,刷新不能及时同步
前端代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="index_3.html">首页</a>
#(name)
</body>
</html>
Controller
@Controller
public class indexController {
@GetMapping("/login")
public String getzxx(Model model){
model.addAttribute("name", "张三");
return "/login/login";
}
}
使用JfinalEnjoy快速搭建前端模板引擎
本文介绍了如何在项目中集成JfinalEnjoy模板引擎,以实现简单高效的前端页面渲染。通过添加依赖,配置EnjoyConfig,并展示了一个简单的Controller示例,演示了如何将数据传递给前端模板并渲染。然而,目前遇到的问题是前端代码修改后无法实时同步。
1308

被折叠的 条评论
为什么被折叠?



