首页 文章 精选 留言 我的

精选列表

搜索[环境],共10000篇文章
优秀的个人博客,低调大师

编码风格:Mvc模式下SSM环境,代码分层管理

本文源码:GitHub·点这里 || GitEE·点这里 一、分层策略 MVC模式与代码分层策略,MVC全名是ModelViewController即模型-视图-控制器,作为一种软件设计典范,用一种业务逻辑、数据、界面显示分离的方法组织代码,将业务逻辑聚集到一个部件里面,在改进和个性化定制界面及用户交互的同时,不需要重新编写业务逻辑,这是一种开发模式,但并不是实际开发中代码的分层模式,通常SSM框架的后端代码分层如下: controller控制层:定义服务端接口,入参出参,和一些入参校验; service业务服务层:组装业务逻辑,业务校验,构建控制层需要的参数模型; dao数据交互层:提供服务层需要的数据查询方法,处理数据交互条件相关的逻辑; mapper持久层:基于mybatis框架需要的原生支持,目前很常用的持久层组件; 二、控制层 1、Rest接口风格 基于资源访问和处理的逻辑,使用不同风格的注解。例如资源新增,更新,查询,删除。 /** * 新增 */ @PostMapping("/insert") public Integer insert (@RequestBody BaseInfo baseInfo){ return baseInfoService.insert(baseInfo); } /** * 更新 */ @PutMapping("/update/{id}") public String update(@PathVariable(value = "id") Integer id, @RequestBody BaseInfo baseInfo) { if (id<1){ return "error"; } baseInfo.setId(id); return "update="+baseInfoService.update(baseInfo); } /** * 主键查询 */ @GetMapping("/detail/{id}") public InfoModel detail(@PathVariable(value = "id") Integer id) { return baseInfoService.detail(id) ; } /** * 主键删除 */ @DeleteMapping("/delete/{id}") public String delete(@PathVariable(value = "id") Integer id) { baseInfoService.delete(id) ; return "SUS" ; } 2、接口复用度 不建议接口高度复用,例如增删改查都各自对接接口即可,基本原则,不同的客户端端操作,对于独立的接口。 /** * 列表加载 */ @GetMapping("/list") public List<BaseInfo> list() { return baseInfoService.list(new BaseInfoExample()) ; } /** * 列表搜索 */ @PostMapping("/search") public List<BaseInfo> search (@RequestParam("userName") String userName, @RequestParam("phone") String phone) { return baseInfoService.search(userName,phone) ; } 例如常见的list接口,list通常都有会按条件加载的search机制,而且搜索的判断条件很复杂,建议分为两个接口,从实际考虑,大部分场景下都是只使用list接口,很少使用search搜索。 3、入参出参 校验客户端必须条件,例如某某条件必填必选等,如果有问题,快速阻断请求链路,做到程序入口控制层拦截返回。 @PutMapping("/update/{id}") public String update(@PathVariable(value = "id") Integer id, @RequestBody BaseInfo baseInfo) { if (id<1){ return "error"; } baseInfo.setId(id); return "update="+baseInfoService.update(baseInfo); } 参数在三个以下,可以直接陈列入参,参数在三个或三个以上可以使用实体类统一封装。 @PostMapping("/search") public List<BaseInfo> search (@RequestParam("userName") String userName, @RequestParam("phone") String phone) { return baseInfoService.search(userName,phone) ; } 4、参数处理 出参格式处理度基本原则,服务器作为公共资源,避免非必要操作,例如客户端可自行判断返回值是否为空,null等,或者一些常见格式处理,利用客户端适当分担服务器压力。 三、业务服务层 1、业务校验 例如传入订单号,经过数据库层查询,没有订单数据,这里称为业务性质的异常,代码本身没有问题,但是业务逻辑无法正常执行。 public InfoModel detail(Integer id){ BaseInfo baseInfo = baseInfoDao.selectByPrimaryKey(id) ; if (baseInfo != null){ DetailInfoEntity detailInfoEntity = detailInfoDao.getById(id); if (detailInfoEntity == null){ LOG.info("id="+id+"数据缺失 DetailInfo"); } return buildModel(baseInfo,detailInfoEntity) ; } LOG.info("id="+id+"数据完全缺失"); return null ; } 2、组装业务逻辑 通常情况下服务层作为逻辑做复杂的一块,用来拼接业务核心步骤,可以通过业务逻辑判定,一步一步执行程序,避免在程序入口做大量可能用到的对象创建和需求数据查询。 public int insert (BaseInfo record){ record.setCreateTime(new Date()); int insertFlag = baseInfoDao.insert(record); if (insertFlag > 0){ DetailInfoEntity detailInfoEntity = new DetailInfoEntity(); detailInfoEntity.setUserId(record.getId()); detailInfoEntity.setCreateTime(record.getCreateTime()); if(detailInfoDao.save(detailInfoEntity)){ return insertFlag ; } } return insertFlag; } 3、数据模型构建 通常情况业务层是偏复杂的,如果想关快速理解业务层,可以对复杂的业务方法,在提供一个返参构建的方法,用来处理服务层要向控制层回传的参数,这样可以让重度的服务层方法变的清晰。 private InfoModel buildModel (BaseInfo baseInfo,DetailInfoEntity detailInfo){ InfoModel infoModel = new InfoModel() ; infoModel.setBaseInfo(baseInfo); infoModel.setDetailInfoEntity(detailInfo); return infoModel ; } 四、数据交互层 1、逆向工程 这里以使用mybatis框架或者mybatis-plus框架作为参考。如果是mybatis框架,建议逆向工程的模板代码不做自定义的修改,如果需要自定义方法,在mapper和xml层面再自定义一个扩展文件,用来存放自定义的方法和SQL逻辑,这样避免表结构变动大引发的强烈不适。 当然现在大部分都会mybatis-plus作为持久层组件,可以避免上述问题。 2、数据交互 针对业务层的需要,提供相应的数据查询方法,只处理与数据库交互的逻辑,避免出现业务逻辑,尤其在分布式架构下,不同服务的数据查询和组装,不应该出现在该层。 public interface BaseInfoDao { int insert(BaseInfo record); List<BaseInfo> selectByExample(BaseInfoExample example); int updateByPrimaryKey(BaseInfo record); BaseInfo selectByPrimaryKey(Integer id); int deleteByPrimaryKey(Integer id); BaseInfo getById (Integer id) ; } 五、源代码地址 GitHub·地址 https://github.com/cicadasmile/data-manage-parent GitEE·地址 https://gitee.com/cicadasmile/data-manage-parent

优秀的个人博客,低调大师

打造超级舒适的Go开发环境之VIM配置

最近博主已经从VIM迁移到了EMACS作为主要生产工具,目的是为了学习Lisp和体验EMACS操作系统之美,哈哈,不要被我弄的技术焦虑,没错,我就是换了个吃饭的盘子。写下这篇博客也是为了纪念我顺利的“从VIM毕业了”。 在阅读本文之前,你需要: 准备一个UNIX like的操作系统 一个可以跨过山和大海的代-理 话不多说,开始吧~ (1)下载必要的Go工具链 go get -v github.com/mdempsky/gocode go get -v github.com/ramya-rao-a/go-outline go get -v github.com/acroca/go-symbols go get -v github.com/uudashr/gopkgs go get -v golang.org/x/tools/cmd/guru go get -v golang.org/x/tools/cmd/gorename go get -v github.com/sqs/goreturns go get -v github.com/rogpeppe/godef go get -v golang.org/x/tools/cmd/godoc go get -v golang.org/x/lint/golint go get -v github.com/derekparker/delve/tree/master/cmd/dlv go get -v github.com/fatih/gomodifytags go get -v github.com/haya14busa/goplay go get -v github.com/josharian/impl go get -v github.com/tylerb/gotype-live go get -v github.com/cweill/gotests go get -v github.com/sourcegraph/go-langserver go get -v github.com/davidrjenni/reftools/tree/master/cmd/fillstruct (2)安装VIM macOS用户可能需要安装一下macvim: brew install macvim (3)主题配置 为了实现类似于Atom的Onedark和Onelight模式,我们可能需要安装两个主题: onedark.vim(只支持黑暗模式):https://github.com/joshdick/onedark.vim.git one.vim(同时支持):https://github.com/rakr/vim-one.git 在.vim目录下创建三个目录:autoload,bundle,colors,将两个仓库克隆到本地,然后将autoload目录的one.vim或者onedark.vim拷贝到autoload目录,将colors目录的one.vim或者onedark.vim拷贝到colors目录。 配置主题,修改~/.vimrc文件: colorscheme one set background=dark 当你想要将主题更改为Onelight的时候,只要将dark替换为light即可。 (4)插件配置 首先要安装插件管理器Vundle: git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim 然后配置~/.vimrc文件: set nocompatible " be iMproved, required filetype off " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " alternatively, pass a path where Vundle should install plugins "call vundle#begin('~/some/path/here') " let Vundle manage Vundle, required Plugin 'VundleVim/Vundle.vim' " The following are examples of different formats supported. " Keep Plugin commands between vundle#begin/end. " plugin on GitHub repo Plugin 'tpope/vim-fugitive' " plugin from http://vim-scripts.org/vim/scripts.html " Plugin 'L9' " Git plugin not hosted on GitHub Plugin 'git://git.wincent.com/command-t.git' " git repos on your local machine (i.e. when working on your own plugin) Plugin 'file:///home/gmarik/path/to/plugin' " The sparkup vim script is in a subdirectory of this repo called vim. " Pass the path to set the runtimepath properly. Plugin 'rstacruz/sparkup', {'rtp': 'vim/'} " Install L9 and avoid a Naming conflict if you've already installed a " different version somewhere else. " Plugin 'ascenator/L9', {'name': 'newL9'} " All of your Plugins must be added before the following line call vundle#end() " required filetype plugin indent on " required " To ignore plugin indent changes, instead use: "filetype plugin on " " Brief help " :PluginList - lists configured plugins " :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate " :PluginSearch foo - searches for foo; append `!` to refresh local cache " :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal " " see :h vundle for more details or wiki for FAQ " Put your non-Plugin stuff after this line 为了支持多种编程语言,我们采用YouCompleteMe插件,macOS用户使用如下命令: brew install cmake python python3 mono go nodejs 如果你已经使用nvm作为Node.js版本管理器,或者已经通过PKG方式安装了Python3.x版本,那么只需要PATH可以识别到命令,另外nvm用户需要安装npm: brew install npm 接下来需要进行编译: cd ~/.vim/bundle/YouCompleteMe python3 install.py --all 由于YouCompleteMe插件使用Vundle安装可能导致失败,因此通过手动安装的方式实现,其他插件均可以通过Vundle安装: Plugin 'fatih/vim-go' Plugin 'Tagbar' Plugin 'scrooloose/nerdtree' Plugin 'Xuyuanp/nerdtree-git-plugin' Plugin 'vim-airline/vim-airline' Plugin 'vim-airline/vim-airline-themes' 写到.vimrc文件中,然后打开vim,进入命令模式,使用如下命令安装: :PluginInstall vim-go插件需要下载一些工具包,如果使用Vundle安装失败,可以进入vim使用如下命令: :GoInstallBinaries 配置完成后的整个.vimrc文件如下: set nocompatible " be iMproved, required filetype off " required syntax on colorscheme one let g:one_allow_italics = 1 set background=dark set nu let NERDTreeWinSize=50 let NERDTreeShowLineNumbers=1 let NERDTreeAutoCenter=1 let NERDTreeShowHidden=1 let g:go_gopls_enabled = 0 set laststatus=2 "始终显示状态栏 set tabstop=2 "一个制表符的长度 set softtabstop=2 "一个制表符的长度(可以大于tabstop) set shiftwidth=2 "一个缩进的长度 set expandtab "使用空格替代制表符 set smarttab "智能制表符 set autoindent "自动缩进 set smartindent "只能缩进 set ruler "显示位置指示器 set ignorecase "检索时忽略大小写 set hls "检索时高亮显示匹配项 set helplang=cn "帮助系统设置为中文 set foldmethod=syntax "代码折叠 set guifont=PowerlineSymbols\ for\ Powerline set nocompatible set t_Co=256 let g:Powerline_symbols = 'fancy' " let g:nerdtree_tabs_open_on_console_startup=1 "Use 24-bit (true-color) mode in Vim/Neovim when outside tmux. "If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support "(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.) if (empty($TMUX)) if (has("nvim")) "For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 > let $NVIM_TUI_ENABLE_TRUE_COLOR=1 endif "For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 > "Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd > " < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 > if (has("termguicolors")) set termguicolors endif endif " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " alternatively, pass a path where Vundle should install plugins "call vundle#begin('~/some/path/here') " let Vundle manage Vundle, required Plugin 'VundleVim/Vundle.vim' Plugin 'fatih/vim-go' Plugin 'Valloric/YouCompleteMe',{'do':'python3 install.py --all'} Plugin 'Tagbar' Plugin 'scrooloose/nerdtree' Plugin 'Xuyuanp/nerdtree-git-plugin' Plugin 'vim-airline/vim-airline' Plugin 'vim-airline/vim-airline-themes' " All of your Plugins must be added before the following line call vundle#end() " required filetype plugin indent on " required " To ignore plugin indent changes, instead use: "filetype plugin on " " Brief help " :PluginList - lists configured plugins " :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate " :PluginSearch foo - searches for foo; append `!` to refresh local cache " :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal " " see :h vundle for more details or wiki for FAQ " Put your non-Plugin stuff after this line let g:go_highlight_types = 1 let g:go_highlight_fields = 1 let g:go_highlight_functions = 1 let g:go_highlight_function_calls = 1 let g:go_highlight_operators = 1 let g:go_highlight_extra_types = 1

优秀的个人博客,低调大师

DataGrip 2020.1 正式发布,多引擎数据库环境

DataGrip 2020.1 正式发布了,更新内容包括: 运行配置 运行脚本文件的配置 运行代码的配置 支持 utPLSQL 和 tSQLt Data editor 编辑器中的结果 地理检视器 [MongoDB] 数据过滤 导出选项 导出到 Excel 更好的可用性 文字资料检视器 连接性 [PostgreSQL] pg_pass 支持 [SQL Server] 域凭据支持 共享的 SSH 配置 查询控制台 更新预览 轻松导航到执行设置 日期时间注入 [MongoDB] 更好的编码帮助 导航和搜索 上下文数据源范围 结构搜索 文件处理 CSV 档案类型 附加目录 标记为纯文本​​​​​​​ 数据库树视图 用于创建用户和角色的用户界面 用于创建架构和数据库的 UI 更新说明:https://blog.jetbrains.com/datagrip/2020/04/06/datagrip-2020-1/

优秀的个人博客,低调大师

Spring Tools 4.4.1 发布,针对 Spring 应用的开发环境

Spring Tools 4.4.1 发布了。Spring Tools 4 是下一代 Spring 工具,提供了从头开始构建所需的所有功能,为开发基于 Spring 的企业应用提供世界级支持,支持 Eclipse、Visual Studio Code 与Theia。 此版本主要更新亮点包括: (Spring Boot)引入了全新的机制来连接和断开运行中的 Spring 应用程序以显示实时数据 (Spring Boot),(Eclipse)增强功能:Goto Symbol 现在也可以在 XML bean 文件中使用 (Spring Boot),(Eclipse)修复:application.properties 中的完成有时会留下一些“垃圾”文本 (Spring Boot):提升xml 符号扫描的性能 (Spring Boot):将 lsp4xml 更新为 0.9.1 以解决(CVE-2019-18212) + (CVE-2019-18213) (Concourse)增强功能:添加了对注册表图像资源类型的支持 更新公告:https://spring.io/blog/2019/10/24/spring-tools-4-4-1-released 下载地址:https://spring.io/tools/

优秀的个人博客,低调大师

Spring Tools 4.3.2 发布,针对 Spring 应用的开发环境

Spring Tools 4.3.2 版本发布了。Spring Tools 4 是为你量身打造的下一代 Spring 工具,无论你喜欢 Eclipse、Visual Studio Code 还是 Atom IDE ,它都可以提供从头开始构建所需的所有功能,为开发基于 Spring 的企业应用提供世界级支持。 新版值得关注的更新内容有: (Spring Boot)fixed:CTRL 单击导航不能正确处理超类上的属性 (#326) (Spring Boot)fixed:配置属性分析不能正确处理以 snake_case 编写的属性 (#327) (Eclipse)fixed:语言服务器进程在特定情况下未正确终止,导致许多语言服务器进程在 Eclipse 打开时继续运行 (Eclipse)fixed:由于使用约束违规,无法解析 Eclipse Language Server (#325) (Eclipse)fixed:由 xmlnamespace 支持导致的 UI 冻结? (#318) (Eclipse)fixed:缺少 javax.inject 导入导致启动仪表板中的 CF 集成失败 一些其他的错误修复 更新公告:https://spring.io/blog/2019/08/14/spring-tools-4-3-2-released

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码