我需要在下面的Runnable Thread中访问Spring bean(featureService和uxService),但是我得到了null值,applicationContext因此我无法在Runnable中获得Spring bean.我想知道是否可以访问runnable中的spring bean?如果没有,请建议我另一种方法.
我正在使用Spring 4.0.6和Java 8
@Component
public class UserMenuUpdateTask implements Runnable, Serializable, ApplicationContextAware {
private static final long serialVersionUID = 3336518785505658027L;
List<User> userNamesList;
FeatureService featureService;
UXService uxService;
private ApplicationContext applicationContext;
public UserMegaMenuUpdateTask() {}
public UserMegaMenuUpdateTask(List<User> userNamesList) {
this.userNamesList = userNamesList;
}
@Override
public void run() {
try {
for (User user : userNamesList) {
featureService = (FeatureService) applicationContext.getBean("featureService");
uxService = (UxService) applicationContext.getBean("uxService");
//.........
}
} catch …Run Code Online (Sandbox Code Playgroud) 我找不到关于这个主题的很多信息.有人可以解释一下Hibernate session.getTransaction().begin(与session.beginTransaction()vs 之间的差异吗?session.beginTransaction().begin()
我有一个Map<String, List<Object>> multiFieldMap,我需要迭代它的值集并将值添加到multiFieldsList如下
public List<Object> fetchMultiFieldsList() {
List<Object> multiFieldsList = new ArrayList<Object>();
for (Entry<String, List<Object>> entry : multiFieldMap.entrySet()) {
String entityName = entry.getKey();
List<Object> ids = entry.getValue();
for (Object id : ids) {
Object entity = queryService.query(entityName, queryService.property("id").eq(id));
multiFieldsList.add(entity);
}
}
return multiFieldsList;
}
Run Code Online (Sandbox Code Playgroud)
我想知道这种方法可以进一步简化吗?
我有一个返回JSON对象的java类,我需要将这个JSON对象传递给gojs javascript,这里是我的gojs javascript文件的样本(gojs_org_view.js)
function init() {
var g = go.GraphObject.make; // for conciseness in defining templates
myDiagram = new go.Diagram("myDiagram"); // must be the ID or reference to div
var graygrad = g(go.Brush, go.Brush.Linear, { 0: "rgb(125, 125, 125)", 1: "rgb(86, 86, 86)", 1: "rgb(86, 86, 86)" });
var unassocArray =[{"id":"12" , "name":"Bugs Bunny", "title":"Head Bunny"},
{"id":"13" , "name":"Honey Bunny", "title":"Wife Bunny"},
{"id":"14" , "name":"Lola Bunny", "title":"Lil' Bunny"},
{"id":"15" , "name":"Mickey Mouse", "title":"Looney In Charge"}];
Run Code Online (Sandbox Code Playgroud)
//一些javascript代码...........
function save() {
var …Run Code Online (Sandbox Code Playgroud) 我有一个如下的html
<table class="ui-widget" id="lines">
<tbody>
<tr>
<th>Line Item Number</th>
<th>Line Item Date</th>
<th>Unit Cost</th>
<th>Number of Units</th>
<th>Line Item Total</th>
</tr>
<tr class="errortrue">
<td>1</td>
<td>20150301</td>
<td>1</td>
<td>1</td>
<td>4</td>
<td class="error">Line : 1 NULL Value is not in the defined list for LINE ITEM TAX TYPE</td>
<td class="error">Line : 1 INVOICE DATE is a required field</td>
<td class="error">Line : 1 BILLING START DATE is a required field</td>
</tr>
<tr class="">
<td>2</td>
<td>20150304</td>
<td>2</td>
<td>2</td>
<td>6</td>
</tr>
<tr class="errortrue">
<td>3</td>
<td>20150306</td>
<td>3</td> …Run Code Online (Sandbox Code Playgroud) 我有一个如下所示的网页Invoice numbers,当用户点击它时,它的详细信息被加载,iframe(id='invoiceFrame')在 IE中可以正常工作,但在 Chrome 中,除非调整窗口大小,否则不会加载 iframe
Google Chrome Version 42.0.2311.90 (Official Build) m (32-bit)
<script type="text/javascript">
function getUrlParameter(URL, param){
var paramTokens = URL.slice(URL.indexOf('?') + 1).split('&');
for (var i = 0; i < paramTokens.length; i++) {
var urlParams = paramTokens[i].split('=');
if (urlParams[0].endsWith(param)) {
return urlParams[1];
}
}
}
String.prototype.endsWith = function(pattern) {
var d = this.length - pattern.length;
return d >= 0 && this.lastIndexOf(pattern) === d;
};
function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}
jQuery(document).ready(function …Run Code Online (Sandbox Code Playgroud) 我有一个groovy列表如下
def certs = ['0xc1','0xc1','0xc1','0xc1','0xc2','0xc2','0xc3','0xc4','0xc4','0xc5','0xc5','0xc5','0xc5']
Run Code Online (Sandbox Code Playgroud)
我试图通过计数找到每个元素和组的出现.我试过了
certs.groupBy { it }.findAll { it.value.size() }
Run Code Online (Sandbox Code Playgroud)
但我得到以下输出
[0xc1:[0xc1, 0xc1, 0xc1, 0xc1], 0xc2:[0xc2, 0xc2], 0xc3:[0xc3], 0xc4:[0xc4, 0xc4], 0xc5:[0xc5, 0xc5, 0xc5, 0xc5]]
Run Code Online (Sandbox Code Playgroud)
相反,我期待下面
[0xc1:4, 0xc2:2, 0xc3:1, 0xc4:2, 0xc5:4]
Run Code Online (Sandbox Code Playgroud)
有人可以帮我弄这个吗?此外,我想在列表中找到最大出现在元素我的情况下它0xc1和0xc5
更新:
def myMap = certs.inject([:]) { m, x -> if (!m[x]) m[x] = 0; m[x] += 1; m }
def maxValue = myMap.values().max{it}
def myKeys = []
myMap.findAll{ it.value == maxValue }.each{myKeys << it?.key}
println myKeys // result = [0xc1:4, 0xc5:4]
//println myMap.sort …Run Code Online (Sandbox Code Playgroud) 下面是我用来做 wsimport 的 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dat</groupId>
<artifactId>digsig</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>digsig</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-xjc -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/endorsed</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.7</version>
<type>jar</type>
</artifactItem>
<artifactItem>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.9</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<goals> …Run Code Online (Sandbox Code Playgroud) 我们正在将log4j升级1.2.14到2.12.1,我的log4j2.properties文件如下
status = error
log4j2.appender.console.type = Console
log4j2.appender.console.name = LogToConsole
log4j2.appender.console.layout.type = PatternLayout
log4j2.appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
#log4j2.appender.file.type = File
#log4j2.appender.file.name = LogToFile
#log4j2.appender.file.fileName=logs/app.log
#log4j2.appender.file.layout.type=PatternLayout
#log4j2.appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
# Rotate log file
log4j2.appender.rolling.type = RollingRandomAccessFile
log4j2.appender.rolling.name = LogToRollingRandomAccessFile
log4j2.appender.rolling.fileName = ${server.home}/logs/server.log
log4j2.appender.rolling.filePattern = logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz
log4j2.appender.rolling.layout.type = PatternLayout
log4j2.appender.rolling.layout.pattern = %d %p %C{1.} [%t] %m%n
log4j2.appender.rolling.policies.type = Policies
log4j2.appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
log4j2.appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.rolling.policies.size.size=10MB
log4j2.appender.rolling.strategy.type …Run Code Online (Sandbox Code Playgroud) 我有下面的 JSON
"Choices": [
{
"choiceId": "1"
},
{
"choiceId": "2",
"choiceType": null
}
]
Run Code Online (Sandbox Code Playgroud)
下面是 POJO,我需要两个构造函数,因为如果 json 中没有,choiceType我需要将其默认为Yes,如果 choiceTypejson 中存在null值,那么它不应该默认为Yes
@Getter
@ToString
@Setter
@NoArgsConstructor
public class Choices {
@JsonProperty("choiceId")
@NonNull
private String choiceId;
@JsonProperty("choiceType")
private String choiceType;
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public Choices(@JsonProperty("choiceId") String choiceId) {
this.choiceType = choiceType !=null ? choiceType : "Yes";
this.choiceId = choiceId;
}
public Choices(@JsonProperty("choiceId") String choiceId, @JsonProperty("choiceType") String choiceType) {
this.choiceType = choiceType;
this.choiceId = …Run Code Online (Sandbox Code Playgroud) java ×6
javascript ×3
jquery ×3
collections ×2
html ×2
java-8 ×2
build ×1
css ×1
gojs ×1
groovy ×1
hibernate ×1
iframe ×1
jackson ×1
json ×1
jsp ×1
lambda ×1
log4j ×1
log4j2 ×1
maven ×1
primefaces ×1
spring ×1
spring-boot ×1
spring-mvc ×1
transactions ×1
wsimport ×1