旧的 .NET 项目在调试下有一个选项,允许“启动外部命令”,如图所示
当我使用新的SDK样式创建新项目时,我看不到相同的选项(如下图)。有办法拿回来吗?
下面的代码将jar文件添加到构建路径,它适用于Java 8.但是,它会抛出Java 9的异常,该异常与转换为URLClassLoader有关.有什么想法可以解决这个问题吗?最佳解决方案将对其进行编辑以与Java 8和9一起使用.
private static int AddtoBuildPath(File f) {
try {
URI u = f.toURI();
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class<URLClassLoader> urlClass = URLClassLoader.class;
Method method = urlClass.getDeclaredMethod("addURL", URL.class);
method.setAccessible(true);
method.invoke(urlClassLoader, u.toURL());
} catch (NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException | MalformedURLException | IllegalAccessException ex) {
return 1;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 目前,Wikidata有一个SPARQL端点" https://query.wikidata.org/ ",我想使用Jena(3.0.1)查询此站点,我使用以下代码但是我收到一条错误消息" Endpoint返回内容-Type:SELECT查询当前不支持的text/html ".有办法解决吗?相同的代码适用于dbpedia.谢谢
queryString = "PREFIX bd: <http://www.bigdata.com/rdf#>\n" +
"PREFIX wikibase: <http://wikiba.se/ontology#>\n" +
"PREFIX wdt: <http://www.wikidata.org/prop/direct/>\n" +
"PREFIX wd: <http://www.wikidata.org/entity/>\n" +
"SELECT DISTINCT ?country ?countryLabel\n" +
"WHERE\n" +
"{\n" +
"\t?country wdt:P31 wd:Q3624078 .\n" +
" ?country wdt:P1622 wd:Q13196750.\n" +
" ?country wdt:P30 wd:Q15\n" +
"\tFILTER NOT EXISTS {?country wdt:P31 wd:Q3024240}\n" +
"\tSERVICE wikibase:label { bd:serviceParam wikibase:language \"en\" }\n" +
"}\n" +
"ORDER BY ?countryLabel";
query = QueryFactory.create(queryString);
qexec = QueryExecutionFactory.sparqlService("https://query.wikidata.org/", queryString);
try {
ResultSet results = qexec.execSelect(); …Run Code Online (Sandbox Code Playgroud) 这个 MSDN链接解释了为什么将 DTO 类用于 Web API 是一种很好的做法。这是可以理解的,让我困惑的是在同一页面中,post 方法使用模型类而不是简单的 DTO 类,如下所示:
[ResponseType(typeof(BookDTO))]
public async Task<IHttpActionResult> PostBook(Book book)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.Books.Add(book);
await db.SaveChangesAsync();
// New code:
// Load author name
db.Entry(book).Reference(x => x.Author).Load();
var dto = new BookDTO()
{
Id = book.Id,
Title = book.Title,
AuthorName = book.Author.Name
};
return CreatedAtRoute("DefaultApi", new { id = book.Id }, dto);
}
Run Code Online (Sandbox Code Playgroud)
我想我的问题是:Post/Put 操作应该采用模型还是 DTO 参数?
更新:从答案来看,即使在 post/put action 的情况下,似乎也建议使用 dto,但这会导致另一个问题,如何在 post action 的情况下从 dto 映射到 …
c# ×2
java ×2
.net ×1
.net-core ×1
asp.net-core ×1
classloader ×1
dto ×1
java-9 ×1
semantic-web ×1
sparql ×1
wikidata ×1