版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
XXIV参考文献[1]张孝祥、徐明华,JAVA基础与案例开发详解[M],清华大学出版社,2009.[2]康牧,JSP动态网站开发实用教程[M],清华大学出版社,2009.[3]刘亚宾,精通Eclipse--JAVA技术大系[M],电子工业出版社,2005.[4]王玉英.基于JSP的MySQL数据库访问技术[J].现代计算机:专业版,2010,19(14):63-66[5]赵钢.JSPServlet+EJB的Web模式应用研究[J].电子设计工程,2013,21(13):47-49[6]肖英.解决JSP/Servlet开发中的中文乱码问题[J].科技传播,2011,(1)11-25[7]HsiaoIH,SosnovskyS,BrusilovskyP.Guidingstudentstotherightquestions:adaptivenavigationsupportinane-learningsystemforJavaprogramming[J].JournalofComputerAssistedLearning,2010,26(4):270-283.[8]VeghA.MySQLDatabaseServer[M].WebDevelopmentwiththeMac®.WileyPublishing,Inc.,2011,179-194[9]RasoolzadeganA,BarforoushAA.Reliableyetflexiblesoftwarethroughformalmodeltransformation(ruledefinition)[J].Knowledge&InformationSystems,2014,40(1):79-126[10]WürthingerT,WimmerC,StadlerL.DynamiccodeevolutionforJava.[J].ProceedingsofInternationalConferenceonthePrinciples&PracticeofProgramminginJavaPppj’,2010,78(5):10—19[11]黄艳峰.在Java语言中实施“案例教学”的研究与探索[J].电脑知识与技术,2010,6(5):1148-1149[12]赵钢.JSPServlet+EJB的Web模式应用研究[J].电子设计工程,2013,21(13):47-49附录1.用户注册代码为:/** *注册 */ @IgnoreAuth @PostMapping(value="/register") publicRregister(@RequestBodyUserEntityuser){// ValidatorUtils.validateEntity(user); if(userService.selectOne(newEntityWrapper<UserEntity>().eq("username",user.getUsername()))!=null){ returnR.error("用户已存在"); }userService.insert(user);returnR.ok();}2.算法加解密代码如下所示。/***公钥生成*/publicstaticPublicKeygetPublicKey(Stringkey){X509EncodedKeySpecx509EncodedKeySpec=newX509EncodedKeySpec(Base64.decodeBase64(key));try{KeyFactoryfactory=KeyFactory.getInstance("RSA");PublicKeypublicKey=factory.generatePublic(x509EncodedKeySpec);returnpublicKey;}catch(NoSuchAlgorithmException|InvalidKeySpecExceptione){e.printStackTrace();}returnnull;}/***私钥生成*/publicstaticPrivateKeygetPrivateKey(Stringkey){PKCS8EncodedKeySpecpkcs8EncodedKeySpec=newPKCS8EncodedKeySpec(Base64.decodeBase64(key));try{KeyFactoryfactory=KeyFactory.getInstance("RSA");PrivateKeyprivateKey=factory.generatePrivate(pkcs8EncodedKeySpec);returnprivateKey;}catch(NoSuchAlgorithmException|InvalidKeySpecExceptione){e.printStackTrace();}returnnull;}/***利用公钥加密信息*/publicstaticStringencode(PublicKeykey,Stringmessage)throwsException{Ciphercipher=Cipher.getInstance("RSA");cipher.init(Cipher.ENCRYPT_MODE,key);returnBase64.encodeBase64String(cipher.doFinal(message.getBytes("UTF-8")));}/***利用私钥解密信息*/publicstaticStringdecode(PrivateKeykey,Stringmessage)throwsException{Ciphercipher=Cipher.getInstance("RSA");cipher.init(Cipher.DECRYPT_MODE,key);returnnewString(cipher.doFinal(Base64.decodeBase64(message.getBytes("UTF-8"))));} 3.异常信息枚举类代码如下,publicenumExceptionCodeEnum{//请求参数异常3000-3999REQUEST_PARAMETER_EMPTY(3001,"请求参数为空!"),REQUEST_PARAMETER_INVALID(3002,"请求参数无效!"),REQUEST_PARAMETER_ILLEGAL(3003,"请求参数不合法!"),//后面可以追加其他请求参数异常//用户异常4000-4999USER_DOES_NOT_EXIST(4001,"用户不存在!"),USER_ID_EMPTY(4002,"用户id为空!"),USER_DOES_NOT_PERMISSION(4003,"用户无权限!"),//后面可以追加其他用户异常//服务器异常5000-5999SERVICE_RESPONSE_TIMEOUT(5001,"服务响应超时!"),DATABASE_OPERATION_FAILED(5002,"数据库操作失败!");//后面可以追加其他服务器异常privateIntegercode;privateStringmessage;ExceptionCodeEnum(Integercode,Stringmessage){this.code=code;this.message=message;}publicIntegergetCode(){returncode;}publicStringgetMessage(){returnmessage;}}每种异常发生时会经过全局异常拦截器GlobalExceptionHandler进行拦截,然后进行特殊处理,GlobalExceptionHandler代码如下,@Slf4j@RestControllerAdvicepublicclassGlobalExceptionHandler{@AutowiredprivateHttpServletRequestrequest;//拦截请求异常@ExceptionHandler(value=RequestException.class)publicResponseUtilhandleRequestException(RequestExceptione){Stringuri=request.getRequestURI();//记录日志log.error("请求异常!请求地址为:{},错误信息为:{}",uri,e.getMessage());//特殊处理逻辑requestHanlder();returnResponseUtil.errorResult(e.getCode(),e.getMessage());}//拦截用户异常@ExceptionHandler(value=UserException.class)publicResponseUtilhandleRequestException(UserExceptione){Stringuri=request.getRequestURI();//记录日志log.error("用户异常!请求地址为:{},错误信息为:{}",uri,e.getMessage());//特殊处理逻辑userHanlder();returnResponseUtil.errorResult(e.getCode(),e.getMessage());}//拦截系统异常@ExceptionHandler(value=SystemException.class)publicResponseUtilhandleRequestException(SystemExceptione){Stringuri=request.getRequestURI();//记录日志log.error("系统异常!请求地址为:{},错误信息为:{}",uri,e.getMessage());//特殊处理逻辑systemHanlder();returnResponseUtil.errorResult(e.getCode(),e.getMessage());}//后面可以加其他异常的特殊处理逻辑}4.用户登录代码为: /** *登录 */ @IgnoreAuth @PostMapping(value="/login") publicRlogin(Stringusername,Stringpassword,Stringcaptcha,HttpServletRequestrequest){ UserEntityuser=userService.selectOne(newEntityWrapper<UserEntity>().eq("username",username)); if(user==null||!user.getPassword().equals(password)){ returnR.error("账号或密码不正确"); } Stringtoken=tokenService.generateToken(user.getId(),username,"users",user.getRole()); returnR.ok().put("token",token); }5.密码修改代码为:/***密码重置*/@IgnoreAuth @RequestMapping(value="/resetPass")publicRresetPass(Stringusername,HttpServletRequestrequest){ UserEntityuser=userService.selectOne(newEntityWrapper<UserEntity>().eq("username",username)); if(user==null){ returnR.error("账号不存在"); } user.setPassword("123456");userService.update(user,null);returnR.ok("密码已重置为:123456");}6.用户管理代码为:/***保存*/@PostMapping("/save")publicRsave(@RequestBodyUserEntityuser){// ValidatorUtils.validateEntity(user); if(userService.selectOne(newEntityWrapper<UserEntity>().eq("username",user.getUsername()))!=null){ returnR.error("用户已存在"); }userService.insert(user);returnR.ok();}/***修改*/@RequestMapping("/update")publicRupdate(@RequestBodyUserEntityuser){//ValidatorUtils.validateEntity(user); UserEntityu=userService.selectOne(newEntityWrapper<UserEntity>().eq("username",user.getUsername())); if(u!=null&&u.getId()!=user.getId()&&u.getUsername().equals(user.getUsername())){ returnR.error("用户名已存在。"); }userService.updateById(user);//全部更新returnR.ok();}/***删除*/@RequestMapping("/delete")publicRdelete(@RequestBodyLong[]ids){userService.deleteBatchIds(Arrays.asList(ids));returnR.ok();}7.车辆管理代码为: /***查询*/@RequestMapping("/query")publicRquery(QicheleixingEntityqicheleixing){EntityWrapper<QicheleixingEntity>ew=newEntityWrapper<QicheleixingEntity>(); ew.allEq(MPUtil.allEQMapPre(qicheleixing,"qicheleixing")); QicheleixingViewqicheleixingView=qicheleixingService.selectView(ew); returnR.ok("查询汽车类型成功").put("d
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 1.2.1 人的社会化 课件(共27张)
- 全国交通安全日中小学交通安全教育课件(图文并茂)
- 【2026年秋季学期】小学低年级德育工作经验总结课件-校园文化建设
- 江苏省扬州市江都区2025~2026学年度第二学期期中检测试题高二物理试卷(含答案)
- 2026年食物变质测试题及答案
- 2026年相似章末测试题及答案
- 2026年外轮理货业务测试题及答案
- 学前教育学试题及答案
- 2026年天才智力测试题及答案
- 2026年恶搞他人测试题及答案
- 督查专员管理办法
- 重症病人常见症状护理
- 股骨的解剖知识
- 国庆节学生们拔河活动方案
- 2024年辽宁省生态环境监测专业技术人员大比武理论试题库(含答案)
- 统编版语文七年级下册第六单元课外古诗词诵读《贾生》公开课一等奖创新教学设计
- AQ 2001-2018 炼钢安全规程(正式版)
- 质量管理工具在临床护理中的应用
- ROHS内部审核检查表
- GB/T 8243.12-2021内燃机全流式机油滤清器试验方法第12部分:颗粒计数法滤清效率和容灰量
- 课件twincat ptp实用教程
评论
0/150
提交评论