我的应用程序中有一些不同颜色的开关控件,并且我使用多个自定义可绘制选择器来更改颜色.
随着AppCompat v21库的发布,引入了一个新的android.support.v7.widget.SwitchCompat控件.
是否可以在没有客户可绘制选择器的情况下以编程方式更改SwitchCompat的颜色,但是使用XML或代码?
我有下一个错误: nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.example.Model.entities, could not initialize proxy - no Session
我的Model实体:
class Model {
...
@OneToMany(fetch = FetchType.LAZY, mappedBy = "model", orphanRemoval = true)
@Cascade(CascadeType.ALL)
@Fetch(value = FetchMode.SUBSELECT)
public Set<Entity> getEntities() {
return entities;
}
public void addEntity(Entity entity) {
entity.setModel(this);
entities.add(entity);
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个服务类:
@Service
@Transactional
class ServiceImpl implements Service {
@Override
public void process(Model model) {
...
model.addEntity(createEntity());
...
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用其他服务方法调用服务:
@Override
@JmsListener(destination = …Run Code Online (Sandbox Code Playgroud) 我的控制器中有方法:
@RequestMapping(method = RequestMethod.POST)
public CustomObject createCustomObject(final @RequestHeader("userId") Long userId) {
...
}
Run Code Online (Sandbox Code Playgroud)
我可以编写一些自定义转换器或类似的东西来将此RequestHeader userId参数转换为User对象,因此我的方法将是:
@RequestMapping(method = RequestMethod.POST)
public CustomObject createCustomObject(final User user) {
...
}
Run Code Online (Sandbox Code Playgroud)
是否可以使用spring-mvc?
我在我的项目中使用Lombok库并且@Log4j2注释有问题.不知道为什么,但它没有产生的log领域class.
但是当我将注释更改为@Slf4j有效时,我可以在IntelliJ IDEA的"结构"选项卡中看到它.
我正在使用它gradle作为构建工具.几乎没有依赖"
dependencies {
compileOnly("org.projectlombok:lombok")
compile("org.springframework.boot:spring-boot-starter-log4j2")
}
Run Code Online (Sandbox Code Playgroud) 我为我的服务器生成了自签名证书.然后使用设置 - >安全性 - >安装将其添加到Android.
当我尝试使用应用程序连接到我的服务器时,我收到错误:
java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Run Code Online (Sandbox Code Playgroud)
据我所知,在我将证书添加到可信任之后它应该可以正常使用我的服务器,或者我可能会遗漏一些东西?这个想法是通过Android系统添加证书,不要更改应用程序代码.
顺便说一句,我OkHttpClient用于网络连接.也许我应该为https连接启用一些东西?
我有一个 url http://example.com/{x}/push/{y},我正在使用 OkHttp 卷曲它。
final HttpUrl httpUrl = HttpUrl
.parse("http://example.com/{x}/push/{y}")
.newBuilder()
???
.build();
Run Code Online (Sandbox Code Playgroud)
是否可以设置这些参数{x}和{y}路径参数?我可以看到类似的方法addPathSegment,这在某种程度上是相关的,但不是我想要的。
我有一种方法的服务:
@Service
public class DefaultTestService implements TestService {
private static final Logger LOGGER = Logger.getLogger(DefaultTestService.class);
@Autowired
private TestRepository testRepository;
@Transactional(readOnly = false, isolation = Isolation.SERIALIZABLE)
@Override
public void incrementAndGet(Long testModelId) {
LOGGER.debug("Transaction is active: " + TransactionSynchronizationManager.isActualTransactionActive());
final TestModel tm = testRepository.findOne(testModelId);
if (tm != null) {
LOGGER.debug("Updated " + testModelId + " from value: " + tm.getValue());
tm.setValue(tm.getValue() + 1);
testRepository.save(tm);
} else {
LOGGER.debug("Saved with id: " + testModelId);
final TestModel ntm = new TestModel();
ntm.setId(testModelId);
testRepository.save(ntm);
} …Run Code Online (Sandbox Code Playgroud) 我有Android应用程序工作正常,但几个小时前它开始Run 'app' click在Android Studio中显示我的错误:
Error:Execution failed for task ':app:transformClassesWithInstantRunForDebug'.
> org.objectweb.asm.tree.analysis.AnalyzerException: Execution can fall off end of the code
Run Code Online (Sandbox Code Playgroud)
如果我从控制台构建应用程序,就像gradle assembleRelease一切正常.
所以我的问题是如何解决这个问题,可能导致这个问题.它让我发疯,因为我无法从Android Studio启动我的应用程序.
顺便说一句:我已经尝试谷歌和许多关于multidex问题的答案,但我想这不是我的选择.
我有下一个 xml 文件
<xml name="Places">
<data>
<row Code="1" Name="#X1.A&B(City)" />
</data>
</xml>
Run Code Online (Sandbox Code Playgroud)
在执行 unmarshal 后,The reference to entity "B" must end with the ';' delimiter由于 Name 属性内的 & 符号,我收到异常。
JAXBContext jaxbContext = JAXBContext.newInstance(Root.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
File xml = new File("test2.xml");
Object obj = unmarshaller.unmarshal(xml);
Run Code Online (Sandbox Code Playgroud)
我怎样才能逃脱这些角色?
我已经尝试添加 CharacterEscapeHandler 但它不适用于 Unmarshaller
private static class EscapeHandler implements CharacterEscapeHandler {
@Override
public void escape(char[] buf, int start, int len, boolean isAttValue,
Writer out) throws IOException {
...
}
}
unmarshaller.setProperty("com.sun.xml.bind.marshaller.CharacterEscapeHandler", …Run Code Online (Sandbox Code Playgroud) 我最近开始研究Go并面临下一期.我想实现Comparable接口.我有下一个代码:
type Comparable interface {
compare(Comparable) int
}
type T struct {
value int
}
func (item T) compare(other T) int {
if item.value < other.value {
return -1
} else if item.value == other.value {
return 0
}
return 1
}
func doComparison(c1, c2 Comparable) {
fmt.Println(c1.compare(c2))
}
func main() {
doComparison(T{1}, T{2})
}
Run Code Online (Sandbox Code Playgroud)
所以我收到了错误
cannot use T literal (type T) as type Comparable in argument to doComparison:
T does not implement Comparable (wrong type for compare method)
have …Run Code Online (Sandbox Code Playgroud) java ×5
android ×4
spring ×3
okhttp ×2
go ×1
go-interface ×1
gradle ×1
hibernate ×1
jaxb ×1
jpa ×1
log4j2 ×1
lombok ×1
spring-data ×1
spring-mvc ×1
ssl ×1
switchcompat ×1
xml ×1