【hibernate validator】(二)声明和验证Bean约束
首发博客地址
https://blog.zysicyj.top/
一、声明bean约束
1. 字段级别约束
-
不支持静态类型字段 -
验证引擎直接访问实例变量,不会调用属性的访问器 -
在验证字节码增强的对象时,应适用属性级别约束,因为字节码增库无法通过反射确定字段访问
package org.hibernate.validator.referenceguide.chapter02.fieldlevel;
public class Car {
@NotNull
private String manufacturer;
@AssertTrue
private boolean isRegistered;
public Car(String manufacturer, boolean isRegistered) {
this.manufacturer = manufacturer;
this.isRegistered = isRegistered;
}
//getters and setters...
}
2. 属性级别约束
-
必须注释getter而不是setter,这样可以限制没有设置方法的只读属性 -
该级别将使用属性访问策略来访问验证的值,即验证引擎通过属性访问器来访问数据 -
不要字段和getter都加校验,这样会导致校验两次
package org.hibernate.validator.referenceguide.chapter02.propertylevel;
public class Car {
private String manufacturer;
private boolean isRegistered;
public Car(String manufacturer, boolean isRegistered) {
this.manufacturer = manufacturer;
this.isRegistered = isRegistered;
}
@NotNull
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
@AssertTrue
public boolean isRegistered() {
return isRegistered;
}
public void setRegistered(boolean isRegistered) {
this.isRegistered = isRegistered;
}
}
-
容器元素约束
3.1 Iterable
在该类型上加约束时,将会校验每个元素
package org.hibernate.validator.referenceguide.chapter02.containerelement.set;
import java.util.HashSet;
import java.util.Set;
public class Car {
private Set<@ValidPart String> parts = new HashSet<>();
public void addPart(String part) {
parts.add( part );
}
//...
}
Car car = new Car();
car.addPart( "Wheel" );
car.addPart( null );
Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
assertEquals( 1, constraintViolations.size() );
ConstraintViolation<Car> constraintViolation =
constraintViolations.iterator().next();
assertEquals(
"'null' is not a valid car part.",
constraintViolation.getMessage()
);
assertEquals( "parts[].<iterable element>",
constraintViolation.getPropertyPath().toString() );
3.2 List
也会校验每个元素
package org.hibernate.validator.referenceguide.chapter02.containerelement.list;
public class Car {
private List<@ValidPart String> parts = new ArrayList<>();
public void addPart(String part) {
parts.add( part );
}
//...
}
Car car = new Car();
car.addPart( "Wheel" );
car.addPart( null );
Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
assertEquals( 1, constraintViolations.size() );
ConstraintViolation<Car> constraintViolation =
constraintViolations.iterator().next();
assertEquals(
"'null' is not a valid car part.",
constraintViolation.getMessage()
);
assertEquals( "parts[1].<list element>",
constraintViolation.getPropertyPath().toString() );
3.3 Map
package org.hibernate.validator.referenceguide.chapter02.containerelement.map;
import java.util.HashMap;
import java.util.Map;
import javax.validation.constraints.NotNull;
public class Car {
public enum FuelConsumption {
CITY,
HIGHWAY
}
private Map<@NotNull FuelConsumption, @MaxAllowedFuelConsumption Integer> fuelConsumption = new HashMap<>();
public void setFuelConsumption(FuelConsumption consumption, int value) {
fuelConsumption.put( consumption, value );
}
//...
}
Car car = new Car();
car.setFuelConsumption( Car.FuelConsumption.HIGHWAY, 20 );
Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
assertEquals( 1, constraintViolations.size() );
ConstraintViolation<Car> constraintViolation =
constraintViolations.iterator().next();
assertEquals(
"20 is outside the max fuel consumption.",
constraintViolation.getMessage()
);
assertEquals(
"fuelConsumption[HIGHWAY].<map value>",
constraintViolation.getPropertyPath().toString()
);
Car car = new Car();
car.setFuelConsumption( null, 5 );
Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
assertEquals( 1, constraintViolations.size() );
ConstraintViolation<Car> constraintViolation =
constraintViolations.iterator().next();
assertEquals(
"must not be null",
constraintViolation.getMessage()
);
assertEquals(
"fuelConsumption<K>[].<map key>",
constraintViolation.getPropertyPath().toString()
);
3.4 Optional
package org.hibernate.validator.referenceguide.chapter02.containerelement.optional;
public class Car {
private Optional<@MinTowingCapacity(1000) Integer> towingCapacity = Optional.empty();
public void setTowingCapacity(Integer alias) {
towingCapacity = Optional.of( alias );
}
//...
}
Car car = new Car();
car.setTowingCapacity( 100 );
Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
assertEquals( 1, constraintViolations.size() );
ConstraintViolation<Car> constraintViolation = constraintViolations.iterator().next();
assertEquals(
"Not enough towing capacity.",
constraintViolation.getMessage()
);
assertEquals(
"towingCapacity",
constraintViolation.getPropertyPath().toString()
);
3.5 自定义容器
package org.hibernate.validator.referenceguide.chapter02.containerelement.custom;
public class Car {
private GearBox<@MinTorque(100) Gear> gearBox;
public void setGearBox(GearBox<Gear> gearBox) {
this.gearBox = gearBox;
}
//...
}
package org.hibernate.validator.referenceguide.chapter02.containerelement.custom;
public class GearBox<T extends Gear> {
private final T gear;
public GearBox(T gear) {
this.gear = gear;
}
public Gear getGear() {
return this.gear;
}
}
package org.hibernate.validator.referenceguide.chapter02.containerelement.custom;
public class Gear {
private final Integer torque;
public Gear(Integer torque) {
this.torque = torque;
}
public Integer getTorque() {
return torque;
}
public static class AcmeGear extends Gear {
public AcmeGear() {
super( 60 );
}
}
}
package org.hibernate.validator.referenceguide.chapter02.containerelement.custom;
public class GearBoxValueExtractor implements ValueExtractor<GearBox<@ExtractedValue ?>> {
@Override
public void extractValues(GearBox<@ExtractedValue ?> originalValue, ValueExtractor.ValueReceiver receiver) {
receiver.value( null, originalValue.getGear() );
}
}
Car car = new Car();
car.setGearBox( new GearBox<>( new Gear.AcmeGear() ) );
Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
assertEquals( 1, constraintViolations.size() );
ConstraintViolation<Car> constraintViolation =
constraintViolations.iterator().next();
assertEquals(
"Gear is not providing enough torque.",
constraintViolation.getMessage()
);
assertEquals(
"gearBox",
constraintViolation.getPropertyPath().toString()
);
3.6 嵌套容器元素
package org.hibernate.validator.referenceguide.chapter02.containerelement.nested;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotNull;
public class Car {
private Map<@NotNull Part, List<@NotNull Manufacturer>> partManufacturers =
new HashMap<>();
//...
}
4. 类级别约束
-
在这种情况下,验证的对象不是单个属性而是完整的对象 -
适合依赖于对象的多个属性之间的相关性很高的场景
package org.hibernate.validator.referenceguide.chapter02.classlevel;
@ValidPassengerCount
public class Car {
private int seatCount;
private List<Person> passengers;
//...
}
5. 约束继承
在一个类实现接口或扩展另一个类时,在超类上声明的所有约束注释都以与该类本身上指定的约束相同的方式约束
package org.hibernate.validator.referenceguide.chapter02.inheritance;
public class Car {
private String manufacturer;
@NotNull
public String getManufacturer() {
return manufacturer;
}
//...
}
package org.hibernate.validator.referenceguide.chapter02.inheritance;
public class RentalCar extends Car {
private String rentalStation;
@NotNull
public String getRentalStation() {
return rentalStation;
}
//...
}
-
RentalCar 不仅会校验getRentalStation,而且会校验父类的getManufacturer -
若继承换成接口,也是会校验超类的
6. 对象图
不仅支持单个对象校验,还支持级联验证
对象的级联校验
package org.hibernate.validator.referenceguide.chapter02.objectgraph;
public class Car {
@NotNull
@Valid
private Person driver;
//...
}
package org.hibernate.validator.referenceguide.chapter02.objectgraph;
public class Person {
@NotNull
private String name;
//...
}
在校验Car的时候,会校验Person,因此若Car引用的Person的name为空,则会校验失败
容器的级联校验
package org.hibernate.validator.referenceguide.chapter02.objectgraph.containerelement;
public class Car {
private List<@NotNull @Valid Person> passengers = new ArrayList<Person>();
private Map<@Valid Part, List<@Valid Manufacturer>> partManufacturers = new HashMap<>();
//...
}
package org.hibernate.validator.referenceguide.chapter02.objectgraph.containerelement;
public class Part {
@NotNull
private String name;
//...
}
package org.hibernate.validator.referenceguide.chapter02.objectgraph.containerelement;
public class Manufacturer {
@NotNull
private String name;
//...
}
-
校验Person的名字是否存在为null的 -
校验Part的名字是否存在为null的 -
校验所有的Manufacturer是否存在名字为null的
二、验证Bean约束
1. 获取验证器
2. 验证的三种方式
先来个车
class Car {
@NotNull
@Size(min = 5,max = 20)
private String manufacturer;
@AssertTrue
private boolean isRegistered;
public Car(String manufacturer, boolean isRegistered) {
this.manufacturer = manufacturer;
this.isRegistered = isRegistered;
}
}
bean全部验证
验证单个属性
对属性的值进行验证
3. 约束违规
「内插的错误消息」
09:35:00.446 [main] INFO com.bm.validate.TestValidatorBean - 内插的错误消息:只能为true
非插补的错误消息
09:35:00.446 [main] INFO com.bm.validate.TestValidatorBean - 非插补的错误消息:{javax.validation.constraints.AssertTrue.message}
正在验证的根Bean
09:35:00.446 [main] INFO com.bm.validate.TestValidatorBean - 正在验证的根Bean:com.bm.validate.Car@7c83dc97
如果是bean约束,则将约束应用到bean实例;如果是属性约束,则是托管该约束的属性的bean实例
09:35:00.446 [main] INFO com.bm.validate.TestValidatorBean - 如果是bean约束,则将约束应用到bean实例;如果是属性约束,则是托管该约束的属性的bean实例:com.bm.validate.Car@7c83dc97
「bean验证器值的属性路径」
09:35:00.447 [main] INFO com.bm.validate.TestValidatorBean - 根bean验证器值的属性路径:isRegistered
**「报告约束失败的原数据」
09:35:00.447 [main] INFO com.bm.validate.TestValidatorBean - 报告约束失败的原数据:false
「告约束失败的元数据」
09:35:00.447 [main] INFO com.bm.validate.TestValidatorBean - 报告约束失败的元数据:ConstraintDescriptorImpl{annotation=j.v.c.AssertTrue, payloads=[], hasComposingConstraints=true, isReportAsSingleInvalidConstraint=false, elementType=FIELD, definedOn=DEFINED_LOCALLY, groups=[interface javax.validation.groups.Default], attributes={groups=[Ljava.lang.Class;@60015ef5, message={javax.validation.constraints.AssertTrue.message}, payload=[Ljava.lang.Class;@2f54a33d}, constraintType=GENERIC, valueUnwrapping=DEFAULT}
三、内置约束
@AssertFalse
检查带注释元素的属性为false
-
Boolean, boolean
@AssertTrue
检查带注释元素的属性为True
-
Boolean,boolean
@DecimalMax(value=, inclusive=)
-
inclusive为false,检查带注释的值是否小于指定的最大值。否则,该值是否小于等于指定的最大值 -
BigDecimal,BigInteger,CharSequence,byte,short,int,long,原始数据包装类,Number,javax.money.MonetaryAmount任意子类
@DecimalMin(value=, inclusive=)
-
inclusive为false,检查带注释的值是否大于指定的最小值。否则,该值是否大于等于指定的最小值 -
BigDecimal,BigInteger,CharSequence,byte,short,int,long,原始数据包装类,Number,javax.money.MonetaryAmount任意子类
@Digits(integer=, fraction=)
-
integer 指定整数位数限制,fraction指定小数位数限制 -
BigDecimal,BigInteger,CharSequence,byte,short,int,long,原始数据包装类,Number,javax.money.MonetaryAmount任意子类
-
是否为有效的电子邮箱地址 -
regexp和flags参数指定正则规则,必须匹配的其它表达式 -
CharSequence
@Future
-
检查是否是将来的日期 -
java.util.Date,java.util.Calendar,java.time.Instant,java.time.LocalDate,java.time.LocalDateTime,java.time.LocalTime,java.time.MonthDay,java.time.OffsetDateTime,java.time.OffsetTime,java.time.Year,java.time.YearMonth,java.time.ZonedDateTime,java.time.chrono.HijrahDate,java.time.chrono.JapaneseDate,java.time.chrono.MinguoDate,java.time.chrono.ThaiBuddhistDate; 如果类路径上有Joda Time日期/时间API ,则由HV额外支持:ReadablePartial和的任何实现ReadableInstant
@FutureOnPresent
-
检查日期是先在还是将来 -
java.util.Date,java.util.Calendar,java.time.Instant,java.time.LocalDate,java.time.LocalDateTime,java.time.LocalTime,java.time.MonthDay,java.time.OffsetDateTime,java.time.OffsetTime,java.time.Year,java.time.YearMonth,java.time.ZonedDateTime,java.time.chrono.HijrahDate,java.time.chrono.JapaneseDate,java.time.chrono.MinguoDate,java.time.chrono.ThaiBuddhistDate; 如果类路径上有Joda Time日期/时间API ,则由HV额外支持:ReadablePartial和的任何实现ReadableInstant
@Max(value=)
-
是否小于或等于该值 -
BigDecimal,BigInteger,byte,short,int,long和原始类型的相应的包装; HV额外支持:的任何子类型CharSequence(评估字符序列表示的数值),Number和的任何子类型javax.money.MonetaryAmount
@Min(value=)
-
是否大于或等于该值 -
BigDecimal,BigInteger,byte,short,int,long和原始类型的相应的包装; HV额外支持:的任何子类型CharSequence(评估字符序列表示的数值),Number和的任何子类型javax.money.MonetaryAmount
@NotBlank
-
指定字符不为null并且长度大于0 -
CharSequence
@NotEmpty
-
指定字符不为null或为空(去除尾随空格) -
CharSequence,Collection,Map和数组
@NotNull
-
检查注释的值不为null -
所有类型均支持
@Negative
-
检查元素是否严格为负,零被视为无效 -
BigDecimal,BigInteger,byte,short,int,long和原始类型的相应的包装; HV额外支持:的任何子类型CharSequence(评估字符序列表示的数值),Number和的任何子类型javax.money.MonetaryAmount
@NegativeOrZero
-
检查元素是负数或0 -
BigDecimal,BigInteger,byte,short,int,long和原始类型的相应的包装; HV额外支持:的任何子类型CharSequence(评估字符序列表示的数值),Number和的任何子类型javax.money.MonetaryAmount
@Null
-
检查注释的值是null -
所有类型均支持
@Past
-
检查带注释的日期是否是过去的日期 -
java.util.Date,java.util.Calendar,java.time.Instant,java.time.LocalDate,java.time.LocalDateTime,java.time.LocalTime,java.time.MonthDay,java.time.OffsetDateTime,java.time.OffsetTime,java.time.Year,java.time.YearMonth,java.time.ZonedDateTime,java.time.chrono.HijrahDate,java.time.chrono.JapaneseDate,java.time.chrono.MinguoDate,java.time.chrono.ThaiBuddhistDate; 如果类路径上有Joda Time日期/时间API ,则由HV附加支持:ReadablePartial和的任何实现ReadableInstant
@PastOrPresent
-
检查带注释的日期是过去还是现在 -
java.util.Date,java.util.Calendar,java.time.Instant,java.time.LocalDate,java.time.LocalDateTime,java.time.LocalTime,java.time.MonthDay,java.time.OffsetDateTime,java.time.OffsetTime,java.time.Year,java.time.YearMonth,java.time.ZonedDateTime,java.time.chrono.HijrahDate,java.time.chrono.JapaneseDate,java.time.chrono.MinguoDate,java.time.chrono.ThaiBuddhistDate; 如果类路径上有Joda Time日期/时间API ,则由HV附加支持:ReadablePartial和的任何实现ReadableInstant
@Pattern(regex=, flags=)
-
regex考虑给定标志,检查带注释的字符串是否与正则表达式匹配match -
CharSequence
@Positive
-
检查元素是否严格为正。零值被视为无效 -
BigDecimal,BigInteger,byte,short,int,long和原始类型的相应的包装; HV额外支持:的任何子类型CharSequence(评估字符序列表示的数值),Number和的任何子类型javax.money.MonetaryAmount
@PositiveOrZero
-
检查元素是否严格为正或零 -
BigDecimal,BigInteger,byte,short,int,long和原始类型的相应的包装; HV额外支持:的任何子类型CharSequence(评估字符序列表示的数值),Number和的任何子类型javax.money.MonetaryAmount
@Size(min=, max=)
-
检查带注释的元素的大小是否介于min和之间max(包括) -
CharSequence,Collection,Map和数组
@CreditCardNumber(ignoreNonDigitCharacters=)
-
检查带注释的字符序列是否通过了Luhn校验和测试 -
ignoreNonDigitCharacters允许忽略非数字字符。默认值为false。 -
CharSequence
@Currency(value=)
-
检查带注释的货币单位javax.money.MonetaryAmount是否为指定货币单位的一部分。 -
javax.money.MonetaryAmount
@DurationMax(days=, hours=, minutes=, seconds=, millis=, nanos=, inclusive=)
-
检查带注释的java.time.Duration元素不大于由注释参数构造的元素。如果将inclusiveflag设置为,则允许平等true -
java.time.Duration
@DurationMin(days=, hours=, minutes=, seconds=, millis=, nanos=, inclusive=)
-
检查带注释的java.time.Duration元素不少于由注释参数构造的元素。如果将inclusiveflag设置为,则允许平等true。 -
java.time.Duration
@EAN
-
检查带注释的字符序列是有效的EAN条形码。类型决定条形码的类型 -
CharSequence
@ISBN
-
检查带注释的字符序列是有效的ISBN -
CharSequence
@Length(min=, max=)
-
验证该注释字符序列是间min和max包含 -
CharSequence
@Range(min=, max=)
-
检查带注释的值是否介于(包括)指定的最小值和最大值之间 -
BigDecimal,BigInteger,CharSequence,byte,short,int,long和原始类型的相应的包装
@UniqueElements
-
检查带注释的集合仅包含唯一元素。使用该equals()方法确定相等性。默认消息不包括重复元素的列表,但是您可以通过覆盖消息并使用{duplicates}message参数来包括它。重复元素的列表也包含在约束违反的动态有效负载中。 -
Collection��负载中。 -
Collection
本文由 mdnice 多平台发布
相关文章:
![](https://www.ngui.cc/images/no-images.jpg)
【hibernate validator】(二)声明和验证Bean约束
首发博客地址 https://blog.zysicyj.top/ 一、声明bean约束 1. 字段级别约束 不支持静态类型字段 验证引擎直接访问实例变量,不会调用属性的访问器 在验证字节码增强的对象时,应适用属性级别约束,因为字节码增库无法通过反射确定字段访问 pac…...
![](https://www.ngui.cc/images/no-images.jpg)
Redis持久化机制之RDB,AOF与混合AOF
Redis是一款高性能的NoSQL数据库,它的速度非常快,同时也支持多种持久化机制,其中最常用的是RDB和AOF,还有一种混合AOF方式。那么这些持久化机制到底是什么,有什么不同呢? RDB是Redis默认的持久化方式&…...
![](https://img-blog.csdnimg.cn/img_convert/59fa6320f0fd1f7170e9478874b4717d.png)
为啥外卖小哥宁愿600一月租电动车,也不花2、3千买一辆送外卖!背后的原因......
大家好!我是菜哥! 又到周末了,我们聊点非技术的东西。最近知乎“为何那些穿梭于城市大街小巷的外卖小哥,宁愿每月掏出600块租一辆电动车,也不愿意掏出2、3千买一辆呢?” 冲上热榜! 听起来有点“…...
![](https://img-blog.csdnimg.cn/615ba319310d4e428c5d2aa6f1bbcf84.png)
分布式定时任务框架Quartz总结和实践(2)—持久化到Mysql数据库
本文主要介绍分布式定时任务框架Quartz集成SpringBoot持久化数据到Mysql数据库的操作,上一篇文章使用Quartz创建定时任务都是保存在内存中,如果服务重启定时任务就会失效,所以Quartz官方也提供将定时任务等信息持久化到Mysql数据库的功能&…...
![](https://www.ngui.cc/images/no-images.jpg)
Linux 服务器搭建配置,开发效率一飞冲天 - Centos 篇
大家好,我是比特桃。最近白嫖了一台 Centos 云服务器,用来做日常开发,特此记录一下搭建配置的过程。 我之前有篇文章是基于 Ubuntu 的:Linux 服务器搭建配置,开发效率一飞冲天 - Ubuntu 篇 如同个人电脑一样࿰…...
![](https://img-blog.csdnimg.cn/img_convert/dcd699a72cf280ecbbefc185b85216a1.jpeg)
Day46|leetcode 139.单词拆分
leetcode 139.单词拆分 题目链接:139. 单词拆分 - 力扣(LeetCode) 视频链接:动态规划之完全背包,你的背包如何装满?| LeetCode:139.单词拆分_哔哩哔哩_bilibili 题目概述 给你一个字符串 s 和一…...
![](https://www.ngui.cc/images/no-images.jpg)
深入理解高并发编程 - Thread 类的 stop () 和 interrupt ()
stop() stop() 方法被用于停止线程。然而,需要注意的是,stop() 方法已经被标记为已废弃(deprecated),并且不推荐使用。这是因为使用该方法可能导致不可预料的问题和数据不一致性,因此它被认为是不安全的。…...
![](https://img-blog.csdnimg.cn/86e27eb4a569461e94fc5f8e987a6e74.png)
C语言之三子棋游戏实现篇
目录 主函数test.c 菜单函数 选择实现 游戏函数 (函数调用) 打印棋盘数据 打印展示棋盘 玩家下棋 电脑下棋 判断输赢 循环 test.c总代码 头文件&函数声明game.h 头文件的包含 游戏符号声明 游戏函数声明 game.h总代码 游戏函数ga…...
![](https://img-blog.csdnimg.cn/8d20b6da88784b28b00f5fc8b1c17c03.png)
jupyter notebook 插件nbextensions的安装
安装步骤: 1、打开 jupyter notebook,新建一个 python 文件; 2、 分别输入以下代码,然后运行,出现 warning 不影响使用,如果出现 errors,则说明下载有问题: !python -m pip install…...
![](https://img-blog.csdnimg.cn/a95ffd1345154d7aabf4b602f921af81.jpeg)
Spring boot 集成单元测试
1.引入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency> 2. 3.编写测试类 package com.enterprise;import com.enterpr…...
![](https://img-blog.csdnimg.cn/91bb406d6c934f03b15aed4f013f37d0.png)
基于C++的QT实现贪吃蛇小游戏
文章目录: 一:效果演示 二:实现思路 三:代码实现 widget.h widget.cpp main.cpp 一:效果演示 效果图◕‿◕✌✌✌ 代码下载 二:实现思路 通过按键控制蛇的移动,每吃一个商品蛇身就会加长…...
![](https://img-blog.csdnimg.cn/3d2b2a73154844e188314ae3f95efcd2.png)
Spring Boot整合RabbitMQ之路由模式(Direct)
RabbitMQ中的路由模式(Direct模式)应该是在实际工作中运用的比较多的一种模式了,这个模式和发布与订阅模式的区别在于路由模式需要有一个routingKey,在配置上,交换机类型需要注入DirectExchange类型的交换机bean对象。…...
![](https://img-blog.csdnimg.cn/c6f6aef22ef44e01971d53ccb5035933.png)
行式存储与列式存储
1.概述 数据处理大致可分为两大类,联机事务处理OLTP(on-line transaction processing) 和联机分析处理OLAP(on-line analytical processing)。 OLTP是传统关系型数据库的主要应用,用来执行一些基本的、日常的事务处理,比如数据库记录的增、删…...
![](https://img-blog.csdnimg.cn/f82dae9051b84f9182142a2e2fdbd43d.png)
windows上sqlserver的ldf日志文件和数据mdf文件分别放到不同的磁盘
之前我的windows上已安装好了sqlserver2017,有一个名为TestDb的数据库。ldf文件和mdf文件都一起放在D:\Database目录下。现在需要把ldf日志文件到E盘的database目录下。 重要的事情先说三遍 先停止网关(例如nginx)并备份数据库 先停止网关&am…...
![](https://img-blog.csdnimg.cn/ea85217c0ec94f19833ae0c5bc440491.png)
vue3+uni——watch监听props中的数据(组件参数接收与传递defineProps、defineEmits)
案例说明 A页面引用的子组件B A页面 <template><view>//引用组件<serviceOrder change"change" :list"list" :current"type"></serviceOrder></view> </template><script setup>import serviceOrd…...
![](https://img-blog.csdnimg.cn/9356956979e340629d088506eab7f2d7.png)
mybatis与spring集成与spring aop集成pagehelper插件
Mybatis与Spring的集成 Mybatis是一款轻量级的ORM框架,而Spring是一个全栈式的框架,二者的结合可以让我们更加高效地进行数据持久化操作。 Mybatis与Spring的集成主要有两种方式:使用Spring的Mybatis支持和使用Mybatis的Spring支持。 使用…...
![](https://img-blog.csdnimg.cn/06d5ee5c64634e77a626fdff33de60f5.png)
Mybatis基础
...
![](https://img-blog.csdnimg.cn/2315b42685404be9a697926669b6841f.png)
TypeScript-- 配置Typescript环境(1)ts 转js,tsc --watch 实时编译
文章目录 安装Typescript判断是否有运行权限编写第一Typescript文件手动编译Ts文件转Js文件实时编译 安装Typescript npm install -g typescript 判断是否有运行权限 命令行运行 tsc -v 遇到了权限问题 用管理员打开window自带的powershell 运行如下指令即可: Set-…...
![](https://img-blog.csdnimg.cn/7ab73817f6af4f93861debd9e89cd5c7.png)
Dockerfile快速搭建自己专属的LAMP环境,生成镜像lamp:v1.1,并推送到私有仓库
环境: CentOS 7 Linux 3.10.0-1160.el7.x86_64 具体要求如下: (1)基于centos:6基础镜像; (2)指定作者信息; (3)安装httpd、mysql、mysql-server、php、ph…...
![](https://img-blog.csdnimg.cn/96bb68b4447043549f2034a21d099195.png)
Lottery抽奖项目学习第二章第一节:环境、配置、规范
Lottery抽奖项目学习第二章第一节:环境、配置、规范 环境、配置、规范 下面以DDD架构和设计模式落地实战的方式,进行讲解和实现分布式抽奖系统的代码开发,那么这里会涉及到很多DDD的设计思路和设计模式应用,以及互联网大厂开发中…...
![](https://www.ngui.cc/images/no-images.jpg)
OpenCV之reshape函数
函数原型: /** brief Changes the shape and/or the number of channels of a 2D matrix without copying the data.The method makes a new matrix header for \*this elements. The new matrix may have a different sizeand/or different number of channels. A…...
![](https://img-blog.csdnimg.cn/59c2d80e01f34f3ab7563f0736a77b88.png)
【JavaEE】Spring事务-@Transactional参数介绍-事务的隔离级别以及传播机制
【JavaEE】Spring事务(2) 文章目录 【JavaEE】Spring事务(2)1. Transactional 参数介绍1.1 value 和 transactionManager1.2 timeout1.3 readOnly1.4 后面四个1.5 isolation 与 propagation 2. Spring 事务隔离级别 - isolation2.…...
![](https://img-blog.csdnimg.cn/abd2740a8e2a4243bb89257d4b295562.png)
微信小程序canvas type=2d生成海报保存到相册、文字换行溢出显示...、文字删除线、分享面板
一、简介 做个简单的生成二维码海报分享,我做的时候也找简单的方法看能不能实现页面直接截图那种生成图片,原生小程序不支持,不多介绍下面有全部代码有注释、参数自行替换运行看看,还有需要优化的地方,有问题可以咨询…...
![](https://www.ngui.cc/images/no-images.jpg)
C++卷积神经网络
C卷积神经网络 #include"TP_NNW.h" #include<iostream> #pragma warning(disable:4996) using namespace std; using namespace mnist;float* SGD(Weight* W1, Weight& W5, Weight& Wo, float** X) {Vector2 ve(28, 28);float* temp new float[10];V…...
![](https://www.ngui.cc/images/no-images.jpg)
go 读取yaml映射到struct
安装 go get gopkg.in/yaml.v3创建yaml Mysql:Host: 192.168.214.134Port: 3306UserName: wwPassword: wwDatabase: go_dbCharset: utf8mb4ParseTime: trueLoc: LocalListValue:- haha- test- vv JWTSecret: nidaye定义结构体 type Mysql struct {Host string yaml:&…...
![](https://img-blog.csdnimg.cn/ffb9f9704f294f078b159cbd82e14f35.png)
Redis 10 大数据类型
1. which 10 1. redis字符串 2. redis 列表 3. redis哈希表 4. redis集合 5. redis有序集合 6. redis地理空间 7. redis基数统计 8. redis位图 9. redis位域 10. redis流 2. 获取redis常见操作指令 官网英文:https://redis.io/commands 官网中文:https:/…...
![](https://img-blog.csdnimg.cn/c8c956391e154e949f11f36ffea9b5a0.jpeg#pic_center)
优化生产流程:数字化工厂中的OPC UA分布式IO模块应用
背景 近年来,为了提升在全球范围内的竞争力,制造企业希望自己工厂的机器之间协同性更强,自动化设备采集到的数据能够发挥更大的价值,越来越多的传统型工业制造企业开始加入数字化工厂建设的行列,实现智能制造。 数字化…...
![](https://img-blog.csdnimg.cn/d0d24f215ae94a1997f40078025308d7.png)
Elasticsearch(十四)搜索---搜索匹配功能⑤--全文搜索
一、前言 不同于之前的term。terms等结构化查询,全文搜索首先对查询词进行分析,然后根据查询词的分词结果构建查询。这里所说的全文指的是文本类型数据(text类型),默认的数据形式是人类的自然语言,如对话内容、图书名…...
![](https://img-blog.csdnimg.cn/65365c23dd4c4e499028802bac6bb0d4.jpeg)
已解决Gradle错误:“Unable to load class ‘org.gradle.api.plugins.MavenPlugin‘”
🌷🍁 博主猫头虎 带您 Go to New World.✨🍁 🦄 博客首页——猫头虎的博客🎐 🐳《面试题大全专栏》 文章图文并茂🦕生动形象🦖简单易学!欢迎大家来踩踩~🌺 &a…...
![](https://img-blog.csdnimg.cn/25a11fac244e4efc87f09748c02cf1dc.png)
windows中安装sqlite
1. 下载文件 官网下载地址:https://www.sqlite.org/download.html 下载sqlite-dll-win64-x64-3430000.zip和sqlite-tools-win32-x86-3430000.zip文件(32位系统下载sqlite-dll-win32-x86-3430000.zip)。 2. 安装过程 解压文件 解压上一步…...
![](https://img-blog.csdnimg.cn/img_convert/ea4acd1a4cf34695225221b1580baef6.png)
专业网站维护/服务营销的七个要素
点击上方“Java基基”,选择“设为星标”做积极的人,而不是积极废人!源码精品专栏 原创 | Java 2020 超神之路,很肝~中文详细注释的开源项目RPC 框架 Dubbo 源码解析网络应用框架 Netty 源码解析消息中间件 RocketMQ 源码解析数据库…...
![](/images/no-images.jpg)
猎趣网站/武汉网站排名提升
今天和大家聊聊泛型在容器中存在的安全问题,我们先来看一个例子。 public class Pet {}public class Dog extends Pet {}public class Cat extends Pet {}public class PelList {public static void main(String[] args) {List dogs new ArrayList<Dog>();d…...
![](/images/no-images.jpg)
wordpress有声主题/友博国际个人中心登录
参考:https://blog.csdn.net/laochu250/article/details/67649210...
![](/images/no-images.jpg)
用旧手机做网站/全球搜钻是什么公司
什么样的链接算是高质量链接? 按照链接路径的不同,网页中超链接一般分为以下3种类型:内部链接,锚点链接和外部链接。 如果按照使用对象的不同,网页中的链接又可以分为:文本超链接,图像超链接…...
![](/images/no-images.jpg)
wordpress 主题购买/seo关键词分析表
一、异常现象 spingbott项目在eclipse中执行maven命令:spring-boot:run, 出现异常: No plugin found for prefix spring-boto in the current project 二、解决方法 参考: No plugin found for prefix spring-boot ...的问题解决方法 转载于:…...
![](https://img-blog.csdnimg.cn/img_convert/b81ae9f7ba6c7b67a9da4a64ce354236.png)
网站上的视频直播是怎么做的呢/企业查询平台
前言 近几年来,互联网行业变化非常大,除了龙头企业的更替,“裁员潮”“失业潮”也不断掀起,尤其是对于年纪太大的程序员真的是不太友好。但是,根据数据统计表明,自2018来,学习IT行业的人不减反…...