我有一个7列的表.我希望列具有以下宽度:
width=20%width=10%我创建了2个CSS类,每个宽度一个,我将它们分配给每个单元格.
我拥有的东西,这是行不通的.相反,宽度始终包含内容.如果我只放一个字母,比宽度会很小,如果我放大字符串,宽度会太大.我希望它不变.
CSS和HTML:
table {
width: 100%;
}
.ten {
width: 10%
}
.twenty {
width: 20%;
}Run Code Online (Sandbox Code Playgroud)
<table>
<tr>
<th class="ten">H1</th>
<th class="ten">H2</th>
<th class="ten">H3</th>
<th class="twenty">H4</th>
<th class="twenty">H5</th>
<th class="twenty">H6</th>
<th class="ten">H7</th>
</tr>
<tr>
<td class="ten">A1</td>
<td class="ten">A2</td>
<td class="ten">A3</td>
<td class="twenty">A4</td>
<td class="twenty">A5</td>
<td class="twenty">A6</td>
<td class="ten">A7</td>
</tr>
<tr>
<td class="ten">B1</td>
<td class="ten">B2</td>
<td class="ten">B3</td>
<td class="twenty">B4</td>
<td class="twenty">B5</td>
<td class="twenty">B6</td>
<td class="ten">B7</td>
</tr>
</table>Run Code Online (Sandbox Code Playgroud)
有人可以解释如何实现我想要的吗?
我正在编写一个Spring Boot应用程序.我编写了一个简单的控制器,只要命中端点就会调用它,但它仍然返回状态404而不是指定的返回值.
为HelloController
@Controller
public class MessageRequestController {
@RequestMapping(method = RequestMethod.GET, value = "/hello", produces = "application/json")
public String hello() {
System.out.println("Hit me!");
return "Hello, you!";
}
}
Run Code Online (Sandbox Code Playgroud)
现在每当我打电话时localhost:8080/hello,我都会看到控制台日志"Hit me!",但"Hello, you!"永远不会返回.邮差输出:
{
"timestamp": 1516953147719,
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/hello"
}
Run Code Online (Sandbox Code Playgroud)
Application.java
@SpringBootApplication
@ComponentScan({"com.sergialmar.wschat"}) // this is the root package of everything
@EntityScan("com.sergialmar.wschat")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud) 我已经阅读了几篇试图解释这一点的帖子,但我无法让它发挥作用。我有一个场景,其中JSON我的服务的输入可以是多个子类型。基本上,我有一个基类UserDto,然后ClientDto与OwnerDto这两者的延伸从UserDto.我想实现,该控制器能够解决的具体亚型UserDto到正确的类的对象。所以像这样的事情。
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public void doSomething(@RequestBody UserDto user) {
ClientDto client = (ClientDto) user;
// do something
}
Run Code Online (Sandbox Code Playgroud)
我试过这样的事情。基本上我想通过profileTypeenum 类型的字段来确定具体对象的类型ProfileType,值OWNER和CLIENT。
UserDto.java
@JsonTypeInfo(use = Id.CLASS, include = As.PROPERTY, property = "profileType", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = ClientDto.class, name = "Client"),
@JsonSubTypes.Type(value = OwnerDto.class, name = "Owner")
})
public class …Run Code Online (Sandbox Code Playgroud) 在尝试樱桃挑选时,我陷入了一个奇怪的循环中.这就是我的工作,以及问题所在.
我有两个分支:主线和临时.我想从主线到临时选择一个特定的提交.我这样做如下.
git checkout tempgit cherry pick <commit sha>Segmentation fault: 11我从2)重新运行命令,并得到: Unable to create ...git/index.lock': File exists
================================================== ==================
现在我跑了 rm -f ./.git/index.lock
再试一次 git cherry pick <commit sha>
现在我明白了:
错误:以下未跟踪的工作树文件将被merge:myfile.java覆盖
...对于一个甚至不存在的文件.我之前已经拥有它,但我将其重命名,因此该名称下的文件不在存储库中.
git status,现在我在未跟踪文件下看到文件myfile.java.现在它甚至出现在编辑器中.我可以从编辑器中删除它,但不能从git存储库中删除它.我明白了pathspec 'myfile.java' did not match any filescherry-pick然后我回到第3步).这里发生了什么,我怎么才能做我的樱桃挑选?:d
我有一节课Config:
Config.java
public class Config {
private final String p = "Prop";
@Bean
public String getP(){return p;}
}
Run Code Online (Sandbox Code Playgroud)
我如何将其注入一些构造函数,即:
public class SomeC {
private String p;
public SomeC(String p) {
this. p = p;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这个String p从Config注入值.那可能吗?
我在我的应用程序中设计了实体以遵循Hibernate 的继承策略Inheritance.JOINED。
基本抽象类是UserTable,具体派生类是ClientTable和OwnerTable。
我想要实现的目标是拥有一个存储库,我可以在其中通过or 进行find任何UserTable(ClientTable和OwnerTable)。重要的要求是,一旦它们被获取,它们就可以被强制转换为正确的类型,并且它们携带它们的特定字段(而不仅仅是从 继承的那些)。IdEmailUserTable
同样重要的是,我应该能够通过同一个存储库保存这些实体,即。repository.save(clientTable).
所以这样的事情应该是可能的:
UserTableRepository repository = // ...
int clientId = 3;
int ownerId = 5;
ClientTable clientTable = (ClientTable) repository.findByUserId(clientId);
OwnerTable clientTable = (OwnerTable) repository.findByUserId(ownerId);
clientTable = (ClientTable) repository.findByEmail(clientEmail);
ownerTable = (OwnerTable) repository.findByEmail(ownerEmail);
Run Code Online (Sandbox Code Playgroud)
我的实体看起来像这样。
用户表.java
@Entity
@Table(name = "USER")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class UserTable implements Serializable {
@Column(name = …Run Code Online (Sandbox Code Playgroud) 我有一个接收 JSON 的应用程序,收到后应该验证它。验证由几个步骤组成。
根据所描述的要求,如果违反任何约束,我应该生成自己的、专门格式化的验证报告对象。
我考虑了几种方法来做到这一点,但我对任何一种都不满意,希望得到你们的建议,如何做到这一点。我考虑过的:
@CustomConstraintIfAThenB // this should emulate the conditional dependency
public class Message {
@JsonProperty(value = "a", required = true)
@Size(min = 3, max = 8)
private String a;
@JsonProperty(value = "b", required = true)
@Size(min = 5, max = 9)
private String b;
// ...
}
Run Code Online (Sandbox Code Playgroud)
我发现这种方法的问题是在生成报告时,因为首先我需要使用 JacksonObjectMapper来尝试创建我的 POJO。如果这抛出,JsonProcessingException我应该解析它,并创建我的报告。如果没有抛出,只有这样我才能使用我的 bean 验证器进行验证(即。Hibernate)。
MyReport report = …Run Code Online (Sandbox Code Playgroud) 我对数据库开发还很陌生,所以也许这个问题并不完全正确,但如果有人能让我更清楚一点,我将不胜感激......我已经阅读了有关序列的所有内容,以及它们的首选方式超越身份。我有一个假设性问题。如果我要使用序列与 Hibernate(数据插入)和 Liquibase(模式创建)一起生成 PK,那么定义序列的正确位置是什么?
例如:类级别的序列生成。
用户.java
@Entity
@Table(name = "USER")
public class User {
@Id
@SequenceGenerator(name = "USER_SEQ", sequenceName = "USER_SEQ")
@GeneratedValue(strategy = SEQUENCE, generator = "USER_SEQ")
@Column(name = "ID")
private Long id;
// other fields
}
Run Code Online (Sandbox Code Playgroud)
或其他示例:模式级别的序列生成。
变更日志.xml
<changeSet author="wesleyy">
<createSequence catalogName="cat"
cycle="true"
incrementBy="1"
maxValue="1000"
minValue="10"
ordered="true"
schemaName="public"
sequenceName="user_seq"
startValue="1"/>
</changeSet>
Run Code Online (Sandbox Code Playgroud)
是否需要在 Liquibase 和 Hibernate 中定义序列?两者到底有什么区别?
我知道已经有类似的问题,但是看着它们,我仍然对应该如何设计代码有一些疑问。我有一项允许User 注册/登录/更新/删除的服务。事实是,它User是一种抽象类型,其中包含应typeOfUser基于其调用实际注册/更新/删除方法的数据,现在我在一个switch-case块中进行操作。我想用一些更好的设计代替它。
UserController.java
public class UserController {
public UserDto register(UserDto user) {
switch(user.getTypeOfUser()) {
case DRIVER: return driverService.register(user);
case CUSTOMER: return customerService.register(user);
// ...
}
}
public UserDto update(UserDto user) {
switch(user.getTypeOfUser) {
case DRIVER: return driverService.update((DriverDto) user);
case CUSTOMER: return customerService.update((CustomerDto) user);
// ...
}
}
public UserDto login(long userId) {
loginService.login(userId);
UserBO user = userService.readById(userId);
switch(user.getTypeOfUser) {
case DRIVER: return DriverDto.fromBO((DriverBO) user);
case CUSTOMER: return CustomerDto.fromBO((CustomerBO) user);
// …Run Code Online (Sandbox Code Playgroud) 我有一个 Gradle 项目,我正在尝试用 Jetty 运行它。我的build.gradle文件如下所示。
构建.gradle
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'jetty'
[jettyRun, jettyRunWar]*.httpPort = 8080
[jettyRun, jettyRunWar]*.contextPath = ''
[jettyRun, jettyRunWar]*.daemon = true
[jettyRun, jettyRunWar, jettyStop]*.stopPort = 8081
[jettyRun, jettyRunWar, jettyStop]*.stopKey = 'stop'
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceSets {
test {
java {
srcDirs = ['src/test/java']
}
}
}
dependencies {
compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.14'
compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.14'
compile 'com.google.guava:guava:14.0.1'
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-all:1.3'
testCompile 'org.mockito:mockito-all:1.10.19'
testCompile 'org.eclipse.jetty:jetty-server:9.4.7.v20170914'
testCompile 'org.eclipse.jetty:jetty-webapp:9.4.7.v20170914'
} …Run Code Online (Sandbox Code Playgroud) 我知道这里有一个类似的问题,但是并没有真正解决我的问题。简而言之,我希望我的一个字段依赖于另一个字段的值。但是对于某些值,我不要求任何字段。这是一个例子:
架构图
{
"definitions": {},
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"colour": {
"type": "string",
"enum": ["red", "black", "blue"]
},
"blackQuote": {
"type": "string",
"maxLength": 11
},
"redQuote": {
"type": "string",
"maxLength": 11
}
},
"oneOf": [
{
"properties": {
"colour": {"enum": ["red"]}
},
"required": ["redQuote"]
},
{
"properties": {
"colour": {"enum": ["black"]}
},
"required": ["blackQuote"]
}
],
"required": [
"colour"
]
}
Run Code Online (Sandbox Code Playgroud)
这是这样的:
我试图了解在 Kotlin 中以预定速率触发异步作业的最佳方式是什么,而应用程序通常正在运行它的正常任务。假设我有一个简单的应用程序,它每秒只打印出“...”,但每 5 秒我想要另一个作业/线程/协程(哪个最适合)来打印“你有一条消息!”。对于异步作业,我有一个类NotificationProducer,它看起来像这样。
class NotificationProducer {
fun produce() {
println("You have a message!")
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我的主要方法看起来像这样。
while (true) {
println("...")
sleep(1000)
}
Run Code Online (Sandbox Code Playgroud)
我应该使用GlobalScope.async,Timer().schedule(...)还是一些 Quartz 工作来实现我想要的?任何建议都非常感谢。关键是通知必须来自另一个类(例如 NotificationProducer)
我希望能够在运行时动态地为现有类(对象)设置属性。
例如,具有 接口MyProperty.java以及实现该接口的其他特定属性。然后拥有一个可以动态接收某个实例MyProperty并自动为其提供getter 的对象。
MyPropery.java [表示某些对象属性的接口]
public interface MyProperty {
String getValue();
}
Run Code Online (Sandbox Code Playgroud)
MyPropertyAge.java [一些特定的对象属性]
public class MyPropertyAge implements MyProperty {
private final String age;
public MyPropertyAge(String age) {
this.age = age;
}
@Override
public String getValue() {
return age;
}
}
Run Code Online (Sandbox Code Playgroud)
MyObject.java [应该动态具有 MyProperty getter 的对象]
public class MyObject {
public MyObject(Set<MyProperty> properties) {
// receive list of properties,
// and have getters for them
}
// For example, if I passed in a …Run Code Online (Sandbox Code Playgroud) java ×9
spring ×4
json ×3
hibernate ×2
inheritance ×2
asynchronous ×1
c# ×1
cherry-pick ×1
css ×1
eclipse ×1
git ×1
gradle ×1
html ×1
jackson ×1
jersey ×1
jetty ×1
jpa ×1
jsonschema ×1
kotlin ×1
liquibase ×1
polymorphism ×1
spring-mvc ×1
sql ×1
validation ×1
visitor ×1