我在嵌入式项目中使用nlohmann json(现代 C++ 的 JSON) 。操作系统是Mongoose操作系统。Mongoose 有一个很好的配置系统,其中配置数据被处理并布置在 mos.yml 文件中。该文件在构建时被转换为结构和访问器函数。因此,我可以将配置数据作为结构获取,其中包含其他嵌套结构。我需要将其转换为 JSON。
我的理解是 nlohmann::json 能够将 JSON 与我自己的类型相互转换,我所要做的就是提供to_json()和from_json()方法,如下所述:
这个示例代码非常简单:
struct person {
std::string name;
std::string address;
int age;
};
void to_json(json& j, const person& p) {
j = json{{"name", p.name}, {"address", p.address}, {"age", p.age}};
}
Run Code Online (Sandbox Code Playgroud)
但给出的例子非常简单。我的类型更复杂,我无法弄清楚更复杂结构的语法,例如这个(为简洁起见摘录):
struct mgos_config_mytype {
struct mgos_config_mytype_input input;
struct mgos_config_mytype_speed speed;
/* many others omitted */
};
struct mgos_config_mytype_input {
struct mgos_config_mytype_input_wired_buttons wired_buttons;
};
struct mgos_config_mytype_input_wired_buttons {
const char * …Run Code Online (Sandbox Code Playgroud) 作为我之前关于使用 Thymeleaf 和防止页面刷新的问题的后续:
http://forum.thymeleaf.org/Preventing-page-refresh-Thymeleaf-amp-Spring-MVC-td4029155.html
基本上我有一个可用的 Spring MVC 应用程序,它使用 Thymeleaf 来保存表单数据。当用户保存数据时,页面会刷新(因为我想将它们留在页面上进行更多编辑)并且我想消除页面刷新。
我编写了一些 Javascript 以使用 JQuery Ajax 将数据发布到我的 Spring MVC 控制器。诀窍似乎是不使用提交按钮,只使用常规按钮并绑定一个 JS 函数以将数据发送到服务器。
这一切似乎都很完美,但我想确保我了解正在发生的事情。我特别想知道 Thymeleaf 现在是否是多余的。我不认为这是因为当我最初加载页面时,Thymeleaf 仍然绑定到数据 bean。通过在控制器中使用服务器端的调试器,看起来 post 请求调用映射的方法并将数据传递给模型。
我很感激您对这是否是实现这一目标的正确方法的评论。
最后,我如何处理错误,例如存储库因任何原因无法持久保存数据?
非常感谢。
以下是表格的重要部分:
<FORM id="adminDataForm" action="#" th:action="@{/admin_ajax}" th:object="${adminFormAjax}" method="post">
<input type="button" value="Save Changes" id="post" onClick="sendData()" />
Run Code Online (Sandbox Code Playgroud)
这是Javascript:
function sendData()
{
$.ajax(
{
type: "POST",
data: $("#adminDataForm").serialize(),
cache: false,
url: "/admin_ajax",
success: function(data)
{
alert("Your changes have been saved");
},
error: function()
{
alert("Error - Data not saved");
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是控制器: …
我正在考虑在AWS Lambda以及可能的AWS API Gateway上将服务实现为一系列REST终结点。前端将是一个JS浏览器客户端,该客户端直接调用这些端点,而无需中间层。
在我的研究中,我似乎找不到的是,如何确保可以访问所谓“登录”人员的电话?我看到Lambda调用是无状态的,因此没有会话数据。除了知道它们已经过身份验证并在相同情况下有权访问特定端点之外,我不需要会话数据。将有一个数据库(DynamoDB或RDS),因此如果我需要会话数据,则可以创建它。
有没有办法做到这一点?我知道我可以在每个API调用中传递其用户名和密码,但是似乎必须有更好的方法。
同样,这可能会用Java实现。我可以使用Spring Security吗?
在我的项目中,我正在迁移到React,因此不加载JQuery.由于我不再使用JQuery,因此对于AJAX调用我正在使用fetch.使用JQuery,我可以挂钩AJAX调用的开始和结束,因此将光标更改为微调器非常容易.我在fetch中找不到类似的钩子.除了在每个单独的AJAX调用中更改它之外,还有其他方法吗?
很多谷歌搜索一直在寻找关于...... JQuery的答案.
我有一个SpringBoot应用程序(在Java 8上为1.3.2RELEASE),它同时使用Hibernate 4.3.11.Final和SQL调用通过JDBC对Oracle JDBC驱动程序12.0.1.1。它还使用hibernate-c3p0 4.3.11.Final。JDBC调用是针对自动装配的JdbcTemplate实例进行的。
在pom中,我还具有Oracle UCP和ONS的依赖关系。以下是相关的pom条目:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.3.11.Final</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.1</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ucp</artifactId>
<version>12.1.0.2</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ons</artifactId>
<version>12.1.0.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但是,我找不到Oracle UCP的配置。同样,c3p0的所有配置似乎仅适用于Hibernate。
以下是相关的application.properties文件条目(没有其他属性文件):
# Properties for Hibernate and Oracle
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.properties.hibernate.connection.driver_class = oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@my-db-server:1523:me
spring.datasource.username=myuser
spring.datasource.password=mypass
# Configure the C3P0 database connection pooling module
spring.jpa.properties.hibernate.c3p0.max_size = 15
spring.jpa.properties.hibernate.c3p0.min_size = 6
spring.jpa.properties.hibernate.c3p0.timeout = 2500
spring.jpa.properties.hibernate.c3p0.max_statements_per_connection = 10
spring.jpa.properties.hibernate.c3p0.idle_test_period = 3000
spring.jpa.properties.hibernate.c3p0.acquire_increment = 3
spring.jpa.properties.hibernate.c3p0.validate = …Run Code Online (Sandbox Code Playgroud) 我有一个使用Postgres的Spring Boot应用程序(1.2).今天我正在尝试将其切换到Oracle,但是当我尝试连接时,我得到一个异常,说:
java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
Run Code Online (Sandbox Code Playgroud)
在那之下,
Caused by: java.net.ConnectException: Connection refused
Run Code Online (Sandbox Code Playgroud)
当然,这看起来像是糟糕的凭据,但我知道它们很好,而且他们在Oracle SQL Developer中工作得很好.我很困惑.这是我的属性文件条目:
# Properties for Hibernate and Oracle
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@//earth-db-11:5121/stardev
spring.datasource.username=ops$abcdefg
spring.datasource.password=mypassword
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
Run Code Online (Sandbox Code Playgroud)
我唯一的想法就是用户名中有一个$,我试图转义并在其周围加上双引号.
有任何想法吗?
谢谢...
更新:
非常感谢BonanzaOne,我的端口号错了.更正会导致新错误:
java.sql.SQLRecoverableException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
Run Code Online (Sandbox Code Playgroud)
当然,我查了一下,但我没有按照它告诉我的说法:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Cause: The listener received a request to establish …Run Code Online (Sandbox Code Playgroud) ajax ×2
hibernate ×2
javascript ×2
aws-lambda ×1
c++ ×1
c++11 ×1
c3p0 ×1
fetch-api ×1
java ×1
jdbc ×1
jquery ×1
json ×1
oracle ×1
spring ×1
spring-boot ×1
spring-mvc ×1
thymeleaf ×1