ios UIScrollView 里边放一个 UIStackView 该怎么设置 AutoLayout 约束 2019年7月11日 | Leave a comment 问题 UIScrollView 里边放一个 UIStackView 该怎么设置 AutoLayout 约束 &… Read More
swift toJson 2019年7月4日 | Leave a comment 问题: 解决: import Foundation func toJson(obj : Any) -> String?{ do { let aa = toObj(obj:obj) let jsonData = try JSONSerialization.data(withJSONObject: aa, options: []) let jsonString = String.init(data: jsonData, encoding: .utf8) return jsonString } catch { print(error) return nil } } func toObj(obj : Any) -> Any{ if let a = obj as? [Any] { var a2 = [Any]() for e in a { let d = toObj(obj: e) a2.append(d) } return a2 }else if obj is Int || obj is String || obj is Bool || obj is Float || obj is Double || obj is NSNull { return obj } else { let dic = toDictionary(obj: obj); if dic.count > 0 { return dic }else {////optional none return obj } } } func toDictionary(obj : Any) -> [String: Any] { var dictionary = [String: Any]() let otherSelf = Mirror(reflecting: obj) for child in otherSelf.children { guard let key = child.label else { continue } let v = child.value dictionary[key] = toObj(obj:v) } return dictionary } extension Dictionary { func floatValue(_ name:Dictionary.Key) ->Float?{ var ret : Float? = nil if let n = self[name] as? NSNumber { ret = n.floatValue }else if let f = self[name] as? Float { ret = f } return ret } } 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 import Foundation func toJson(obj : Any) -> String?{ do { let aa = toObj(obj:obj) let jsonData = try JSONSerialization.data(withJSONObject: aa, options: []) let jsonString = String.init(data: jsonData, encoding: .utf8) return jsonString } catch { print(error) return nil }}func toObj(obj : Any) -> Any{ if let a = obj as? [Any] { var a2 = [Any]() for e in a { let d = toObj(obj: e) a2.append(d) } return a2 }else if obj is Int || obj is String || obj is Bool || obj is Float || obj is Double || obj is NSNull { return obj } else { let dic = toDictionary(obj: obj); if dic.count > 0 { return dic }else {////optional none return obj } }} func toDictionary(obj : Any) -> [String: Any] { var dictionary = [String: Any]() let otherSelf = Mirror(reflecting: obj) for child in otherSelf.children { guard let key = child.label else { continue } let v = child.value dictionary[key] = toObj(obj:v) } return dictionary} extension Dictionary { func floatValue(_ name:Dictionary.Key) ->Float?{ var ret : Float? = nil if let n = self[name] as? NSNumber { ret = n.floatValue }else if let f = self[name] as? Float { ret = f } return ret }} … Read More
如何定制 spring security 403 返回的错误 2019年7月1日 | Leave a comment 问题: 默认返回的 解决: [crayon-6934b0afb098… Read More
【转】什么是服务治理平台? 2019年6月21日 | Leave a comment https://blog.csdn.net/simplemurrina/article/details/841… Read More
【转】浅谈服务治理与微服务 2019年6月21日 | Leave a comment https://www.cnblogs.com/scode2/p/8820155.html 近期… Read More
private static enum StoreFieldSetMapper implements FieldSetMapper 这种写法少见呢 2019年6月19日 | Leave a comment /* * Copyright 2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package example.stores; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import lombok.extern.slf4j.Slf4j; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.file.FlatFileItemReader; import org.springframework.batch.item.file.mapping.DefaultLineMapper; import org.springframework.batch.item.file.mapping.FieldSetMapper; import org.springframework.batch.item.file.separator.DefaultRecordSeparatorPolicy; import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.data.geo.Point; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.stereotype.Component; import org.springframework.validation.BindException; /** * Component initializing a hand full of Starbucks stores and persisting them through a {@link StoreRepository}. * * @author Oliver Gierke */ @Slf4j @Component public class StoreInitializer { @Autowired public StoreInitializer(StoreRepository repository) throws Exception { if (repository.count() != 0) { return; } List<Store> stores = readStores(); log.info("Importing {} stores into MongoDB…", stores.size()); repository.saveAll(stores); log.info("Successfully imported {} stores.", repository.count()); } /** * Reads a file {@code starbucks.csv} from the class path and parses it into {@link Store} instances about to * persisted. * * @return * @throws Exception */ public static List<Store> readStores() throws Exception { ClassPathResource resource = new ClassPathResource("starbucks.csv"); Scanner scanner = new Scanner(resource.getInputStream()); String line = scanner.nextLine(); scanner.close(); FlatFileItemReader<Store> itemReader = new FlatFileItemReader<Store>(); itemReader.setResource(resource); // DelimitedLineTokenizer defaults to comma as its delimiter DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(); tokenizer.setNames(line.split(",")); tokenizer.setStrict(false); DefaultLineMapper<Store> lineMapper = new DefaultLineMapper<Store>(); lineMapper.setLineTokenizer(tokenizer); lineMapper.setFieldSetMapper(StoreFieldSetMapper.INSTANCE); itemReader.setLineMapper(lineMapper); itemReader.setRecordSeparatorPolicy(new DefaultRecordSeparatorPolicy()); itemReader.setLinesToSkip(1); itemReader.open(new ExecutionContext()); List<Store> stores = new ArrayList<>(); Store store = null; do { store = itemReader.read(); if (store != null) { stores.add(store); } } while (store != null); return stores; } private static enum StoreFieldSetMapper implements FieldSetMapper<Store> { INSTANCE; /* * (non-Javadoc) * @see org.springframework.batch.item.file.mapping.FieldSetMapper#mapFieldSet(org.springframework.batch.item.file.transform.FieldSet) */ @Override public Store mapFieldSet(FieldSet fields) throws BindException { Point location = new Point(fields.readDouble("Longitude"), fields.readDouble("Latitude")); Address address = new Address(fields.readString("Street Address"), fields.readString("City"), fields.readString("Zip"), location); return new Store(fields.readString("Name"), address); } } } 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 /* * Copyright 2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package example.stores; import java.util.ArrayList;import java.util.List;import java.util.Scanner; import lombok.extern.slf4j.Slf4j; import org.springframework.batch.item.ExecutionContext;import org.springframework.batch.item.file.FlatFileItemReader;import org.springframework.batch.item.file.mapping.DefaultLineMapper;import org.springframework.batch.item.file.mapping.FieldSetMapper;import org.springframework.batch.item.file.separator.DefaultRecordSeparatorPolicy;import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;import org.springframework.batch.item.file.transform.FieldSet;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.core.io.ClassPathResource;import org.springframework.data.geo.Point;import org.springframework.data.mongodb.core.MongoOperations;import org.springframework.stereotype.Component;import org.springframework.validation.BindException; /** * Component initializing a hand full of Starbucks stores and persisting them through a {@link StoreRepository}. * * @author Oliver Gierke */@Slf4j@Componentpublic class StoreInitializer { @Autowired public StoreInitializer(StoreRepository repository) throws Exception { if (repository.count() != 0) { return; } List<Store> stores = readStores(); log.info("Importing {} stores into MongoDB…", stores.size()); repository.saveAll(stores); log.info("Successfully imported {} stores.", repository.count()); } /** * Reads a file {@code starbucks.csv} from the class path and parses it into {@link Store} instances about to * persisted. * * @return * @throws Exception */ public static List<Store> readStores() throws Exception { ClassPathResource resource = new ClassPathResource("starbucks.csv"); Scanner scanner = new Scanner(resource.getInputStream()); String line = scanner.nextLine(); scanner.close(); FlatFileItemReader<Store> itemReader = new FlatFileItemReader<Store>(); itemReader.setResource(resource); // DelimitedLineTokenizer defaults to comma as its delimiter DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(); tokenizer.setNames(line.split(",")); tokenizer.setStrict(false); DefaultLineMapper<Store> lineMapper = new DefaultLineMapper<Store>(); lineMapper.setLineTokenizer(tokenizer); lineMapper.setFieldSetMapper(StoreFieldSetMapper.INSTANCE); itemReader.setLineMapper(lineMapper); itemReader.setRecordSeparatorPolicy(new DefaultRecordSeparatorPolicy()); itemReader.setLinesToSkip(1); itemReader.open(new ExecutionContext()); List<Store> stores = new ArrayList<>(); Store store = null; do { store = itemReader.read(); if (store != null) { stores.add(store); } } while (store != null); return stores; } private static enum StoreFieldSetMapper implements FieldSetMapper<Store> { INSTANCE; /* * (non-Javadoc) * @see org.springframework.batch.item.file.mapping.FieldSetMapper#mapFieldSet(org.springframework.batch.item.file.transform.FieldSet) */ @Override public Store mapFieldSet(FieldSet fields) throws BindException { Point location = new Point(fields.readDouble("Longitude"), fields.readDouble("Latitude")); Address address = new Address(fields.readString("Street Address"), fields.readString("City"), fields.readString("Zip"), location); return new Store(fields.readString("Name"), address); } }} &… Read More
【未解决】springboot bean init-method 不灵光呢 2019年6月14日 | Leave a comment 问题: 下列代码不会调用 init 方法 @Component //@RequestScope @Scope(scopeName = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS) public class RequestOpContext implements InitializingBean { int i = 0; public RequestOpContext(){ System.out.println("RequestOpContext()"); } public void init(){ System.out.println("init"); i=10; } public int getId(){ return i; } @Override public void afterPropertiesSet() throws Exception { init(); } } 1234567891011121314151617181920212223 @Component//@RequestScope@Scope(scopeName = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS)public class RequestOpContext implements InitializingBean { int i = 0; public RequestOpContext(){ System.out.println("RequestOpContext()"); } public void init(){ System.out.println("init"); i=10; } public int getId(){ return i; } @Override public void afterPropertiesSet() throws Exception { init(); }} &… Read More
【转】解决sourceforge下载速度慢畅快下载sourceforge开源软件 2019年6月11日 | Leave a comment https://chaihongjun.me/others/190.html &n… Read More
IDEA spring boot devtools 怎么使用 2019年6月6日 | Leave a comment 问题: IDEA devtools 不起作用了,改了类不会自动重新运行 解决: C… Read More