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

阿里巴巴新网站怎么做运营爱站网长尾关键词挖掘工具福利片

阿里巴巴新网站怎么做运营,爱站网长尾关键词挖掘工具福利片,wordpress上传文件类型,成品网站管系统目录 完善登录功能 注册接口参数校验 完善分页查询 完善日期格式 更新文章分类和添加文章分类的分组校验 ​编辑 自定义校验 文件上传 完善登录功能 对前端传过来的明文密码进行md5加密处理 password DigestUtils.md5DigestAsHex(password.getBytes()); 这样既可 注…

目录

完善登录功能

注册接口参数校验

完善分页查询

完善日期格式

更新文章分类和添加文章分类的分组校验

​编辑

自定义校验 

文件上传 



完善登录功能

对前端传过来的明文密码进行md5加密处理

  password = DigestUtils.md5DigestAsHex(password.getBytes());

 这样既可

注册接口参数校验

Spring Validation

Spring 提供的一个参数校验框架,使用预定义的注解完成参数校验

使用Spring Validation,对注册接口的参数进行合法性校验

引入Spring Validation 起步依赖

在参数前面添加@Pattern注解

在Controller类上添加@Validated注解

完善分页查询

pom.xml:

<dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId></dependency>

mapper:动态sql

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sky.mapper.EmployeeMapper"><select id="pageQuery" resultType="com.sky.entity.Employee">select * from employee<where><if test="name!=null and name!=''">and name like concat('%',#{name},'%')</if></where>order by create_time desc</select>
</mapper>

 service:

完善日期格式

解决方式:
方式一:在属性上加入注解,对日期进行格式化

@JsonFormat(pattern ="yyyy-MM-dd HH:mm:ss")private LocalDateTime updateTime;

方式二:在 WebMvcConfiguration 中扩展Spring MVC的消息转换器,统一对日期类型进行格式化处理

//扩展springMvc框架的消息转化器protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {log.info("扩展消息转化器..");//创建一个消息转化器对象MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();//需要为消息转化器设置一个对象转化器,对象转化器可以将java对象序列化为json数据converter.setObjectMapper(new JacksonObjectMapper());//将自己的消息转化器加入容器中converters.add(0,converter);}

 

更新文章分类和添加文章分类的分组校验

添加文章中没有传id参数 

更新文章分类中传了id参数 

这样运行起来就会报错

 可以这样👇

package com.yjj.bigevent.Pojo;import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.groups.Default;
import lombok.Data;import java.time.LocalDateTime;@Data
public class Category {@NotNull(groups = Update.class)private Integer id;//主键ID@NotEmptyprivate String categoryName;//分类名称@NotEmptyprivate String categoryAlias;//分类别名private Integer createUser;//创建人ID@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")private LocalDateTime createTime;//创建时间@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")private LocalDateTime updateTime;//更新时间//如果说某个校验项没有指定分组,默认属于Default分组// 分组之间可以继承,A extends B那么A中拥有B中所有的校验项public interface Add extends Default {}public interface Update extends Default{}
}

就不会报错了

自定义校验 

自定义注解State

package com.yjj.bigevent.Anno;import com.yjj.bigevent.Validation.StateValidation;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;@Target({ FIELD})//元注解
@Retention(RUNTIME)//元注解
@Documented//元注解
@Constraint(validatedBy = { StateValidation.class})//指定提供校验规则的类
public @interface State {//提供校验失败后的提示信息String message() default "state参数的值只能是已发布或者草稿";//指定分组Class<?>[] groups() default { };//负载获取到State注解的附加信息Class<? extends Payload>[] payload() default { };
}

自定义校验数据的类StateValidation实现ConstraintValidator接口

package com.yjj.bigevent.Validation;import com.yjj.bigevent.Anno.State;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;public class StateValidation implements ConstraintValidator<State,String> {//@param value 将来要校验的数据//@param context context in which the constraint is evaluated//@return 如果返回false,则校验不通过,如果返回true,则校验通过@Overridepublic boolean isValid(String value, ConstraintValidatorContext context) {//提供校验规则if (value==null) {return false;}if (value.equals("已发布")||value.equals("草稿")){return true;}return false;}
}

在需要校验的地方使用自定义注解 

测试

文件上传 

导入阿里云的依赖坐标

pom.xml 

<dependency><groupId>com.aliyun.oss</groupId><artifactId>aliyun-sdk-oss</artifactId><version>3.17.4</version>
</dependency>

如果使用的是Java 9及以上的版本,则需要添加JAXB相关依赖。添加JAXB相关依赖示例代码如下:

<dependency><groupId>javax.xml.bind</groupId><artifactId>jaxb-api</artifactId><version>2.3.1</version>
</dependency>
<dependency><groupId>javax.activation</groupId><artifactId>activation</artifactId><version>1.1.1</version>
</dependency>
<!-- no more than 2.3.3-->
<dependency><groupId>org.glassfish.jaxb</groupId><artifactId>jaxb-runtime</artifactId><version>2.3.3</version>
</dependency>

工具类: 

package com.yjj.bigEvent.Utils;import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;import java.io.InputStream;public class AliOssUtil {private static final String ENDPOINT = "https://加上访问端口(https://oss-cn-hangzhou.aliyuncs.com)";private static final String ACCESS_KEY_ID = "ACCESS的id";private static final String SECRET_ACCESS_KEY = "ACCESS的secret";private static final String BUCKET_NAME = "自己的bucket名字";//上传文件,返回文件的公网访问地址public static String uploadFile(String objectName, InputStream inputStream){// 创建OSSClient实例。OSS ossClient = new OSSClientBuilder().build(ENDPOINT,ACCESS_KEY_ID,SECRET_ACCESS_KEY);//公文访问地址String url = "";try {// 创建存储空间。ossClient.createBucket(BUCKET_NAME);ossClient.putObject(BUCKET_NAME, objectName, inputStream);url = "https://"+BUCKET_NAME+"."+ENDPOINT.substring(ENDPOINT.lastIndexOf("/")+1)+"/"+objectName;} catch (OSSException oe) {System.out.println("Caught an OSSException, which means your request made it to OSS, "+ "but was rejected with an error response for some reason.");System.out.println("Error Message:" + oe.getErrorMessage());System.out.println("Error Code:" + oe.getErrorCode());System.out.println("Request ID:" + oe.getRequestId());System.out.println("Host ID:" + oe.getHostId());} catch (ClientException ce) {System.out.println("Caught an ClientException, which means the client encountered "+ "a serious internal problem while trying to communicate with OSS, "+ "such as not being able to access the network.");System.out.println("Error Message:" + ce.getMessage());} finally {if (ossClient != null) {ossClient.shutdown();}}return url;}
}

http://www.bjxfkj.com.cn/article/108736.html

相关文章:

  • 如何做好网站建设内容的策划重庆市住房和城乡建设厅官方网站
  • 下载网站的软件wordpress最新发布模块
  • 网站建设 东方网景廊坊百度网站排名
  • 长春专业做网站的公司排名wordpress运行
  • 平面广告作品分析昆明seo网站排名优化
  • 网站平台建设工作汇报伊春网络运营推广
  • 定制开发 商城网站 最快天翼云wordpress插件
  • 电子商务公司网站设计凡客科技
  • 流程网站广东队对阵广州队
  • 网站的页面布局福建省文明建设办公室网站
  • 生物科技企业网站做的比较好的免费建设手机网站
  • 做地方的门户网站wordprees可以做棋类网站吗
  • 做响应式网站的常用尺寸园区网络建设方案
  • 全屏式网站花店网页制作素材
  • 来年做那个网站能致富网站支付功能建设
  • 济南市莱芜区网站应用市场华为
  • 做电影网站涉及的侵权问题重庆网站推广运营
  • 网站前端设计与实现设计本接单大厅
  • 沈阳营销网站建设做电销要在哪个网站上找资源
  • 网站开发人员 怎么保存中国seo排行榜
  • 好的销售网站广东平台网站建设平台
  • 网站建设公司网站模版德宏企业网站建设公司
  • 宁波网站推广制作公司知识库搭建工具
  • 网站前后台模板php 企业网站 后台图片上传
  • 制作一个购物网站需要多少钱莱芜金点子招聘信息电子版
  • 网站建设的方法有哪些方面如何将自己 做的网站发布网上
  • 网站搭建dns有用吗wordpress两个菜单栏
  • 网站备案去哪做官网设计好的公司
  • 微网站管理平台淘宝客如何做淘宝客网站推广
  • 湖南seo网站多少钱山西建设厅报名网站