当前位置: 首页 > news >正文

外贸网站建设制作wordpress获取分类名称

外贸网站建设制作,wordpress获取分类名称,网站建设板块如何分类,产品摄影文章目录 一、整合流程图1.1 Spring整合Mybatis1.2 Spring整合SpringMVC 二、表现层数据封装2.1 问题引出2.2 统一返回结果数据格式 代码设计 三、异常处理器3.1 概述3.2 异常处理方案 四、前端五、拦截器5.1 概念5.2 入门案例5.3 拦截器参数5.4 拦截器链 一、整合流程图 1.1 S… 文章目录 一、整合流程图1.1 Spring整合Mybatis1.2 Spring整合SpringMVC 二、表现层数据封装2.1 问题引出2.2 统一返回结果数据格式 代码设计 三、异常处理器3.1 概述3.2 异常处理方案 四、前端五、拦截器5.1 概念5.2 入门案例5.3 拦截器参数5.4 拦截器链 一、整合流程图 1.1 Spring整合Mybatis 1.2 Spring整合SpringMVC 二、表现层数据封装 2.1 问题引出 前端人员接收到很多不同数据格式如下图 不便于操作因此前端操作人员需要与后端人员统一数据格式 设计一个统一的数据返回结果类如下 2.2 统一返回结果数据格式 代码设计 Code.java自定义状态码类 package com.itheima.controller;//状态码 public class Code {public static final Integer SAVE_OK 20011;public static final Integer DELETE_OK 20021;public static final Integer UPDATE_OK 20031;public static final Integer GET_OK 20041;public static final Integer SAVE_ERR 20010;public static final Integer DELETE_ERR 20020;public static final Integer UPDATE_ERR 20030;public static final Integer GET_ERR 20040; } Result.java统一数据返回结果类 package com.itheima.controller;public class Result {//描述统一格式中的数据private Object data;//描述统一格式中的编码用于区分操作可以简化配置0或1表示成功失败private Integer code;//描述统一格式中的消息可选属性private String msg;// 提供不同的构造方法public Result() {}public Result(Integer code,Object data) {this.data data;this.code code;}public Result(Integer code, Object data, String msg) {this.data data;this.code code;this.msg msg;}public Object getData() {return data;}public void setData(Object data) {this.data data;}public Integer getCode() {return code;}public void setCode(Integer code) {this.code code;}public String getMsg() {return msg;}public void setMsg(String msg) {this.msg msg;} } BookController.java修改controller类统一返回数据格式 package com.itheima.controller;import com.itheima.domain.Book; import com.itheima.service.BookService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*;import java.util.List;//统一每一个控制器方法返回值 RestController RequestMapping(/books) public class BookController {Autowiredprivate BookService bookService;PostMappingpublic Result save(RequestBody Book book) {boolean flag bookService.save(book);return new Result(flag ? Code.SAVE_OK:Code.SAVE_ERR,flag);}PutMappingpublic Result update(RequestBody Book book) {boolean flag bookService.update(book);return new Result(flag ? Code.UPDATE_OK:Code.UPDATE_ERR,flag);}DeleteMapping(/{id})public Result delete(PathVariable Integer id) {boolean flag bookService.delete(id);return new Result(flag ? Code.DELETE_OK:Code.DELETE_ERR,flag);}GetMapping(/{id})public Result getById(PathVariable Integer id) {Book book bookService.getById(id);Integer code book ! null ? Code.GET_OK : Code.GET_ERR;String msg book ! null ? : 数据查询失败请重试;return new Result(code,book,msg);}GetMappingpublic Result getAll() {ListBook bookList bookService.getAll();Integer code bookList ! null ? Code.GET_OK : Code.GET_ERR;String msg bookList ! null ? : 数据查询失败请重试;return new Result(code,bookList,msg);} } 三、异常处理器 3.1 概述 3.2 异常处理方案 定义异常编码Code.class package com.itheima.controller;//状态码 public class Code {public static final Integer SAVE_OK 20011;public static final Integer DELETE_OK 20021;public static final Integer UPDATE_OK 20031;public static final Integer GET_OK 20041;public static final Integer SAVE_ERR 20010;public static final Integer DELETE_ERR 20020;public static final Integer UPDATE_ERR 20030;public static final Integer GET_ERR 20040;public static final Integer SYSTEM_ERR 50001;public static final Integer SYSTEM_TIMEOUT_ERR 50002;public static final Integer SYSTEM_UNKNOW_ERR 59999;public static final Integer BUSINESS_ERR 60002; } 定义业务异常BusinessException.class package com.itheima.exception; //自定义异常处理器用于封装异常信息对异常进行分类 public class BusinessException extends RuntimeException{private Integer code;public Integer getCode() {return code;}public void setCode(Integer code) {this.code code;}public BusinessException(Integer code, String message) {super(message);this.code code;}public BusinessException(Integer code, String message, Throwable cause) {super(message, cause);this.code code;}} 定义系统异常SystemExceptionException.class package com.itheima.exception;//自定义异常处理器用于封装异常信息对异常进行分类 public class SystemException extends RuntimeException{private Integer code;public Integer getCode() {return code;}public void setCode(Integer code) {this.code code;}// 构造方法public SystemException(Integer code, String message) {super(message);this.code code;}public SystemException(Integer code, String message, Throwable cause) {super(message, cause);this.code code;}} 拦截异常并处理SystemExceptionException.class package com.itheima.controller;import com.itheima.exception.BusinessException; import com.itheima.exception.SystemException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice;//RestControllerAdvice用于标识当前类为REST风格对应的异常处理器 RestControllerAdvice public class ProjectExceptionAdvice {//ExceptionHandler用于设置当前处理器类对应的异常类型ExceptionHandler(SystemException.class)public Result doSystemException(SystemException ex){//记录日志//发送消息给运维//发送邮件给开发人员,ex对象发送给开发人员return new Result(ex.getCode(),null,ex.getMessage());}ExceptionHandler(BusinessException.class)public Result doBusinessException(BusinessException ex){return new Result(ex.getCode(),null,ex.getMessage());}//除了自定义的异常处理器保留对Exception类型的异常处理用于处理非预期的异常ExceptionHandler(Exception.class)public Result doOtherException(Exception ex){//记录日志//发送消息给运维//发送邮件给开发人员,ex对象发送给开发人员return new Result(Code.SYSTEM_UNKNOW_ERR,null,系统繁忙请稍后再试);} } 书写异常 package com.itheima.controller;import com.itheima.domain.Book; import com.itheima.exception.BusinessException; import com.itheima.exception.SystemException; import com.itheima.service.BookService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*;import java.util.List;//统一每一个控制器方法返回值 RestController RequestMapping(/books) public class BookController {Autowiredprivate BookService bookService;GetMapping(/{id})public Result getById(PathVariable Integer id) {if(id 1){throw new BusinessException(Code.BUSINESS_ERR,写错了噢);}try {int i 1 / 0;}catch(Exception e){throw new SystemException(Code.SYSTEM_TIMEOUT_ERR,访问超时);}Book book bookService.getById(id);Integer code book ! null ? Code.GET_OK : Code.GET_ERR;String msg book ! null ? : 数据查询失败请重试;return new Result(code,book,msg);}} 四、前端 编写处理前端路径的配置器SpringMvcSupport.class package com.itheima.config;import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;Configuration public class SpringMvcSupport extends WebMvcConfigurationSupport {Overrideprotected void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler(/pages/**).addResourceLocations(/pages/);registry.addResourceHandler(/css/**).addResourceLocations(/css/);registry.addResourceHandler(/js/**).addResourceLocations(/js/);registry.addResourceHandler(/plugins/**).addResourceLocations(/plugins/);} } 前端代码books.html !DOCTYPE htmlhtmlhead!-- 页面meta --meta charsetutf-8meta http-equivX-UA-Compatible contentIEedgetitleSpringMVC案例/titlemeta contentwidthdevice-width,initial-scale1,maximum-scale1,user-scalableno nameviewport!-- 引入样式 --link relstylesheet href../plugins/elementui/index.csslink relstylesheet href../plugins/font-awesome/css/font-awesome.min.csslink relstylesheet href../css/style.css/headbody classhold-transitiondiv idappdiv classcontent-headerh1图书管理/h1/divdiv classapp-containerdiv classboxdiv classfilter-containerel-input placeholder图书名称 v-modelpagination.queryString stylewidth: 200px; classfilter-item/el-inputel-button clickgetAll() classdalfBut查询/el-buttonel-button typeprimary classbutT clickhandleCreate()新建/el-button/divel-table sizesmall current-row-keyid :datadataList stripe highlight-current-rowel-table-column typeindex aligncenter label序号/el-table-columnel-table-column proptype label图书类别 aligncenter/el-table-columnel-table-column propname label图书名称 aligncenter/el-table-columnel-table-column propdescription label描述 aligncenter/el-table-columnel-table-column label操作 aligncentertemplate slot-scopescopeel-button typeprimary sizemini clickhandleUpdate(scope.row)编辑/el-buttonel-button typedanger sizemini clickhandleDelete(scope.row)删除/el-button/template/el-table-column/el-table!-- 新增标签弹层 --div classadd-formel-dialog title新增图书 :visible.syncdialogFormVisibleel-form refdataAddForm :modelformData :rulesrules label-positionright label-width100pxel-rowel-col :span12el-form-item label图书类别 proptypeel-input v-modelformData.type//el-form-item/el-colel-col :span12el-form-item label图书名称 propnameel-input v-modelformData.name//el-form-item/el-col/el-rowel-rowel-col :span24el-form-item label描述el-input v-modelformData.description typetextarea/el-input/el-form-item/el-col/el-row/el-formdiv slotfooter classdialog-footerel-button clickdialogFormVisible false取消/el-buttonel-button typeprimary clickhandleAdd()确定/el-button/div/el-dialog/div!-- 编辑标签弹层 --div classadd-formel-dialog title编辑检查项 :visible.syncdialogFormVisible4Editel-form refdataEditForm :modelformData :rulesrules label-positionright label-width100pxel-rowel-col :span12el-form-item label图书类别 proptypeel-input v-modelformData.type//el-form-item/el-colel-col :span12el-form-item label图书名称 propnameel-input v-modelformData.name//el-form-item/el-col/el-rowel-rowel-col :span24el-form-item label描述el-input v-modelformData.description typetextarea/el-input/el-form-item/el-col/el-row/el-formdiv slotfooter classdialog-footerel-button clickdialogFormVisible4Edit false取消/el-buttonel-button typeprimary clickhandleEdit()确定/el-button/div/el-dialog/div/div/div/div/body!-- 引入组件库 --script src../js/vue.js/scriptscript src../plugins/elementui/index.js/scriptscript typetext/javascript src../js/jquery.min.js/scriptscript src../js/axios-0.18.0.js/scriptscriptvar vue new Vue({el: #app,data:{pagination: {},dataList: [],//当前页要展示的列表数据formData: {},//表单数据dialogFormVisible: false,//控制表单是否可见dialogFormVisible4Edit:false,//编辑表单是否可见rules: {//校验规则type: [{ required: true, message: 图书类别为必填项, trigger: blur }],name: [{ required: true, message: 图书名称为必填项, trigger: blur }]}},//钩子函数VUE对象初始化完成后自动执行created() {this.getAll();},methods: {//列表getAll() {//发送ajax请求axios.get(/books).then((res){this.dataList res.data.data;});},//弹出添加窗口handleCreate() {this.dialogFormVisible true;this.resetForm();},//重置表单resetForm() {this.formData {};},//添加handleAdd () {//发送ajax请求axios.post(/books,this.formData).then((res){console.log(res.data);//如果操作成功关闭弹层显示数据if(res.data.code 20011){this.dialogFormVisible false;this.$message.success(添加成功);}else if(res.data.code 20010){this.$message.error(添加失败);}else{this.$message.error(res.data.msg);}}).finally((){this.getAll();});},//弹出编辑窗口handleUpdate(row) {// console.log(row); //row.id 查询条件//查询数据根据id查询axios.get(/books/row.id).then((res){// console.log(res.data.data);if(res.data.code 20041){//展示弹层加载数据this.formData res.data.data;this.dialogFormVisible4Edit true;}else{this.$message.error(res.data.msg);}});},//编辑handleEdit() {//发送ajax请求axios.put(/books,this.formData).then((res){//将信息打印在控制台上console.log(res.data)//如果操作成功关闭弹层显示数据if(res.data.code 20031){this.dialogFormVisible4Edit false;this.$message.success(修改成功);}else if(res.data.code 20030){this.$message.error(修改失败);}else{this.$message.error(res.data.msg);}}).finally((){this.getAll();});},// 删除handleDelete(row) {//1.弹出提示框this.$confirm(此操作永久删除当前数据是否继续,提示,{type:info}).then((){//2.做删除业务axios.delete(/books/row.id).then((res){if(res.data.code 20021){this.$message.success(删除成功);}else{this.$message.error(删除失败);}}).finally((){this.getAll();});}).catch((){//3.取消删除this.$message.info(取消删除操作);});}}})/script/html五、拦截器 5.1 概念 拦截器的执行流程 5.2 入门案例 第一步声明拦截器的bean并实现HandlerInterceptor接口拦截器Intercepter一般放在controller业务层包下需要在类前添加Component注解。 当preHandle返回值类型可以拦截控制的执行true放行false终止。 Component //定义拦截器类实现HandlerInterceptor接口 //注意当前类必须受Spring容器控制 public class ProjectInterceptor implements HandlerInterceptor {Override//原始方法调用前执行的内容//返回值类型可以拦截控制的执行true放行false终止public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {String contentType request.getHeader(Content-Type);HandlerMethod hm (HandlerMethod)handler;System.out.println(preHandle...contentType);return true;}Override//原始方法调用后执行的内容public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {System.out.println(postHandle...);}Override//原始方法调用完成后执行的内容public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {System.out.println(afterCompletion...);} }第二步定义配置类继承WebMvcConfigurationSupport实现方法addInterceptors需要在类前添加Configuration注解 Configuration public class SpringMvcSupport extends WebMvcConfigurationSupport {Autowiredprivate ProjectInterceptor projectInterceptor;Overrideprotected void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler(/pages/**).addResourceLocations(/pages/);}Overrideprotected void addInterceptors(InterceptorRegistry registry) {//配置拦截器registry.addInterceptor(projectInterceptor).addPathPatterns(/books,/books/*);} }第三步在SpringMvc的配置类前添加ComponentScan({“com.itheima.controller”,“com.itheima.config”})以便拦截器ProjectInterceptor和配置类SpringMvcSupport被SpringMvc扫描到。 Configuration ComponentScan({com.itheima.controller}) EnableWebMvc public class SpringMvcConfig{ }最后第二、三步可以合在一起简化开发 Configuration ComponentScan({com.itheima.controller,com.itheima.config}) EnableWebMvc //实现WebMvcConfigurer接口可以简化开发但具有一定的侵入性 public class SpringMvcConfig implements WebMvcConfigurer {Autowiredprivate ProjectInterceptor projectInterceptor;Autowiredprivate ProjectInterceptor2 projectInterceptor2;Overridepublic void addInterceptors(InterceptorRegistry registry) {//配置多拦截器registry.addInterceptor(projectInterceptor).addPathPatterns(/books,/books/*);registry.addInterceptor(projectInterceptor2).addPathPatterns(/books,/books/*);} }5.3 拦截器参数 5.4 拦截器链
http://www.pierceye.com/news/149197/

相关文章:

  • 优秀企业网站欣赏网站的备案怎么处理
  • 怎样做古玩网站毕业设计开题报告网站开发
  • 西安网站 建设app注册推广
  • 丹徒网站建设公司代理公司注册价格
  • 网站建站建设网站中国商标商标查询网
  • 机械加工网站平台南京app制作开发公司
  • 用vs2008做网站教程seo推广网址
  • 正规制作网站公司哪家好视觉传达设计专业作品集
  • 做网站多少钱特惠西宁君博s网站网站建设多少钱
  • 建筑模版东莞网站建设技术支持手机网站开发学习
  • 专业网站建设效果显著做设计找参考的设计网站有那些
  • 最新网站建设技术2022年新闻摘抄简短
  • 手机网站总是自动跳转最吃香的男生十大手艺
  • 免费网站推广软件哪个好企业vi设计公司价格
  • 自助建网站不需要域名番禺网站优化平台
  • 一般建设网站的常见问题国家企业信用信息公示官网
  • 韩国美容网站 模板互联网大赛官网入口
  • 太原网站开发哪家好wordpress怎么贴代码
  • 深圳网站设计与制作网站建设公司海南
  • 做网站需要什么cailiao网站项目申报书建设规模
  • wordpress手机网站模板wordpress分类设置seo
  • 哪个网站设计好互助网站制作公司
  • 网站建设评估报告惠民建设局网站
  • 网站后台上传模板aspnet网站开发实例论文
  • 顺德公司做网站网站美工和网页设计的区别
  • 江苏建设造价信息网站山东丽天建设集团网站
  • 兰州网站建设程序wordpress自动超链接
  • zencart网站模板下载怎么自己建立网站及建立网站方法
  • 孝感市门户网站各大网站怎么把世界杯做头条
  • 手机端网站开发视频教程怎么制作爆米花教程