我用了Fluent Validator.但有时我需要创建一个规则层次结构.例如:
[Validator(typeof(UserValidation))]
public class UserViewModel
{
public string FirstName;
public string LastName;
}
public class UserValidation : AbstractValidator<UserViewModel>
{
public UserValidation()
{
this.RuleFor(x => x.FirstName).NotNull();
this.RuleFor(x => x.FirstName).NotEmpty();
this.RuleFor(x => x.LastName).NotNull();
this.RuleFor(x => x.LastName).NotEmpty();
}
}
public class RootViewModel : UserViewModel
{
public string MiddleName;
}
Run Code Online (Sandbox Code Playgroud)
我想从UserValidation继承验证规则到RootValidation.但是这段代码不起作用:
public class RootViewModelValidation:UserValidation<RootViewModel>
{
public RootViewModelValidation()
{
this.RuleFor(x => x.MiddleName).NotNull();
this.RuleFor(x => x.MiddleName).NotEmpty();
}
}
Run Code Online (Sandbox Code Playgroud)
如何使用FluentValidation继承验证类?
我有一个PopupWindow,我希望它在用户触摸外面时解散,所以我调查并发现我必须使用它popup.setBackgroundDrawable(new BitmapDrawable());
.问题new BitmpaDrawable()
是不推荐使用构造函数.我想在不使用它的情况下找到解决方案.
谁知道怎么解决这个问题?
谢谢!
final PopupWindow popup = new PopupWindow(sortByView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
true);
popup.setBackgroundDrawable(new BitmapDrawable());
popup.setOutsideTouchable(true);
popup.showAsDropDown(v);
Run Code Online (Sandbox Code Playgroud) 我试图调用返回引用游标的Oracle存储过程,我需要从返回的数据生成树视图.我是新手,我有两个问题.
第一个问题是我无法调用该程序.我收到此错误:"调用'OBJECT_HIERARCHY'时参数的数量或类型错误"
而我的第二个问题是,当这个过程返回一个引用游标值时,我不明白我将如何获取该数据?该表中有超过5000条记录,我没有获得该数据,而是一个引用游标值.有人可以解释我如何使用ref游标值获取该数据.我没有使用Oracle的经验.
这是oracle中的过程定义:
CREATE OR REPLACE PROCEDURE SAD.object_hierarchy
(nAppId IN NUMBER,
nParentId IN NUMBER DEFAULT -1,
o_cRefCursor OUT SYS_REFCURSOR)
IS
BEGIN
IF NOT o_cRefCursor%ISOPEN THEN
OPEN o_cRefCursor FOR
SELECT
h.PARENT_ID, h.CHILD_ID, h.H_LEVEL,
o.OBJECT_IDENTIFIER, o.OBJECT_TYPE_ID
FROM
(
SELECT
PARENT_ID, CHILD_ID, LEVEL AS H_LEVEL
FROM OBJECT_RELATIONSHIPS
START WITH PARENT_ID = nParentId --> -1 --= 60170
CONNECT BY PRIOR CHILD_ID = PARENT_ID
) h
INNER JOIN
OBJECTS o
ON
o.OBJECT_ID = h.CHILD_ID AND
O.APPLICATION_ID = nAppId;
END IF;
END object_hierarchy;
Run Code Online (Sandbox Code Playgroud)
这些是表字段定义
Column …
Run Code Online (Sandbox Code Playgroud) 我有以下控制器操作
public void Post(Dto model)
{
using (var message = new MailMessage())
{
var link = Url.Link("ConfirmAccount", new { model.Id });
message.To.Add(model.ToAddress);
message.IsBodyHtml = true;
message.Body = string.Format(@"<p>Click <a href=""{0}"">here</a> to complete your registration.<p><p>You may also copy and paste this link into your browser.</p><p>{0}</p>", link);
MailClient.Send(message);
}
}
Run Code Online (Sandbox Code Playgroud)
为了测试这个,我需要设置控制器上下文
var httpConfiguration = new HttpConfiguration(new HttpRouteCollection { { "ConfirmAccount", new HttpRoute() } });
var httpRouteData = new HttpRouteData(httpConfiguration.Routes.First());
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "http://localhost");
sut = new TheController
{
ControllerContext = …
Run Code Online (Sandbox Code Playgroud) 我很好奇的性能特点joined()
,并.flatMap(_:)
在扁平化多维数组:
let array = [[1,2,3],[4,5,6],[7,8,9]]
let j = Array(array.joined())
let f = array.flatMap{$0}
Run Code Online (Sandbox Code Playgroud)
他们都压平嵌套array
进[1, 2, 3, 4, 5, 6, 7, 8, 9]
.我是否应该更喜欢一个而不是性能?此外,是否有更可读的方式来编写呼叫?
我真的不明白如何创建这样的inputStream,它是Seekable和PositionedReadable ......
Resource resource = new ClassPathResource("somefile");
InputStream bla = resource.getInputStream();
FSDataInputStream inputStream = new FSDataInputStream (bla);
Run Code Online (Sandbox Code Playgroud)
投掷FS线:
java.lang.IllegalArgumentException: In is not an instance of Seekable or PositionedReadable
Run Code Online (Sandbox Code Playgroud)
我需要做嘲笑,这对我来说是一个阻碍者.
我有以下型号:
public class ViewDataItem
{
public string viewName { get; set; }
public UpdateIndicator updateIndicator { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
使用以下枚举:
public enum UpdateIndicator
{
Original,
Update,
Delete
}
Run Code Online (Sandbox Code Playgroud)
以下验证者:
public class ViewValidator : AbstractValidator<ViewDataItem>
{
public ViewValidator()
{
RuleFor(x => x.viewName).NotEmpty().WithMessage("View name must be specified");
RuleFor(x => x.updateIndicator).SetValidator(new UpdateIndicatorEnumValidator<UpdateIndicator>());
}
}
public class UpdateIndicatorEnumValidator<T> : PropertyValidator
{
public UpdateIndicatorEnumValidator() : base("Invalid update indicator") {}
protected override bool IsValid(PropertyValidatorContext context)
{
UpdateIndicator enumVal = (UpdateIndicator)Enum.Parse(typeof(UpdateIndicator), context.PropertyValue.ToString());
if (!Enum.IsDefined(typeof(UpdateIndicator), enumVal))
return …
Run Code Online (Sandbox Code Playgroud) 在TypeScript中声明一个属性readonly
与通过a创建它之间在功能上有区别get()
吗?两者的行为相同,但最好知道除偏好之外是否还有理由使用一个。
这是一个普遍的问题,虽然我确实有一个我正在看的特定实例,所以我试图尽可能保持标题和标签的通用性.
我正在和IOC一起做MVC项目.我的具体存储库实现IDisposable
了处理Ef Context.
显然,MVC处理被调用的Controller对象的处理.但是,我需要Dispose()
在控制器中覆盖吗?这是我现在的代码:
private IUserRepository repository;
public UserController(IUserRepository repository) {
this.repository = repository;
}
protected override void Dispose(bool disposing) {
if (repository is IDisposable && repository != null) {
(repository as IDisposable).Dispose();
repository = null;
}
base.Dispose(disposing);
}
Run Code Online (Sandbox Code Playgroud)
我检查以确保它IDisposable
从我的单元测试中实现为模拟我不认为实现它.
现在,我的问题是超越Dispose()
冗余?当Controller(或任何其他对象)被释放时,垃圾收集器是否会查找实现的任何属性IDisposable
,或者我是否正确执行此操作?
我可以成功通过Java Mail API发送电子邮件,但现在我正在尝试发送从带有边框等格式的表中的MySQL查询填充的ResultSet的内容,我可以使用CSS标签来执行此操作吗?如果是这样的话?
我的代码如下:
public void getOutstanding() throws MessagingException {
try {
String outS = "SELECT period_to, type, amt, status FROM tblinstall "
+ "WHERE status like ?";
PreparedStatement update = toDB.prepareStatement(outS);
email = new StringBuilder();
email.append("<html><head><style type='text/css'>table .out {border-width:1px, "
+ "border-color: black}</style></head>"
+ "<body>"
+ "<table class'out'><span style=border-color: black, border-width: 1px>");
update.setString(1, "Outstanding");
ResultSet results = update.executeQuery();
while (results.next()) {
System.out.println("in results...");
email.append("<tr>");
email.append("<td>");
long period = results.getLong("period_to");
email.append(DateConvert.fromEpoch(period));
email.append("</td>");
email.append("<td>");
email.append(results.getString("type"));
email.append("</td>");
email.append("<td>");
email.append(results.getString("amt"));
email.append("</td>");
email.append("<td>");
email.append(results.getString("status")); …
Run Code Online (Sandbox Code Playgroud) c# ×4
android ×1
apache ×1
arrays ×1
c#-4.0 ×1
dispose ×1
enums ×1
hadoop ×1
idisposable ×1
jakarta-mail ×1
java ×1
javascript ×1
json ×1
oracle11g ×1
plsql ×1
popupwindow ×1
spring ×1
swift ×1
swift3 ×1
typescript ×1
unit-testing ×1