问题有点夸夸其谈.我和同事就以下模式发生了争执:
@Component
public class MetaService {
public static UserService userService;
public static GroupService groupService;
public static PermissionService permissionService;
// ...more fields
@Autowired
public MetaService(UserService userService,
GroupService groupService
PermissionService permissionService) {
MetaService.userService = userService;
MetaService.groupService = groupService;
MetaService.permissionService = permissionService;
}
}
Run Code Online (Sandbox Code Playgroud)
基本上,MetaService是多个Spring bean @Service类的入口点/包装器.而且还有一个类似于bean类的MetaDao包装器@Repository:
@Component
public class MetaDao {
public static UserDao userDao;
public static GroupDao groupDao;
public static PermissionDao permissionDao;
// ...more fields
@Autowired
public MetaDao(UserDao userDao,
GroupDao groupDao,
PermissionDao permissionDao) { …Run Code Online (Sandbox Code Playgroud) java spring design-patterns dependency-injection anti-patterns
我正在尝试使用jOOQ和Kotlin并看到一些教程和文档,它看起来非常好.
但是如果jOOQ有一些非常烦人的东西就是代码生成.这似乎太复杂了,最终无法维持.我决定创建自己的表模型(类似于hibernate的工作原理).
我创建了两个表模型:
用户
data class User(
val id: String = UUID.randomUUID().toString(),
val name: String,
val email: String,
val password: String? = null
) {
companion object {
val TABLE: Table<Record> = DSL.table("user")
val ID: Field<String> = DSL.field("id", String::class.java)
val USER_NAME: Field<String> = DSL.field("user_name", String::class.java)
val EMAIL: Field<String> = DSL.field("email", String::class.java)
val PASSWORD: Field<String> = DSL.field("password", String::class.java)
}
}
Run Code Online (Sandbox Code Playgroud)
关注
data class Followers(
val id: String,
val followerId: String,
val userId: String
) {
companion object {
val TABLE: Table<Record> …Run Code Online (Sandbox Code Playgroud) 我正在使用 wordpress 并使用 CSS 通过添加填充使我的“关于”和“联系人”页面的宽度更加居中和更小。但是,当我这样做时,尤其是在移动视图中(我认为平板电脑还可以),因此两侧都有空白。
我正在使用的主题是按照我的想法构建的,我无法在该主题中真正找到使元素看起来更小宽度并以页面为中心的内容,因此我使用填充来使其显示为我想要的方式。
这是我网站的链接:http : //www.lisaweng.com/contact/
即使我添加了填充,是否有 CSS 可以使这些页面在移动视图上查看时显示正常或全宽,就像投资组合页面如何在移动设备上查看全宽,即使在屏幕两侧查看时在屏幕两侧都有空白桌面版?
对于用于填充“关于”和“联系方式”页面元素的 CSS 的 PS,我确实使用了百分比而不是像素。我不确定为什么在移动视图中查看时它不完全响应。
这是“关于”和“联系方式”页面的 CSS 样式:
.cf7_custom_style_1 {
padding-left: 20%;
padding-right: 20%;
}
Run Code Online (Sandbox Code Playgroud)
和
.aboutme {
padding-left: 14%;
padding-right: 14%;
}
Run Code Online (Sandbox Code Playgroud)
有没有代码可以解决这个问题?或者知道为什么会这样吗?如果有移动视图修复的代码,它是否也适用于平板电脑,还是平板电脑也有一个 CSS 来修复它应该如何响应?
Symfony版本:4.1
当我使用PHPUnit运行测试时,我有以下弃用消息:
从版本5.2开始,不推荐使用注释"Sensio\Bundle\FrameworkExtraBundle\Configuration\Route".请改用"Symfony\Component\Routing\Annotation\Route".
我想澄清我放入我的framework.yaml:
sensio_framework_extra:
router:
annotations: false
Run Code Online (Sandbox Code Playgroud)
我还想澄清use Sensio \ Bundle \ FrameworkExtraBundle \ Configuration \ Route我的控制器中没有.
我使用FOSRestBundle,我得到的印象是问题来自那里,但我试图修复FOSREST文档中提供的配置.
你有这种类型的错误和/或你知道我应该在哪里看吗?
我有一个对特定端点发出POST请求的代码。这段代码是使用Apache的HttpClient,我想开始使用HttpClientJava(JDK11)的本机代码。但是我不明白如何指定请求的参数。
这是我使用Apache Httpclient的代码:
var path = Path.of("file.txt");
var entity = MultipartEntityBuilder.create()
.addPart("file", new FileBody(path.toFile()))
.addTextBody("token", "<any-token>")
.build();
Run Code Online (Sandbox Code Playgroud)
和代码使用HttpClient:
var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
.uri(URI.create("https://myendpoint.com/"))
.POST( /* How can I set the parameters here? */ );
Run Code Online (Sandbox Code Playgroud)
如何设置file和token参数?
我正在阅读 Spring 文档,发现从创建子类ResponseEntityExceptionHandler是处理异常的好方法。但是,我尝试以不同的方式处理异常,因为我需要BusinessExceptions从TechnicalExceptions.
创建了一个BusinessFault封装异常详细信息的 bean :
业务故障.java
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonInclude(value = Include.NON_NULL)
public class BusinessFault {
@JsonProperty(value = "category")
private final String CATEGORY = "Business Failure";
protected String type;
protected String code;
protected String reason;
protected String description;
protected String instruction;
public BusinessFault(String type, String code, String reason) {
this.type = type;
this.code = code;
this.reason = reason;
}
public BusinessFault(String type, String code, String reason, String description, …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用 Room,在将数据插入我的数据库时,ConcurrentModificationException有时会抛出错误。为什么会这样呢?
我使用分页 api,在每次 api 调用后,我使用以下命令将 dataList 插入到我的数据库中
new Thread(new Runnable() {
@Override
public void run() {
appDatabase.dataDao().insertMultipleData(dataList);
}
}).start();
Run Code Online (Sandbox Code Playgroud)
在哪里
appDatabase = Room.databaseBuilder(context, AppDatabase.class, AppDatabase.DATABASE_NAME)
.fallbackToDestructiveMigration()
.build();
Run Code Online (Sandbox Code Playgroud)
插入操作
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertMultipleData(List<Data> dataList);
Run Code Online (Sandbox Code Playgroud) 我使用以下代码将 C# 中的 Guid 转换为 Base64:
var id = Guid.Parse("be9f1bb6-5c8e-407d-85a3-d5ef31f21b4d");
var base64=Convert.ToBase64String(id.ToByteArray());
Run Code Online (Sandbox Code Playgroud)
输出
thufvo5cfUCFo9XvMfIbTQ==
当我尝试使用以下命令在 Java 中执行相同操作时:
java.util.Base64.Encoder encoder=Base64.getEncoder();
UUID uuid = UUID.fromString("be9f1bb6-5c8e-407d-85a3-d5ef31f21b4d");
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
encoder.encodeToString(bb.array());
Run Code Online (Sandbox Code Playgroud)
输出不同
vp8btlyOQH2Fo9XvMfIbTQ==
我的 Java 代码做错了什么?如何才能获得与使用 C# 相同的结果?
我正在尝试在Mac OS上运行示例JavaFX应用程序.
的build.gradle
apply plugin: 'java'
apply plugin: 'application'
repositories {
mavenCentral()
}
dependencies {
compile "org.openjfx:javafx-base:11"
compile "org.openjfx:javafx-graphics:11"
compile "org.openjfx:javafx-controls:11"
}
compileJava {
doFirst {
println "CLASSPATH IS $classpath.asPath"
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.graphics'
]
classpath = files()
}
}
Run Code Online (Sandbox Code Playgroud)
Java类
package com.test;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;
public class HelloFX extends Application {
@Override
public void start(Stage stage) {
String javaVersion = System.getProperty("java.version");
String javafxVersion = System.getProperty("javafx.version");
Label l = new Label("Hello, JavaFX …Run Code Online (Sandbox Code Playgroud) 我有一个遗留代码,它有十几个数据库调用来填充报告,我试图减少使用CompletableFuture.
我怀疑我是否正确地做事并且没有过度使用这项技术。
我的代码现在看起来像这样:
在每个方法中使用许多数据库调用启动文档部分的异步填充
CompletableFuture section1Future = CompletableFuture.supplyAsync(() -> populateSection1(arguments));
CompletableFuture section2Future = CompletableFuture.supplyAsync(() -> populateSection2(arguments));
...
CompletableFuture section1oFuture = CompletableFuture.supplyAsync(() -> populateSection10(arguments));
Run Code Online (Sandbox Code Playgroud)然后我按特定顺序安排期货arrayList并加入所有期货以确保我的代码只有在所有期货都完成后才能进一步运行。
List<CompletableFuture> futures = Arrays.asList(
section1Future,
section2Future, ...
section10Future);
List<Object> futureResults = futures.stream()
.map(CompletableFuture::join)
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)然后我用它的碎片填充 PDF 文档本身
Optional.ofNullable((PdfPTable) futureResults.get(0)).ifPresent(el -> populatePdfElement(document, el));
Optional.ofNullable((PdfPTable) futureResults.get(1)).ifPresent(el -> populatePdfElement(document, el));
...
Optional.ofNullable((PdfPTable) futureResults.get(10)).ifPresent(el -> populatePdfElement(document, el));
Run Code Online (Sandbox Code Playgroud)
退回文件
我的担忧是:
1) 以这种方式创建和实例化许多 Completable Futures 是否可以?将它们按要求的顺序排序arrayList,加入它们以确保它们全部完成,然后通过将它们转换为特定对象来获得结果?
2) 可以不指定执行器服务而运行,而是依赖 commonForkJoinPool吗?但是,此代码在 Web 容器中运行,所以可能为了使用 JTA,我需要通过 JNDI 使用容器提供的线程池执行程序? …
java ×7
java-11 ×2
spring ×2
android ×1
android-room ×1
asynchronous ×1
base64 ×1
css ×1
gradle ×1
java-8 ×1
java-module ×1
javafx ×1
jooq ×1
kotlin ×1
mobile ×1
multipart ×1
php ×1
responsive ×1
spring-boot ×1
spring-rest ×1
sql ×1
symfony ×1
uuid ×1
wordpress ×1