根据Spring 文档,使用Spring JdbcTemplate的步骤如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- Scans within the base package of the application for @Components to configure as beans -->
<context:component-scan base-package="org.springframework.docs.test" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<context:property-placeholder location="jdbc.properties"/>
</beans>
Run Code Online (Sandbox Code Playgroud)
然后,
@Repository
public class JdbcCorporateEventDao implements CorporateEventDao {
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
// JDBC-backed implementations …Run Code Online (Sandbox Code Playgroud) 我对PersonDTO有以下定义:
public class PersonDTO
{
private String id
private String firstName;
private String lastName;
private String maritalStatus;
}
Run Code Online (Sandbox Code Playgroud)
这是一个示例记录:
{
"id": 1,
"firstName": "John",
"lastName": "Doe",
"maritalStatus": "married"
}
Run Code Online (Sandbox Code Playgroud)
现在,John Doe离婚了.所以我需要向这个URL发送一个PATCH请求:
http://localhost:8080/people/1
Run Code Online (Sandbox Code Playgroud)
使用以下请求正文:
{
"maritalStatus": "divorced"
}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚该怎么做.这是我到目前为止尝试的内容:
// Create Person
PersonDTO person = new PersonDTO();
person.setMaritalStatus("Divorced");
// Create HttpEntity
final HttpEntity<ObjectNode> requestEntity = new HttpEntity<>(person);
// Create URL (for eg: localhost:8080/people/1)
final URI url = buildUri(id);
ResponseEntity<Void> responseEntity = restTemplate.exchange(url, HttpMethod.PATCH, requestEntity, Void.class);
Run Code Online (Sandbox Code Playgroud)
以下是上述问题:
1)由于我只设置MaritalStatus,其他字段都将为null.因此,如果我打印出请求,它将如下所示:
{
"id": null,
"firstName": …Run Code Online (Sandbox Code Playgroud) 我即将开始在Java中使用新的rest api进行开发.我的问题是关于PATCH的使用 - 为什么?
可以说,我们有一个名为Address.java的实体
public class Address {
@Id
private Long id
@NotNull
private String line1;
private String line2; //optional
@NotNull
private String city;
@NotNull
private String state;
}
Run Code Online (Sandbox Code Playgroud)
要创建一个新地址,我会做这个http请求:
POST http://localhost:8080/addresses
Run Code Online (Sandbox Code Playgroud)
满足以下要求:
{
"line1" : "mandatory Address line 1",
"line2" : "optional Address line 2",
"city" : "mandatory City",
"state" : "cd"
}
Run Code Online (Sandbox Code Playgroud)
假设创建的记录具有id 1
相应的@RestController AddressResource.java将具有以下方法:
@PostMapping(value = "/addresses")
public ResponseEntity<Address> create(@valid Address newAddress) {
addressRepo.save(newAddress);
}
Run Code Online (Sandbox Code Playgroud)
@valid将确保在将数据存储到表中之前实体有效.
现在假设,我从上面的公寓搬到街上的房子.如果我使用PATCH,它就会变成
PATCH http://localhost:8080/addresses/1
Run Code Online (Sandbox Code Playgroud)
请求有效负载:
{
"line1" : "1234 NewAddressDownTheStreet …Run Code Online (Sandbox Code Playgroud) 我的java模块从大型机获取一个巨大的输入xml.不幸的是,大型机无法跳过可选元素,结果我在输入中得到了很多空标记:
所以,
<SSN>111111111</SSN>
<Employment>
<Current>
<Address>
<line1/>
<line2/>
<line3/>
<city/>
<state/>
<country/>
</Address>
<Phone>
<phonenumber/>
<countryCode/>
</Phone>
</Current>
<Previous>
<Address>
<line1/>
<line2/>
<line3/>
<city/>
<state/>
<country/>
</Address>
<Phone>
<phonenumber/>
<countryCode/>
</Phone>
</Previous>
</Employment>
<MaritalStatus>Single</MaritalStatus>
Run Code Online (Sandbox Code Playgroud)
应该:
<SSN>111111111</SSN>
<MaritalStatus>SINGLE</MaritalStatus>
Run Code Online (Sandbox Code Playgroud)
我使用jaxb解组大型机发送的输入xml字符串.是否有一种干净/简单的方法来删除所有空组标签,或者我必须在每个元素的代码中执行此操作.我的输入xml中有超过350个元素,所以如果jaxb本身有办法自动执行此操作,我会很喜欢它吗?
谢谢,SGB
现在,我需要在SINGLE服务器上同时运行三个实例--Dev,QA,UAT.
这种情况的域模式是?我的结论是,事实并非如此.该域模式是跨多个服务器管理JVM.例如,如果我希望QA在server1和server2中.那是对的吗?
但是,我的需要是不要跨多个服务器管理JBOSS实例.
鉴于我应该使用独立模式吗?如果是这样,我将如何同时运行三个JBOSS(Dev,QA和UAT)实例.
我尝试了这里给出的说明(方法2):https://community.jboss.org/wiki/MultipleInstancesOfJBossAS7OnTheSameMachine
但我一直得到这样的错误:
MSC00001: Failed to start service jboss.serverManagement.controller.management.http: org.jboss.msc.service.StartException in service jboss.serverManagement.controller.management.http: Address already in use /127.0.0.1:9990
Run Code Online (Sandbox Code Playgroud)
有没有我可以遵循的简单教程.我看到这个问题被多次询问,但是他们似乎没有一个令人满意的答案......我发现它很有帮助.这是一种低级开发人员不应该单独在家中尝试的黑色艺术吗?
SGB
Spring Boot 默认允许LocalDate.
例如对于以下 DTO:
public class Person {
private LocalDate birthDate;
//getter & setters
}
Run Code Online (Sandbox Code Playgroud)
以下两种情况都是可以接受的:
{
"birthDate" : "2021-07-24"
}
Run Code Online (Sandbox Code Playgroud)
{
"birthDate" : "2021-07-24T17:00:00Z"
}
Run Code Online (Sandbox Code Playgroud)
Jackson 有一个lenient可以设置为拒绝日期和时间的标志:
@JsonFormat(pattern="uuuu-MM-dd", lenient = OptBoolean.FALSE)
private LocalDate birthDate;
Run Code Online (Sandbox Code Playgroud)
是否有相应的 Spring Boot 应用程序属性标志可以设置为全局应用于所有LocalDate字段,以便不需要将注释添加到每个LocalDate字段,也不需要像这样定义自定义反序列化器?
无法弄清楚在RedHat Linux中启动jboss EAP 6.1的正确方法.
nohup ./dev/jboss-eap-6.1/bin/standalone.sh 2>&1 < /dev/null &
Run Code Online (Sandbox Code Playgroud)
要么
nohup ./dev/jboss-eap-6.1/bin/standalone.sh 2>&1 > /dev/null &
Run Code Online (Sandbox Code Playgroud)
对我来说后者更有意义,但是当我用Google搜索时,我找到了第一个.
另外,以上是在服务器中启动jboss的正确方法之一,以便在我注销时不会退出吗?或者有更好的方法(比如sudo的东西)?
-SGB.
java ×4
spring ×3
jboss7.x ×2
api ×1
backend ×1
date-parsing ×1
installation ×1
jackson ×1
jaxb ×1
jboss ×1
jdbctemplate ×1
json ×1
linux ×1
nohup ×1
rest ×1
resttemplate ×1
spring-boot ×1
xml ×1