日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術(shù)文章
文章詳情頁

SpringBoot+Vue實現(xiàn)數(shù)據(jù)添加功能

瀏覽:108日期:2023-03-21 10:00:04
一、添加代碼生成器

用來自動為數(shù)據(jù)庫映射類建立:mapper、service、controller

注:代碼生成器的寫法,參考官方文檔:https://mp.baomidou.com/

package com.hanmh.utils;import com.baomidou.mybatisplus.core.toolkit.StringPool;import com.baomidou.mybatisplus.generator.AutoGenerator;import com.baomidou.mybatisplus.generator.InjectionConfig;import com.baomidou.mybatisplus.generator.config.*;import com.baomidou.mybatisplus.generator.config.po.TableInfo;import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;import com.hanmh.pojo.BasePojo; import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map; public class HanGenerator { public static void main(String[] args) { // 代碼生成器 AutoGenerator mpg = new AutoGenerator(); // 全局配置 GlobalConfig gc = new GlobalConfig(); //這樣獲取到的是父項目的目錄 String projectPath = System.getProperty('user.dir'); String pojoProject = 'pojo' + '/src/main/java/com/hanmh/pojo'; String otherProject = 'admin'; //gc.setOutputDir(projectPath + '/src/main/java'); gc.setAuthor('hanmh'); gc.setOpen(false); // gc.setSwagger2(true); 實體屬性 Swagger2 注解 mpg.setGlobalConfig(gc); // 數(shù)據(jù)源配置 DataSourceConfig dsc = new DataSourceConfig(); dsc.setUrl('jdbc:mysql://39.105.231.52:3306/db?useUnicode=true&useSSL=false&characterEncoding=utf8'); // dsc.setSchemaName('public'); dsc.setDriverName('com.mysql.jdbc.Driver'); dsc.setUsername('root'); dsc.setPassword('123456'); mpg.setDataSource(dsc); // 包配置 PackageConfig pc = new PackageConfig(); pc.setParent('com.hanmh'); //設(shè)置父包 //自定義生成路徑 Map<String,String> pathInfo = new HashMap<String,String>(); pathInfo.put('entity_path', projectPath + '/' + pojoProject); //pojo位置 pathInfo.put('controller_path', projectPath + '/' + otherProject + '/src/main/java/com/hanmh/controller'); pathInfo.put('service_impl_path', projectPath + '/' + otherProject + '/src/main/java/com/hanmh/service/impl'); pathInfo.put('service_path', projectPath + '/' + otherProject + '/src/main/java/com/hanmh/service'); pathInfo.put('mapper_path', projectPath + '/' + otherProject + '/src/main/java/com/hanmh/mapper'); pathInfo.put('xml_path', projectPath + '/' + otherProject + '/src/main/resources/com/hanmh/mapper'); pc.setEntity('pojo'); //實體類 pc.setPathInfo(pathInfo); mpg.setPackageInfo(pc); // 自定義配置 InjectionConfig cfg = new InjectionConfig() { @Override public void initMap() {// to do nothing } }; // 如果模板引擎是 freemarker String templatePath = '/templates/mapper.xml.ftl'; // 策略配置 StrategyConfig strategy = new StrategyConfig(); strategy.setNaming(NamingStrategy.underline_to_camel); strategy.setColumnNaming(NamingStrategy.underline_to_camel); //生成時,繼承的父類 strategy.setSuperEntityClass(BasePojo.class); strategy.setEntityLombokModel(true); strategy.setRestControllerStyle(true); // 公共父類 strategy.setSuperControllerClass('你自己的父類控制器,沒有就不用設(shè)置!'); // 寫于父類中的公共字段 strategy.setSuperEntityColumns('id'); strategy.setInclude('ums_admin'); strategy.setControllerMappingHyphenStyle(true); strategy.setTablePrefix(pc.getModuleName() + '_'); mpg.setStrategy(strategy); mpg.setTemplateEngine(new FreemarkerTemplateEngine()); mpg.execute(); }}二、導(dǎo)入需要的jar包

前期需要導(dǎo)入的包有:mybatis-plus、mysql、duracloud(工具包)、pojo、spring-boot-starter-web

<dependency> <groupId>com.hanmh</groupId> <artifactId>pojo</artifactId></dependency><dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId></dependency><dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId></dependency><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency><dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId></dependency><dependency> <groupId>org.duracloud</groupId> <artifactId>common</artifactId></dependency>三、創(chuàng)建啟動類

啟動類必須創(chuàng)建在父包下面,注意在SpringBoot中,并不是不掃包,而是框架幫助完成了這件事,它會掃描啟動類所在包下的所有類及其子包中的類

package com.hanmh; import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication@MapperScan('com.hanmh.mapper')public class AdminRun { public static void main(String[] args) { SpringApplication.run(AdminRun.class); }}四、創(chuàng)建配置文件(application.yml)

server: port: 8080spring: application: name: admin datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://39.105.231.52:3306/db?useUnicode=true&useSSL=false&characterEncoding=utf8 username: root password: 123456 hikari: maximum-pool-size: 20 minimum-idle: 10 servlet: #文件傳輸配置 multipart: max-file-size: 5MB max-request-size: 10MB#運行的過程中輸出sql語句(日志信息)logging: level: com.hanmh.mapper: debug五、返回值統(tǒng)一定義1、ResultJson

package com.hanmh.pojo; import lombok.Data; @Datapublic class ResultJson { private Integer code; //200成功,500錯誤 private Object obj; private String message; public ResultJson(ResultCode resultCode, Object obj) { this.code = resultCode.getCode(); this.message = resultCode.getMessage(); this.obj = obj; } public ResultJson(ResultCode resultCode, Object obj, String message) { this.code = resultCode.getCode(); this.message = message; this.obj = obj; } public static ResultJson success(Object obj) { return new ResultJson(ResultCode.SUCCESS, obj); } public static ResultJson success(Object obj, String message) { return new ResultJson(ResultCode.SUCCESS, obj, message); } public static ResultJson error(Object obj) { return new ResultJson(ResultCode.ERROR, obj); } public static ResultJson error() { return new ResultJson(ResultCode.ERROR, null); } public static ResultJson error(String message) { return new ResultJson(ResultCode.ERROR, null, message); }}2、ResultCode

定義4種返回代號和返回信息,使用枚舉類進行實現(xiàn)

package com.hanmh.pojo; import lombok.Data;import lombok.Getter; @Getterpublic enum ResultCode { SUCCESS(200, '請求成功'), ERROR(500, '請求失敗'), NOAUTH(401, '用戶未登錄或者登錄超時'), //操作時 NOPREMISSION(403, '沒有此權(quán)限'); private Integer code; private String message; //枚舉類型的構(gòu)造默認為私有 private ResultCode(Integer code, String message) { this.code = code; this.message = message; }}六、創(chuàng)建基礎(chǔ)pojo

在所有的數(shù)據(jù)庫表種,共有的字段是ID,現(xiàn)在將id獨立出來

1、導(dǎo)入 mybatis-plus-annotation包

為了使用該包內(nèi)部的IdType等類內(nèi)部提供的注解,以告訴BasePojo中某些字段在數(shù)據(jù)庫表中的存在與否

<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-annotation</artifactId> <version>3.0-RELEASE</version></dependency>2、BasePojo類

package com.hanmh.pojo; import com.baomidou.mybatisplus.annotation.IdType;import com.baomidou.mybatisplus.annotation.TableField;import com.baomidou.mybatisplus.annotation.TableId;import lombok.Data;import org.omg.CORBA.IDLType; @Datapublic class BasePojo { @TableId(type = IdType.AUTO) private Integer id; //做分頁操作需要的字段 @TableField(exist = false) private Integer pageNO; @TableField(exist = false) private Integer pageSize;}七、后端添加數(shù)據(jù)1、密碼加密

(1)需要使用安全包提供加密服務(wù)(security)

<dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-core</artifactId></dependency>2、將加密類(BCryptPasswordEncoder)放入IOC容器

在SpringBoot環(huán)節(jié),需要將某個類加入IOC容器,就需要在配置類中,配置@Bean節(jié)點

@Configurationpublic class AdminConfig { @Bean //將BCryptPasswordEncoder放進IOC容器 BCryptPasswordEncoder getPasswordEncoder() { return new BCryptPasswordEncoder(); }}

注:使用此方法對數(shù)據(jù)進行加密的原因:此加密方法相同明文密碼多次可以生成不同的密文,而MD5相同密碼則會生成相同的密文

3、后端添加數(shù)據(jù)簡單實現(xiàn)

@PostMapping('/add')ResultJson add(UmsAdmin umsAdmin) throws InterruptedException, IOException { //對密碼加密 umsAdmin.setPassword(passwordEncoder.encode(umsAdmin.getPassword())); //TimeUnit.SECONDS.sleep(2); return ResultJson.success(adminService.save(umsAdmin), '添加用戶成功');}八、前端頁面添加功能1、添加用戶(按鈕和彈窗)

<el-button>:elementUI按鈕標簽<el-button type='primary' plain @click='add'>添加用戶</el-button><!-- <el-dialog> 代表彈窗 :visible.sync表示顯示或隱藏--><!-- close-on-click-modal代表點擊對話框以外區(qū)域是否可以關(guān)閉 --><el-dialog :title='dialog.title' :visible.sync='dialog.show':close-on-click-modal='false'width='450px'> <AdminEdit :show.sync='dialog.show' v-if='dialog.show'></AdminEdit></el-dialog>

(1)添加用戶功能

add() { this.dialog.show = true this.dialog.title = '添加用戶'}

(2)添加內(nèi)容彈窗

<template> <div> <el-form :model='forms' :rules='rules' ref='ruleForm' label-width='100px'> <el-form-item label='登錄名' prop='loginName'> <el-input v-model='forms.loginName' placeholder='請輸入登錄名'></el-input> </el-form-item> <el-form-item label='昵稱' prop='name'> <el-input v-model='forms.name' placeholder='請輸入昵稱'></el-input> </el-form-item> <el-form-item label='密碼' prop='password'> <el-input v-model='forms.password' placeholder='請輸入密碼' show-password></el-input> </el-form-item> <el-form-item label='郵箱' prop='email'> <el-input v-model='forms.email' placeholder='請輸入郵箱'></el-input> </el-form-item> <el-form-item label='手機號' prop='phone'> <el-input v-model='forms.phone' placeholder='請輸入手機號'></el-input> </el-form-item> <el-form-item label='頭像' prop='imgobj'> </el-form-item> <el-form-item> <el-button size='small' type='primary' plain @click='save'>保存</el-button> </el-form-item> </el-form> </div></template> <script> export default{ name: ’AdminEdit’, props:{ show:{ type: Boolean } }, data(){ return { forms: { loginName: ’’, name: ’’, password: ’’, email: ’’, phone: ’’, imgobj: ’這是一張圖片’ }, rules:{ loginName:[ {required: true, message: ’請輸入登錄名’, trigger: ’blur’}, {min : 1, max: 20, message: ’長度在1-20之間’, trigger: ’change’} ], name:[ {required: true, message: ’請輸入昵稱’, trigger: ’blur’}, {min : 1, max: 20, message: ’長度在1-20之間’, trigger: ’change’} ], password:[ {required: true, message: ’請輸入密碼’, trigger: ’blur’}, {min : 1, max: 100, message: ’長度在1-100之間’, trigger: ’change’} ], email:[ {required: true, message: ’請輸入郵箱’, trigger: ’blur’}, {min : 1, max: 50, message: ’長度在1-50之間’, trigger: ’change’}, {type: ’email’, message: ’請輸入正確格式的郵箱’, trigger: ’blur’} ], phone:[ {required: true, message: ’請輸入電話號’, trigger: ’blur’}, {min : 1, max: 20, message: ’長度在1-20之間’, trigger: ’change’}, {pattern: /^1([38][0-9]|4[5-9]|5[0-3,5-9]|66|7[0-8]|9[89])[0-9]{8}$/, message: ’請輸入正確的手機號’, trigger: ’blur’} ], } } }, methods:{ save() { //提交表單前需要對表單再次進行驗證 //獲取表單對象//表單二次驗證 this.$refs[’ruleForm’].validate((flag) => { //如果通過驗證,則進行表單數(shù)據(jù)提交 if(flag === true) { this.request(’/umsadmin/add’, ’post’, this.forms, response => { this.$message.success(response.message) }) } }) }, changeimg(file, fileList) { this.forms.imgobj = file.raw }, removeimg() { this.forms.imgobj = null } } }</script> <style></style>2、此時前端給后端發(fā)post請求會出現(xiàn)跨域錯誤

跨域錯誤解決需要在后端植入跨域過濾器(Bean節(jié)點)

//跨域問題解決@BeanCorsFilter getCorsFilter() { UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource(); CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.addAllowedHeader('*'); corsConfiguration.addAllowedMethod('*'); corsConfiguration.addAllowedOrigin('*'); //域名 configurationSource.registerCorsConfiguration('/**', corsConfiguration); return new CorsFilter(configurationSource);}

到此這篇關(guān)于SpringBoot+Vue實現(xiàn)數(shù)據(jù)添加功能的文章就介紹到這了,更多相關(guān)SpringBoot Vue數(shù)據(jù)添加內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標簽: Spring
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
免费欧美日韩| 免费看精品久久片| 99久久婷婷| 麻豆成人91精品二区三区| 麻豆91精品| 欧美va亚洲va日韩∨a综合色| 国产欧美一区二区精品久久久| 亚洲高清久久| 国产精品毛片aⅴ一区二区三区| 激情五月综合网| 成人精品高清在线视频| 欧美国产先锋| 欧美日韩亚洲一区二区三区在线| 久久午夜精品| 好吊日精品视频| xxxxx性欧美特大| a国产在线视频| 另类专区亚洲| 国产成人精品福利| 国产精品一区二区三区四区在线观看| 亚洲精品在线国产| 亚洲一区二区三区久久久| 日韩午夜精品| 久久中文字幕av一区二区不卡| 国产一区二区三区久久| av中文资源在线资源免费观看| 麻豆精品av| 成人午夜网址| 国产一区观看| 亚洲一区二区成人| 日本一区二区中文字幕| 日韩av一区二| 国产欧美一区二区精品久久久 | 亚洲在线网站| 伊人成人网在线看| 伊人精品久久| 国产精品中文字幕亚洲欧美| 日韩av网站免费在线| 久久一区精品| 天堂va欧美ⅴa亚洲va一国产| 樱桃视频成人在线观看| 青青国产91久久久久久| 久久免费高清| 9999国产精品| 日本不卡一区二区| 久久一区视频| 欧美日韩黑人| 国产精品一区免费在线| 99视频精品全部免费在线视频| 视频精品一区| av亚洲一区二区三区| 亚洲精品乱码久久久久久蜜桃麻豆 | 久久精品国产福利| 激情六月综合| 欧美综合精品| 国产模特精品视频久久久久| 国产精品sss在线观看av| 在线一区电影| 免费美女久久99| 国产模特精品视频久久久久| 激情综合网址| 国产在线日韩| 久久久精品久久久久久96| 精品国产aⅴ| 国产亚洲精品美女久久| 亚洲精品中文字幕99999| 蜜桃视频一区二区三区| 热久久久久久久| 亚洲综合小说| 日本综合视频| 91麻豆精品| 国产精品二区影院| 久久精品国产成人一区二区三区| 蜜桃91丨九色丨蝌蚪91桃色| 欧美精品激情| 亚洲综合中文| 国产精品99精品一区二区三区∴ | 最新国产精品久久久| 国产美女一区| 欧美精品影院| 欧美偷窥清纯综合图区| 久久精品国产精品亚洲毛片| 精品国产中文字幕第一页| 国产成人精品一区二区三区在线| 日韩成人精品一区| 一区二区小说| 午夜宅男久久久| 久久精品国产久精国产爱| 成人免费电影网址| 蜜桃一区二区三区在线观看| 欧美国产另类| 亚洲激情偷拍| 国产精品红桃| 免费欧美日韩| 精品网站999| 亚洲综合日本| 激情综合婷婷| 亚洲精品乱码| 亚洲黄色免费av| 美国欧美日韩国产在线播放| 国产精品久久观看| 亚洲制服欧美另类| 日韩av首页| 国产精品美女久久久久久不卡| 激情丁香综合| 麻豆一区二区在线| 国精品一区二区| 国产精品一区二区99| 亚洲在线免费| 极品av在线| 国产精品久久国产愉拍| 日韩在线一二三区| 久久91导航| 蜜臀av在线播放一区二区三区| 国产精品v日韩精品v欧美精品网站| 四虎影视精品| 久久成人高清| 视频一区二区国产| 久久在线视频免费观看| 国产在线不卡一区二区三区| 日韩精彩视频在线观看| 国产精品日韩欧美一区| 亚洲午夜天堂| 精品免费在线| 国产欧美在线| 久久精品99久久久| 亚洲一二av| 亚洲一区欧美激情| 福利一区二区三区视频在线观看| 久久精品凹凸全集| 日韩视频一二区| 婷婷综合成人| 中文字幕一区二区三区日韩精品| 99精品在线免费在线观看| 国精品产品一区| jizzjizz中国精品麻豆| 精品国产91| 吉吉日韩欧美| 黑人精品一区| 快播电影网址老女人久久| 成人一区而且| 日韩在线精品| 欧美精品资源| 亚洲精品午夜av福利久久蜜桃| av综合电影网站| 亚洲成人二区| 欧美特黄一区| 亚洲一级大片| 国产精品一区二区三区四区在线观看 | 一区二区亚洲视频| 午夜亚洲福利| 国产欧美日韩影院| 久久不见久久见免费视频7| 欧美欧美黄在线二区| 精品国产欧美日韩| 中文字幕系列一区| 欧美专区在线| 麻豆精品新av中文字幕| 日本免费一区二区三区四区| 欧美黄色网页| 蜜桃视频在线观看一区| 久久国产婷婷国产香蕉| 国产精品片aa在线观看| 国产91在线播放精品| 欧美女激情福利| 国产免费av国片精品草莓男男| 国产乱码午夜在线视频| 国产精品日本欧美一区二区三区| 日韩视频在线一区二区三区 | av免费不卡国产观看| 性欧美69xoxoxoxo| 国产乱码精品一区二区三区四区 | 日韩成人一级| 91青青国产在线观看精品| 亚洲va中文在线播放免费| 国内精品99| 久久亚洲国产精品尤物| 99成人在线视频| 国产精品亚洲片在线播放| 欧美网站在线| 国产高潮在线| 国产极品模特精品一二| 精品欧美久久| av在线最新| 国产精品v亚洲精品v日韩精品| 99国产精品| 美女福利一区二区三区| 国产精品亚洲二区| 在线精品视频一区| 国产一区二区精品久| 亚洲欧洲日韩精品在线| 欧美精品一线| 欧美国产91| 蜜桃成人精品| 国产精品成人a在线观看| 久久wwww| 免费亚洲一区| 麻豆精品久久| 久久久精品区| 精品视频自拍|