在我的表视图控制器中有
self.navigationItem.leftBarButtonItem = self.editButtonItem;
Run Code Online (Sandbox Code Playgroud)
这会在左上角生成一个常规的编辑/完成按钮.因此,一旦用户单击"编辑",按钮标题将变为"完成",并且可以删除或重新排序表条目.我想在用户实际点击"完成"后收到通知.那有什么钩子吗?
背景:我想保留条目的顺序,即下次用户提取此视图时,我想在最近最少使用的顺序中显示条目.
我是Spring和Spring Security的新手.我正在阅读关于Spring Security的内容,它出现了principal的概念,它应该是当前登录的用户.但是,如果我们有多个当前登录用户怎么办?所以,我的问题是,那么春季安全的主要内容到底是什么?
我已阅读本教程的示例:
http://www.mkyong.com/spring-security/get-current-logged-in-username-in-spring-security/
他们似乎考虑到只有一个当前登录的用户,这种情况并非如此.
如何检索特定用户?我如何区分正在进行请求的用户?
我们正在构建一个可供经过身份验证的用户和匿名用户使用的Web应用程序.如果您决定不注册/登录,则只有一组有限的功能.使用Spring Security通过OpenID完成用户身份验证.这很好.
但是,该应用程序还附带了部署的管理UI <host>/<context-root>/admin
.我们可以在Spring Security中使用两个独立的领域(例如基本身份验证/admin/**
)吗?如何配置?
已将persistence.xml放在eclipse中项目的类路径中,因为在错误之前找不到该文件.现在给出了这个错误:
引发者:javax.persistence.PersistenceException:无效的persistence.xml.解析XML时出错[line:-1,column:-1]:cvc-elt.1:找不到元素'persistence'的声明
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1"
xsi:schemalocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/Automoveis" />
<property name="javax.persistence.jdbc.user" value="postgres" />
<property name="javax.persistence.jdbc.password" value="1234" />
<property name="javax.persistence.jdbc.driver" value="org.postgresql.jdbc.Driver" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>
</persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud) 什么是影响消息转换器优先级的最方便的方法Spring在POST时使用RestTemplate
?
使用案例:我想确保给定的实体作为JSON而不是例如XML进行POST restTemplate.postForEntity(url, entity, Void.class)
.
默认
默认情况下,实体将转换为XML,因为MappingJackson2XmlHttpMessageConverter
它优先于MappingJackson2HttpMessageConverter
.我的应用程序的默认转换器列表似乎是(Spring扫描类路径以查看可用的内容):
选项1
您可以为给定RestTemplate
实例显式配置消息转换器,如下所示restTemplate.setMessageConverters(Lists.newArrayList(new MappingJackson2HttpMessageConverter()))
.如果实例是共享的(例如Spring bean),这是不方便的,因为在一种情况下可能需要转换器X而在另一种情况下可能需要转换器Y.
选项2
您可以设置Accept
和Content-Type
HTTP头文件明确在这种情况下,Spring将使用匹配的消息变换.缺点是你必须诉诸于RestTemplate.exchange
而不是通过RestTemplate.postForEntity
哪种方式:额外的代码,更少的便利.
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
HttpEntity requestEntity = new HttpEntity(entity, requestHeaders);
restTemplate.exchange(url, HttpMethod.POST, requestEntity, Void.class);
Run Code Online (Sandbox Code Playgroud)
选项3
这可能是我正在寻找的:)
我正在开发一个使用EJB2s的项目.创建的EJB Jars需要在应用程序服务器捆绑在war/ear中并进行部署之前进行其他处理.
我已经创建了一个自定义任务,如果我明确地调用它(gradle ejbDeploy),它可以进行额外的处理,但是很难将它安装到gradle多项目生命周期中.我需要以某种方式将它添加到构建图中,以便在jar任务之后自动执行.
我的第一次尝试是将它添加到jar中
jar.doLast{
ejbDeploy.execute()
}
Run Code Online (Sandbox Code Playgroud)
这似乎适用于任意代码块,但不适用于任务
推荐的解决方案是什么?我看到三种方法:
有推荐的方法吗?
谢谢!
我已经在Docker容器中运行Ubuntu 16.04 LTS(托管在macOS上).日期/时间约为四天.
$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
$ date
Sun May 7 05:57:21 UTC 2017
Run Code Online (Sandbox Code Playgroud)
生效日期是2017年5月11日06:17:13 UTC.
我想解决这个问题(检查这个和这个),但我甚至无法运行timedatectl
:
$ timedatectl status
Failed to create bus connection: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我想在表格单元格中添加一个按钮.日历应用程序中的"删除事件"启发了我...(类似案例是联系人中的"共享联系人")
截至目前已有
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//..yadayadayada
cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"buttonCell"] autorelease];
}
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoDark];
[button setBackgroundColor:[UIColor redColor]];
button.titleLabel.text = @"Foo Bar";
[cell.contentView addSubview:button];
Run Code Online (Sandbox Code Playgroud)
确实产生了一个按钮.它看起来还不怎么样(很明显我从未处理过iPhone中的按钮),但这至少是正确的方法吗?
我用JProfiler和YourKit分析了我的代码.但是,我还没弄清楚如何检测哪一段代码导致高CPU负载.
如果响应时间不好,检测热点是微不足道的.在我的情况下,虽然响应时间不是问题.只是在处理此特定请求的短时间内CPU负载非常高(非常高).
如何确定哪个类/方法导致此问题?我想我正在寻找的是某种列表,它告诉我需要多少CPU周期来处理一个方法 - 左右.
我有一组Futures
通过提交Callable
s来创建Executor
.伪代码:
for all tasks
futures.add(executor.submit(new callable(task)))
Run Code Online (Sandbox Code Playgroud)
现在我想让所有期货等待最多n秒,直到全部完成.我知道我可以打电话Future#get(timeout)
但是如果我在循环中按顺序呼叫我的所有未来,则时间开始加起来.伪代码:
for all futures
future.get(timeout)
Run Code Online (Sandbox Code Playgroud)
get
超时的块直到结果准备好.因此,如果第一个在超时之前完成,第二个也在超时之前完成,那么整个执行时间number of futures * timeout
最多不是timeout
.
因此,我正在寻找一种接受Future
s 列表和超时的方法,并行运行,然后返回未来结果的集合.有任何想法吗?
java ×6
spring ×3
iphone ×2
uitableview ×2
concurrency ×1
cpu ×1
cpu-usage ×1
docker ×1
future ×1
gradle ×1
hibernate ×1
jpa ×1
ntp ×1
persistence ×1
profiler ×1
profiling ×1
resttemplate ×1
security ×1
ubuntu ×1
ubuntu-16.04 ×1
uibutton ×1