我有一个方法,我遍历List并创建List.在这样做时,我调用一个方法(createResult)来给一个Result也抛出CustomException,我将它包装为ResultClassException.但我一直收到一个错误,指出未处理的异常.
我的代码:
private List<Result> getResultList(List<String> results) throws ResultClassException {
List<Result> resultList = new ArrayList<>();
results.forEach(
(resultName) -> {
if (!resultRepository.contains(resultName)) {
try {
final Result result = createResult(resultName);
resultList.add(result);
} catch (CustomException e) {
throw new ResultClassException("Error",e);
}
} else {
resultList.add(resultRepository.get(resultName));
log.info("Result {} already exists.", resultName);
}
}
);
return Collections.unmodifiableList(resultList);
}
Run Code Online (Sandbox Code Playgroud)
有人能说出我做错了什么吗?
我有2个方法,它执行80%相同的工作,但结果处理不同.我在做 :
private <T> T getResponse(final RestURI query, final Class<T> responseClass) throws IOException {
T response = null;
final RestResponse<Record> tempResponse = getResponseFromDataPath(query);
if (isResponseOK(tempResponse, query)) {
final CustomReader reader = createCustomReaderFromResponse(tempResponse);
response = objectMapper.readValue(reader, responseClass);
^
// DIFFERENCE --------------------------------|
}
return response;
}
private <T> T getResponse(final RestURI query, final TypeReference valueTypeRef) throws IOException {
T response = null;
final RestResponse<Record> tempResponse = getResponseFromDataPath(query);
if (isResponseOK(tempResponse, query)) {
final CustomReader reader = createCustomReaderFromResponse(tempResponse);
response = objectMapper.readValue(reader, valueTypeRef);
^
// …Run Code Online (Sandbox Code Playgroud) 如何使用java 8流更新Map?至于现在我在做:
Map<String, Integer> testMap = Maps.newHashMap();
for(Map.Entry<String,Integer> testEntrySet : testCounts.entrySet()) {
String name = Utils.cleanName(testEntrySet.getKey());
if(testMap.containsKey(name)) {
testMap.put(name, testMap.get(name) +
testCounts.get(testEntrySet.getKey()));
} else {
testMap.put(name, testCounts.get(testEntrySet.getKey()));
}
}
return testMap;
}
Run Code Online (Sandbox Code Playgroud) 我有一个对象,其中包含一个 id 和该 id 的一些属性。
public class Data {
private String id;
private String name;
private String value;
}
Run Code Online (Sandbox Code Playgroud)
目前我已在请求对象中将其定义为:
public class Request {
private List<Data> dataList;
}
Run Code Online (Sandbox Code Playgroud)
如果我知道我可能永远不会在请求中遇到相同的 id(内容),那么 List 与 Set 是否会有任何区别。
总的来说,对于这个用例,哪个更好?列表 vs 集合?
我是棱角分明的新手.我有带输入文本框的搜索页面来搜索customerId,但我想添加一个功能,我可以根据url字符串进行搜索.
例如,我的网址是:
http://localhost:8080/#/search
Run Code Online (Sandbox Code Playgroud)
但我需要类似的东西
http://localhost:8080/#/search?ACC34ff
Run Code Online (Sandbox Code Playgroud)
http:// localhost:8080 /#/ search?CustomerId以便我可以在url中基于customerId进行搜索
有人可以告诉我如何添加查询字符串?
app.config(['$routeProvider',
function($routeProvider) {
$routeProvider
.when('/home', {
templateUrl: 'partials/home.html',
controller: 'homePageCtrl',
reloadOnSearch: true
}).when('/features', {
templateUrl: 'partials/features.html',
controller: 'featuresCtrl',
reloadOnSearch: false
}).when('/search', {
templateUrl: 'partials/search.html',
controller: 'searchCtrl',
reloadOnSearch: false
}).otherwise({
redirectTo: '/home'
});
}]);
Run Code Online (Sandbox Code Playgroud)
控制器:
appControllers.controller('searchCtrl', ['$scope','$route','$filter', '$http', '$location','$window','$timeout',
function($scope, $route, $filter, $http, $location, $window, $timeout) {
$scope.searchCustomerFeatures = function () {
if($scope.customerId != null) {
$http.get('/getCustomerFeatures.do', {params: {'customerId': $scope.customerId}}).success(function (data) {
$scope.featuresJson = angular.toJson(data, true);
});
}
}
}]); …Run Code Online (Sandbox Code Playgroud) java ×4
java-8 ×2
java-stream ×2
angularjs ×1
arrays ×1
coding-style ×1
exception ×1
javascript ×1
list ×1
location ×1
object ×1
query-string ×1
set ×1
throws ×1
url ×1