在C#中,您可以使用属性使数据字段可公开访问(允许用户直接访问它),同时保留在这些直接访问的字段上执行数据验证的功能.Java有类似的东西吗?对于Instance,假设存在一个带有以下实现的C#类(见下文):
public class newInt{
public newInt(){...}
public int x{
get{ return this.x }
set{ this.x = isValid(value) }
}
}
private static int isValid(int value){...}
Run Code Online (Sandbox Code Playgroud)
类中的这个定义允许用户在从中检索值并为其赋值时"自然地"使用数据字段'x'.以下是它将如何在主要使用.
public class Test{
public static void main(String[] args){
newInt a = new newInt();
a.x = 50;
int b = a.x;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是...... java也可以这样做吗?如果是这样,它叫什么?
我刚刚从这里举了一个例子https://angular.io/guide/quickstart
我根据快速入门手册完成了所有工作.但是在app.ts编译时在WebStorm控制台中收到警告.
这是详细信息:
我在Windows 8.1 x64,Webstorm 11.0.1上
app.ts:
import {bootstrap, Component} from 'angular2/angular2';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 3 App</h1>'
})
class AppComponent { }
bootstrap(AppComponent);
Run Code Online (Sandbox Code Playgroud)
tsconfig.json:
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"sourceRoot": "/"
},
"exclude": [
"node_modules"
]
}
Run Code Online (Sandbox Code Playgroud)
我将tsconfig.json文件放在文件app夹和根目录中.
在app.ts实际得到的文件汇编,但得到某种原因的警告:
error TS1148: Cannot compile modules unless the '--module' flag is provided.
error TS2307: …Run Code Online (Sandbox Code Playgroud) 编译器找到 的定义HTMLElement,但react/global.d.ts取自的定义而不是typescript/lib/lib.dom.d.ts。
这是编译器错误:
Property 'value' does not exist on type 'EventTarget'. TS2339
Run Code Online (Sandbox Code Playgroud)
以下是差异:
Property 'value' does not exist on type 'EventTarget'. TS2339
Run Code Online (Sandbox Code Playgroud)
interface Element { }
interface HTMLElement extends Element { }
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:如何让编译器typescript/lib/lib.dom.d.ts在 React 之前选择?任何帮助将不胜感激?
编辑:这是tsconfig.json正确引用 TS 库的 :
interface HTMLElement extends Element, GlobalEventHandlers, DocumentAndElementEventHandlers, ElementContentEditable, HTMLOrSVGElement, ElementCSSInlineStyle {
accessKey: string;
readonly accessKeyLabel: string;
autocapitalize: string;
dir: string;
draggable: boolean;
hidden: boolean;
innerText: string;
lang: string;
readonly …Run Code Online (Sandbox Code Playgroud) 我们公司开始使用单一产品,一些由一些Java服务支持的rails应用程序,然后决定他们想要另一种产品,这种产品最初与第一种产品有很大不同,但随着时间的推移,我们已经意识到它们已经开始融合,并且将代码更改为一个需要对另一个进行类似的代码更改以进行新功能/错误修复.这显然是一种痛苦.
在某些情况下,我们拥有共享一些此功能的宝石,但它超越了ruby到javascript,css等.
所以我的任务是将这两个应用程序合并到一个代码库中.我认为最终我们希望它是一个具有基于权限的角色访问权限的应用程序,但这将会更晚.
我第一次想到将它们快速组合在一起就是创建两个rails引擎并在它们之间共享公共库.我认为这是组合代码,查找常见部分和开始共享的最快捷方式.
我的第一个问题是如何在应用程序之间进行路由.一个应用程序使用永远不会更改的单个域名,另一个应用程序具有许多域.有人可以建议我如何将特定请求路由到特定应用程序,以便在共享库的公共代码库时可以保持独立开始吗?
或者,如果有人对如何组合这些应用程序有其他建议,我会全神贯注.
它们都是运行JRUBY 1.5.3的Rails 2.3.10应用程序,但是我们可能会升级到Rails3,如果这会使事情变得更容易或更清晰(即更好的Rack集成)
我没有做任何Rack编程,但从来没有伤害过,如果这将使我们的生活更轻松.
我正在编写一个从一组 XML 文件生成 PDF 文件的服务。正在正确生成 PDF。但是,每次我单击“查看 PDF”链接时,浏览器都会要求用户下载 PDF 文件。
我需要 PDF 内联显示,就像任何常规 HTML 页面一样。我虽然我写的代码是正确的,但一定缺少一些东西 - 浏览器不断要求用户下载。
这是当前的代码:
class PdfController < Controller
def generate
# stuff
send_data pdf_bytes, :disposition => 'inline', :type => 'application/pdf'
end
end
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我的应用程序存储了很多XML文件.后台作业会定期将某些XML文件发送到特定邮箱.邮件代码很简单:
class MailSender < ActionMailer::Base
default :from => AppConfig.mail_from
smtp_settings :address => AppConfig.smtp_host,
:username => AppConfig.smtp_user,
:password => AppConfig.smtp_pass
def send_xml(record)
f = record.filename.gsub("\\", "/") # converts \ to /
f_short = arq.gsub(/.*\//, "") # extracts only the filename
f_phys = "#{AppConfig.xml_root}#{arq}" # builds the physical filename
headers["Return-Receipt-To"] = AppConfig.return_receipt
attachments[f_short] = File.read(f_phys) if File.exists?(f_phys)
mail :subject => "...",
:to => AppConfig.mail_to
end
end
Run Code Online (Sandbox Code Playgroud)
但是,由于某些原因,这些XML在传输时会被破坏:第945行会添加第一个换行符,第990行会添加以下内容.每次中断后,都会插入一个空格.我认为图片说明了一切:
col 1 col 990
|.................................................|
<?xml version="1.0" ... </IE><IM>321505493301<
/IM><CNAE>4744001< ... 00</pCOFINS><vCOFINS>0.00
</vCOFINS></COFINS ... /prod><imposto><ICMS><ICM …Run Code Online (Sandbox Code Playgroud) 我正在使用Node.js开发一个简单的服务.它接收上载的文件,将它们存储在磁盘上并在Oracle表上记录一些元数据.我将这个db-oracle包与连接池一起使用,遵循这篇文章:http://nodejsdb.org/2011/05/connection-pooling-node-db-with-generic-pool/
但是,我注意到我插入的数据仅在连接池通过调用其disconnect()方法关闭空闲连接后才发送到Oracle数据库.
有没有办法在向客户端发送"OK"信号之前刷新数据?它现在的工作方式,我的Web服务或Oracle本身的崩溃都可能导致数据丢失,而我的服务客户端也不会知道它.我实际上是在上传一段时间后通过杀死我的应用程序进行测试,数据确实丢失了.
这是代码的简化版本:
var express = require('express');
var app = module.exports = express.createServer();
app.post('/upload', handleUpload);
app.listen(4001, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
function handleUpload(req, res) {
res.contentType('application/xml');
var buf = '';
req.on('data', function(chunk) { buf += chunk; });
req.on('end', function() {
saveUpload(req, res, buf);
});
}
function saveUpload(req, res, buf) {
if (buf.length == 0)
return sendError(res, 'No data supplied', 422);
var payload = new …Run Code Online (Sandbox Code Playgroud) 我使用crontab在某个时间调用rake任务,例如:每3小时一次
我想确保当crontab准备好执行rake任务时,它可以检查rake任务是否正在运行.如果它是这样不执行.
这该怎么做.谢谢.
我已经使用Mongoid大约3个月了,由于那里有很棒的文档和资源,我已经设法完成了我需要的任何事情.
但是回过头来改进一些我已经退缩的东西,我肯定在嵌入式文档上苦苦挣扎.
简而言之,我要做的是在嵌入式文档上维护版本控制和时间戳,但我无法做到.
这是我模型的相关部分:
class Content
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Paranoia
embeds_many :localized_contents
accepts_nested_attributes_for :localized_contents
end
class LocalizedContent
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Paranoia
include Mongoid::Versioning
embedded_in :content, :inverse_of => :localized_contents
end
Run Code Online (Sandbox Code Playgroud)
这里没有什么真正复杂的,关于内容模型的行为一切正常,但是LocalizedContent模型的表现并不像我期望的那样,所以我的期望要么需要理顺,要么我需要帮助解决我做错的事情.
要创建新的嵌入式文档,请执行以下操作:
my_content = Content.find(params[:id])
my_content.localized_contents.build(params[:localized_content])
if parent.save
#redirect, etc.
end
Run Code Online (Sandbox Code Playgroud)
这是因为它在正确的内容中成功创建了一个新的嵌入式文档,但是我留下的时间戳字段为零
现在,如果我尝试更新那个localized_content:
my_content = Content.find(params[:content_id])
localized_content = my_content.localized_contents.find(params[:id])
Run Code Online (Sandbox Code Playgroud)
现在,如果我这样做:localized_content.update_attributes(params[:localized_content])我收到以下错误:
=> Mongoid::Errors::InvalidCollection: Access to the collection for LocalizedContent is not allowed since it is an embedded document, please access a collection from the …Run Code Online (Sandbox Code Playgroud) 我正在使用 system() 调用在 Rails(-v 2.3.5) 应用程序中调用 C 可执行文件。
makefile_path = File.expand_path('./c_executalbe', Rails.root)
system(makefile_path)
Run Code Online (Sandbox Code Playgroud)
在我的本地机器上一切正常,但由于某种原因系统()调用不会在服务器(dreamhost)上运行。并且 log/production.log 中没有错误信息。我想在日志中看到该系统调用的返回输出。我怎样才能做到这一点?
提前致谢!
我试图在我的机器上安装Ruby EE,但我无法.
ping production.cf.rubygems.org也有效.可能是什么问题?
prashanth@prashanth-laptop:~/Downloads$ rvm install ree
Installing Ruby Enterprise Edition from source to: /usr/local/rvm/rubies/ree-1.8.7-2011.03
ree-1.8.7-2011.03 - #fetching (ruby-enterprise-1.8.7-2011.03)
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 184 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0Warning: Failed to create the file ruby-enterprise-1.8.7-2011.03.tar.gz
0 7713k 0 16150 0 0 3108 0 0:42:21 0:00:05 0:42:16 17497
curl: (23) Failed writing body (0 != 16150)
ERROR: There was …Run Code Online (Sandbox Code Playgroud)