博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Springmvc 整合 jetbrick 实例
阅读量:5773 次
发布时间:2019-06-18

本文共 10521 字,大约阅读时间需要 35 分钟。

应用环境: 

<jetbrick.version>1.2.8</jetbrick.version>

<antlr4-runtime.version>4.2.2</antlr4-runtime.version>

<spring.mybatis.common.version>2.0</spring.mybatis.common.version>

项目结构:

实例展示:

1.引如pom依赖

4.0.0
com.spring.mybatis
jetbrick-mvc
war
0.0.1-SNAPSHOT
jetbrick-mvc Maven Webapp
http://maven.apache.org
UTF-8
1.7.7
4.11
4.1
1.1.3
1.7
1.2.8
4.2.2
2.4
jetbrick-template
jetbrick-template
${jetbrick.version}
com.spring.mybatis
spring-mybatis-data-common
2.0
org.apache.geronimo.specs
geronimo-servlet_3.0_spec
junit
junit
${junit.version}
test
org.slf4j
slf4j-api
${slf4j.version}
org.antlr
antlr4-runtime
${antlr4-runtime.version}
servlet-api
servlet-api
${servlet.version}
jetbrick-mvc

2.添加jetbrick的监听与配置文件到web.xml

org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath*:context/spring-context.xml
org.springframework.web.util.IntrospectorCleanupListener
jetbrick.template.web.JetWebEngineLoader
jetbrick-template-config-location
classpath:template/jetbrick-template.properties
org.springframework.web.util.Log4jConfigListener
log4jConfigLocation
classpath:property/log4j.properties
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
encodingFilter
/*
spring-controller
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath*:context/spring-mvc.xml
1
spring-controller
/
60
index.jsp

3.配置jetbrick的全局属性

import.packages = com.mvc.cmrn.dao, com.mvc.cmrn.model#import inner define function,once import use anywhere import.functions = jetbrick.template.runtime.JetFunctions#set autoscan is trueimport.autoscan = true#set autoscan packageimport.autoscan.packages = com.mvc.cmrn#set reloadable is truetemplate.reloadable = trueinput.encoding= UTF-8output.encoding=UTF-8template.reloadable = true#template.path  +  spring prefix +   VIEW + spring suffix (or?? template.suffix)template.path=/WEB-INF/jetx/compile.debug = truetemplate.loader = jetbrick.template.web.WebResourceLoader#more config read :http://subchen.github.io/jetbrick-template/config.html

4.定义jetbrick为应用试图

5.springmvc操作

package com.mvc.cmrn.controller;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.ModelAttribute;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.servlet.ModelAndView;import com.mvc.cmrn.model.Member;import com.mvc.cmrn.service.IMemberService;import com.spring.mybatis.data.common.controller.BaseMultiController;@Controller@RequestMapping("/member")public class MemberController extends BaseMultiController{    @Autowired    private IMemberService memberService;        @RequestMapping(value={"/{id:\\d+}/query.baidu"},method={RequestMethod.GET,RequestMethod.POST})    public ModelAndView query(HttpServletRequest request,HttpServletResponse response,@ModelAttribute("id") Long id){        Map
map = new HashMap
(); Member member = this.memberService.query(id); map.put("member", member); String viewPath = "front/detail"; return toView(viewPath, map); } @RequestMapping(value={"/lists.baidu"},method={RequestMethod.GET,RequestMethod.POST}) public ModelAndView lists(HttpServletRequest request,HttpServletResponse response){ Map
map = new HashMap
(); List
lists = this.memberService.list(); map.put("item", lists); String viewPath = "front/list"; return toView(viewPath, map); } @RequestMapping(value={"/{id:\\d+}/delete.baidu"},method={RequestMethod.GET,RequestMethod.POST}) public ModelAndView delete(HttpServletRequest request,HttpServletResponse response,@ModelAttribute("id") Long id){ Map
map = new HashMap
(); int result = this.memberService.delete(id); if(result>0){ map.put("message", "Delete OK"); }else{ map.put("message", "Delete Error"); } List
lists = this.memberService.list(); map.put("item", lists); String viewPath = "front/list"; return toView(viewPath, map); } public IMemberService getMemberService() { return memberService; } public void setMemberService(IMemberService memberService) { this.memberService = memberService; } }
package com.mvc.cmrn.controller;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.ModelAttribute;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.servlet.ModelAndView;import com.mvc.cmrn.model.Member;import com.mvc.cmrn.service.IMemberService;import com.spring.mybatis.data.common.controller.BaseMultiController;@Controller@RequestMapping("/member")public class MemberController extends BaseMultiController{    @Autowired    private IMemberService memberService;        @RequestMapping(value={"/{id:\\d+}/query.baidu"},method={RequestMethod.GET,RequestMethod.POST})    public ModelAndView query(HttpServletRequest request,HttpServletResponse response,@ModelAttribute("id") Long id){        Map
map = new HashMap
(); Member member = this.memberService.query(id); map.put("member", member); String viewPath = "front/detail"; return toView(viewPath, map); } @RequestMapping(value={"/lists.baidu"},method={RequestMethod.GET,RequestMethod.POST}) public ModelAndView lists(HttpServletRequest request,HttpServletResponse response){ Map
map = new HashMap
(); List
lists = this.memberService.list(); map.put("item", lists); String viewPath = "front/list"; return toView(viewPath, map); } @RequestMapping(value={"/{id:\\d+}/delete.baidu"},method={RequestMethod.GET,RequestMethod.POST}) public ModelAndView delete(HttpServletRequest request,HttpServletResponse response,@ModelAttribute("id") Long id){ Map
map = new HashMap
(); int result = this.memberService.delete(id); if(result>0){ map.put("message", "Delete OK"); }else{ map.put("message", "Delete Error"); } List
lists = this.memberService.list(); map.put("item", lists); String viewPath = "front/list"; return toView(viewPath, map); } public IMemberService getMemberService() { return memberService; } public void setMemberService(IMemberService memberService) { this.memberService = memberService; } }

6.获取应用路径

在全局属性配置文件jetbrick-template.properties中引入的jetbrick模板中自定义的函数.通过函数webroot()获取路径.

#for(Member member: item)
#end
ID 姓名 邮箱 查看 删除
${user.id} ${user.name} ${user.email} 查看 删除

语法说明: 

实例下载: http://files.cnblogs.com/dennisit/springmvc-jetbrick-demo.7z
转载请注明出处:[]

你可能感兴趣的文章
vue开发框架搭建(详细版)
查看>>
函数计算性能福利篇(二) —— 业务冷启动优化
查看>>
分布式环境各种问题 与 CAP/BASE
查看>>
学习Python3 进程,这一篇就够了
查看>>
对Session.getAttribute(),Request.setAttribute()和ModelMap.addAttribute()用法的理解
查看>>
set uid/set gid/sticky bit、软链接、硬链接
查看>>
PublicCMS 网站漏洞 任意文件写入并可提权服务器权限
查看>>
【CentOS 7笔记】,目录权限,所有者与所有组,隐藏权限
查看>>
20181211 上课截图
查看>>
Java程序员达到高薪架构师的一套完美总结(涨薪必看)
查看>>
C# fmpeg加虹软的人脸识别demo
查看>>
Spring AOP 切面编程记录日志和接口执行时间
查看>>
线下实体店应用小程序,实现收益翻倍
查看>>
JavaScript闭包原理与用法实例
查看>>
hadoop运行java类
查看>>
Debian下自动备份MySQL数据库并上传到远程FTP服务器且删除指定日
查看>>
hadoop 网站日志分析
查看>>
最长回文串-我的算法
查看>>
Docker:启动Redis镜像
查看>>
16进制对应颜色代码
查看>>