在IntelliJ IDEA中,我已经定义了一个这样的实时模板:
@Inject
private void postInject() {
//I want the cursor to be placed here after the execution of the live template.
}
Run Code Online (Sandbox Code Playgroud)
有没有办法告诉IntelliJ在展开实时模板后将光标放在方法体内?
当我注意到一些奇怪的东西时,我正在学习如何使用java 8流.
Arrays.stream() 有浮动数组的所有方法:
Arrays.stream(int[]) : IntStreamArrays.stream(long[]) : LongStreamArrays.stream(double[]) : DoubleStream类似地,有int,double等的Stream实现,但不是浮点数:
IntStreamLongStreamDoubleStream这有什么理由吗?
使用浮点流的推荐方法是什么?
从不使用方法时,IntelliJ会显示警告 Method xxx() is never used
但对于POJO,我为每个属性创建Getters/Setter,我不希望IntelliJ警告我未使用的Getters/Setter.
有没有办法自动抑制这些警告?
我已经阅读了关于SO 的文档和所有相关问题,但是Angular的XSRF机制仍然不适合我:我绝不能自动附加X-XSRF-TOKEN标头发出POST请求.
我有一个带登录表单的Angular 6应用程序.
它是Symfony(PHP 7.1)网站的一部分,Angular应用程序页面,当从Symfony提供时,发送正确的Cookie(XSRF-TOKEN):
我的app.module.ts包含正确的模块:
// other imports...
import {HttpClientModule, HttpClientXsrfModule} from "@angular/common/http";
// ...
@NgModule({
declarations: [
// ...
],
imports: [
NgbModule.forRoot(),
BrowserModule,
// ...
HttpClientModule,
HttpClientXsrfModule.withOptions({
cookieName: 'XSRF-TOKEN',
headerName: 'X-CSRF-TOKEN'
}),
// other imports
],
providers: [],
entryComponents: [WarningDialog],
bootstrap: [AppComponent]
})
export class AppModule {
}
Run Code Online (Sandbox Code Playgroud)
然后,在Service的方法中,我正在进行以下http请求(this.http是一个实例HttpClient):
this.http
.post<any>('api/login', {'_username': username, '_pass': password})
.subscribe(/* handler here */);
Run Code Online (Sandbox Code Playgroud)
post请求永远不会发送X-XSRF-TOKEN标头.为什么?
我已经读过Java7中的内容,我们现在可以写下这个有趣的声明:
public static boolean isZero(int O_O){
return O_O == 0_0;
}
Run Code Online (Sandbox Code Playgroud)
问题是:0_0在这种情况下究竟意味着什么?
我正在使用带有ui-grid的angularjs.网格的一列包含一个时间戳,我想将其呈现为格式正确的日期.
到目前为止,我尝试过这样,但从未调用过该函数.
$scope.formatDate = function(date) {
return '42';
};
$scope.columns = [
{field: 'date', cellTemplate: '<div class="ui-grid-cell-contents">formatDate({{row.entity.date}})</div>'},
{field: 'title'},
{field: 'quantity'},
//[...]
];
Run Code Online (Sandbox Code Playgroud)
相反,函数调用被视为字符串文字.因此,该列始终显示formatDate(*timestamp*).
我只是通过在接收它们时在每一行上定义一个函数来找到一种不令人满意的方法来实现它:
$scope.columns = [
{field: 'getFormattedDate()'},
//[...]
];
$http.post('/api/data/').success(function (data) {
$scope.gridOptions.data = data.elements;
$scope.gridOptions.data.forEach(function(row) {
row.getFormattedDate = function() {
return '42';
}
})
});
Run Code Online (Sandbox Code Playgroud)
还有更好的建议吗?
(我为这个问题做了一个SSCCE.)
我有2个简单的实体:Employee和Company.与默认获取策略(渴望)Employee有@ManyToOne关系Company.
我希望能够Employee在Company不更改的情况下加载the 而不更改在中定义的获取策略,Employee因为我只需要为一个用例执行此操作.
JPA的实体图似乎是为了这个目的.
所以我@NamedEntityGraph在课堂上定义了一个Employee:
@Entity
@NamedEntityGraph(name = "employeeOnly")
public class Employee {
@Id
private Integer id;
private String name;
private String surname;
@ManyToOne
private Company company;
//Getters & Setters
Run Code Online (Sandbox Code Playgroud)
和EmployeeRepository这样的:
public interface EmployeeRepository extends CrudRepository<Employee, Integer> {
@EntityGraph(value = "employeeOnly", type = EntityGraph.EntityGraphType.FETCH)
List<Employee> findByCompanyId(Integer companyId);
}
Run Code Online (Sandbox Code Playgroud)
尽管使用了@EntityGraph,我可以在日志中看到Company仍然由hibernate加载:
2016-11-07 23:16:08.738 …Run Code Online (Sandbox Code Playgroud) 我试图在threejs场景中有一些相机控制.
我看了一下这个例子,似乎用这些行完全处理了它:
controls = new THREE.TrackballControls( camera );
controls.rotateSpeed = 1.0;
controls.zoomSpeed = 1.2;
controls.panSpeed = 0.8;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
Run Code Online (Sandbox Code Playgroud)
这些线路使用THREE.TrackballControls来自js/controls/TrackballControls.js
我的问题是:究竟是TrackballControls.js什么?我在threejs下载包中找不到它.这是一个扩展吗?我在哪里可以找到它?(除了直接从示例的文件中获取)
我想用JodaTime获得当前的周数.
在法国,周定义如下:
示例:2012年1月1日是星期日.因此,
使用JodaTime,我发现我可以使用以下方法获取周数DateTime#getWeekOfWeekyear().
我认为通过指定正确的TimeZone,我会得到一个本地化的结果:
DateTime dtFr = new DateTime(2012, 1, 1, 11,11, DateTimeZone.forTimeZone(TimeZone.getTimeZone("Europe/Paris")));
DateTime dtUS = new DateTime(2012, 1, 1, 11,11, DateTimeZone.forTimeZone(TimeZone.getTimeZone("US/Arizona")));
LOGGER.info("weekYear (FR) : " + dtFr.weekyear().get());
LOGGER.info("weekOfWeekYear (FR) : " + dtFr.getWeekOfWeekyear());
LOGGER.info("weekYear (US) : " + dtUS.weekyear().get());
LOGGER.info("weekOfWeekYear (US) : " + dtUS.getWeekOfWeekyear());
Run Code Online (Sandbox Code Playgroud)
输出是:
2014-03-05 11:28:08,708 - INFO - c.g.s.u.JodaTest - weekYear (FR) : 2011
2014-03-05 11:28:08,709 …Run Code Online (Sandbox Code Playgroud) 我使用Jaxb2和Spring.我正在尝试解组由我的两个客户发送的一些XML.
到目前为止,我只需要处理一个发送了一些像这样的xml的客户:
<foo xmlns="com.acme">
<bar>[...]</bar>
<foo>
Run Code Online (Sandbox Code Playgroud)
绑定到这样的POJO:
@XmlType(name = "", propOrder = {"bar"})
@XmlRootElement(name = "Foo")
public class Foo {
@XmlElement(name = "Bar")
private String bar;
[...]
}
Run Code Online (Sandbox Code Playgroud)
我发现之前的开发人员在unmarshaller中硬编码了命名空间以使其工作.
现在,第二个客户发送相同的XML但更改名称空间!
<foo xmlns="com.xyz">
<bar>[...]</bar>
<foo>
Run Code Online (Sandbox Code Playgroud)
显然,unmarshaller没有解组,因为它期望一些{com.acme}foo而不是{com.xyz}foo.不幸的是,要求客户更改XML不是一种选择.
我尝试了什么:
1)在application-context.xml,我搜索了一个配置,它允许我忽略命名空间但找不到:
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="packagesToScan">
<list>
<value>com.mycompany.mypkg</value>
</list>
</property>
<property name="marshallerProperties">
<map>
<entry key="???"><value type="java.lang.Boolean">false</value></entry>
</map>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
似乎唯一可用的选项是Jaxb2Marshaller的Javadoc中列出的选项:
/**
* Set the JAXB {@code Marshaller} properties. These properties will be set on the
* underlying …Run Code Online (Sandbox Code Playgroud) java ×6
angular ×1
angular6 ×1
angularjs ×1
csrf ×1
hibernate ×1
java-8 ×1
java-stream ×1
javascript ×1
jaxb ×1
jodatime ×1
spring ×1
spring-data ×1
three.js ×1
typescript ×1
x-xsrf-token ×1