对于公共博客,我们目前使用默认的富文本编辑器。这作为内容编辑器不是 html 作家。
现在在某个帖子/自定义页面上,我们想要使用 html 表添加表格数据。tumblr 中的富文本编辑器不支持创建表格,所以我们切换到 html 编辑器。在那里我们创建了表格标签和一些行。在保存帖子之前,一切看起来都很好。保存表格元素似乎消失了......
在使用任何REST框架(jersey,resteasy,spring-mvc)时,(持久性)模型类与公开的REST资源表示形式不同.即使大多数时候,传入的json表示(例如创建和更新)与传出的json表示(例如list,get,..)不同.
我正在寻找一些好的命名约定来解决这个问题.
结构示例:
+-- my.comp.domain.Customer
+-- my.comp.rest.resource.CustomerResource (or CustomerController)
Run Code Online (Sandbox Code Playgroud)
CustomerResource将在内部使用Customer来持久化和检索数据.但是对于外部(Request + Response对象),它将使用一点点不同的结构.
我现在做的是:
+-- my.comp.rest.representation.CustomerRequest
+-- my.comp.rest.representation.SimpleCustomerResponse
+-- my.comp.rest.representation.SimpleCustomerCollectionResponse
+-- my.comp.rest.representation.ExtendedCustomerResponse
Run Code Online (Sandbox Code Playgroud)
这些基本上都是简单的POJO,只包含字段.使用的REST框架将使用它们将其转换为json.
其他人使用不同的namings?我愿意接受建议.
是否可以为通过MockMvc的所有请求(获取,发布,放置,删除)设置servlet路径?
Spring派发servlet映射到/ rest / *,但是在我的测试中,我必须删除url中的/ rest部分,否则Spring测试无法识别控制器。
编辑
@Sotirios:
可能是这样的:
public class MyWebTests {
private MockMvc mockMvc;
@Before
public void setup() {
mockMvc = standaloneSetup(new AccountController())
.defaultRequest(get("/")
.contextPath("/app").servletPath("/main")
.accept(MediaType.APPLICATION_JSON).build();
Run Code Online (Sandbox Code Playgroud)
}}
但是我不知道如何为所有请求设置servlet路径。上面的代码来自http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/testing.html。
还是只能使用standaloneSetup定义servletPath?
我最终得到了很多代码:
<section layout:fragment="content" th:remove="tag">
<p>content section</p>
</section>
Run Code Online (Sandbox Code Playgroud)
和
<section th:switch="${session['SOME_KEY'" th:remove="tag">
<section th:case="${'BadCredentialsException'}" th:remove="tag">
Invalid username/password
</section>
<section th:case="${'UsernameNotFoundException'}" th:remove="tag">
Invalid username/password
</section>
<section th:case="${'DisabledException'}" th:remove="tag">
Account is blocked, contact your admin
</section>
<section th:case="*" th:remove="tag">
Something went wrong
</section>
</section>
Run Code Online (Sandbox Code Playgroud)
请注意th:remove ="tag"不显示本案例中的部分标签,因为我没有将它们印在上面.
这是正确的方法吗?
虽然我提出了问题https://github.com/spring-projects/spring-boot/issues/662来提供spring-boot-starter-liquibase-starter模块,但今天我发现已经存在某种集成.
Spring Boot已经包含https://github.com/spring-projects/spring-boot/tree/master/spring-boot/src/main/java/org/springframework/boot/liquibase以及Spring Boot Liquibase特定服务定位器.从这段代码和Spring Boot参考指南中我无法弄清楚Spring Boot已经提供了什么.
但是我也发现当添加Gradle依赖"org.liquibase:liquibase-core"(注意没有版本号)时它会自动解析liquibase 3.1.1,所以Spring Boot特定的依赖解析器在这里做了一些"魔术".
任何人都知道Spring Boot在Liquibase方面提供什么样的集成?我想在启动应用程序期间自动执行迁移(如果需要).
为了简化内部开发,我正在考虑为 Spring Boot 开发一个薄层/客户启动器。这个自定义启动程序仅依赖于一些启动启动程序和我们需要的其他一些依赖项(外部和内部)。
不管怎样,我想做的下一步是这个自定义启动器包含一个 application.properties 配置,其中包含我们想要在项目中应用的默认设置。我希望自动获取此配置文件,而无需明确引用它。当然,应该可以覆盖实际项目中的属性。
Boot 是否已经提供了一些可以轻松实现的功能?
注意:我已经有了扩展 Boot 的 SpringApplication 的“自定义”应用程序;所以如果我能这样配置就没有问题了。
我正在测试一个Spring控制器,它可以回馈400字段错误.这些字段错误是包含"路径"和"消息"字段的对象数组.
现在我想测试一些特定的调用返回具有特定路径和消息的多个错误.
我无法接近下面的任何东西:
.andExpect(jsonPath("$.fieldErrors[*].path", containsInAnyOrder("title", "description")))
.andExpect(jsonPath("$.fieldErrors[*].message", containsInAnyOrder(
"The maximum length of the description is 500 characters.",
"The maximum length of the title is 100 characters.")));
Run Code Online (Sandbox Code Playgroud)
但这使得选项保持开放,即"路径"和"消息"的错误组合被接受.
有任何想法如何改进jsonpath来测试这个?
想象一下,REST端点(/employees)以JSON HAL格式提供员工页面.一名员工住在一个居住在非洲大陆的国家.
对于国家和大陆而言,也有单独的端点.
返回的页面包含_embedded具有员工数据的典型字段.员工资源还包含嵌套country资源.这个嵌套country资源也包含_links.
在这种情况下,输出将是:
GET /employees
{
"_embedded": {
"employees": [{
"employee_id": 1
"name": "Mr. X",
"place_name": "London",
"country": {
"alpha2_code": "AU",
"name": "Australia",
"continent": {
"code": "OC",
"name": "Australia",
"_links": {
"self": {
"href": "http://localhost:8077/continents/au"
}
}
},
"_links": {
"self": {
"href": "http://localhost:8077/countries/au"
}
}
},
"_links": {
"self": {
"href": "http://localhost:8077/employees/1"
}
}
},
{
..
}
]
},
"_links": {
"first": {
"href": "http://localhost:8077/employees?page=1&size=10"
}, …Run Code Online (Sandbox Code Playgroud) 如https://cloud.google.com/appengine/docs/standard/java/tools/gradle-reference上所述,AppEngine Gradle插件提供如下配置:
appengine { // App Engine tasks configuration
run { // local (dev_appserver) configuration (standard environments only)
port = 8080 // default
}
deploy { // deploy configuration
stopPreviousVersion = true // default - stop the current version
promote = true // default - & make this the current version
}
}
Run Code Online (Sandbox Code Playgroud)
使用时,这样的配置应该如何build.gradlke.kts?
我当时在看AppEngine任务,但不知道将其连接到正确的Kotlin DSL设置。
编辑
当简单地将以上代码块添加到build.gradle.ktsIntelliJ时,会抱怨:
当从cml运行Gradle时我得到:
无法打开缓存目录azhqxsd1d4xoovq4o5dzec6iw(/Users/test/.gradle/caches/4.5/gradle-kotlin-dsl/azhqxsd1d4xoovq4o5dzec6iw)。内部错误:无法编译脚本,请参阅日志以获取详细信息
编辑2
在下面添加了plugins和buildscript块:
val kotlinVersion = property("kotlin.version")
val javaVersion …Run Code Online (Sandbox Code Playgroud) 对于@ManyToOneJPA 实体中的关系,我只对实际 id 引用感兴趣,而不是获取与该关系关联的整个模型。
以这些 Kotlin JPA 实体为例:
@Entity
class Continent(
@Id
var id: String,
var code: String,
var name: String
) : Comparable<Continent> {
companion object {
private val COMPARATOR = compareBy<Continent> { it.id }
}
override fun compareTo(other: Continent): Int {
return COMPARATOR.compare(this, other)
}
}
@Entity
class Country(
@Id
var id: String,
var alpha2Code: String,
var alpha3Code: String,
var name: String,
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "continent_id")
var continent: Continent
) : Comparable<Country> {
companion …Run Code Online (Sandbox Code Playgroud) spring ×3
spring-mvc ×3
kotlin ×2
rest ×2
spring-boot ×2
spring-test ×2
gradle ×1
hal ×1
hibernate ×1
html-table ×1
hypermedia ×1
jersey ×1
jpa ×1
json ×1
jsonpath ×1
liquibase ×1
proxy ×1
resteasy ×1
thymeleaf ×1
tumblr ×1