我使用 ASP.NET Core 5 创建了一个基本的 Rest API,我想用 docker 运行。该应用程序在 IIS Express 上运行良好。
我还想创建一个 docker 容器来启动应用程序。
在项目文件夹中,我创建了一个包含多个文件的 Docker 文件夹。 这是我的 App.dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:5.0
ARG WEBAPP_VERSION=0.0.1
LABEL maintainer=anymail@email_server.com \
Name=webapp \
Version=${WEBAPP_VERSION}
ARG URL_PORT
WORKDIR /app
ENV NUGET_XMLDOC_MODE skip
ENV ASPNETCORE_URLS http://*:${URL_PORT}
ENTRYPOINT [ "dotnet", "WebApplication.dll" ]
Run Code Online (Sandbox Code Playgroud)
我还有一个 Build.docker 文件:
FROM mcr.microsoft.com/dotnet/aspnet:5.0
## Can be Debug or Release.
ARG BUILD_CONFIG=Debug
ARG BUILDER_VERSION=0.0.1
LABEL maintainer=some_email@email_server.com \
Name=webapp-build-${BUILD_CONFIG} \
Version=${BUILDER_VERSION}
## Will be the path mapped to the external volume.
ARG BUILD_LOCATION=/app/out
ENV …Run Code Online (Sandbox Code Playgroud) 基于 MS 图形文档,我看到我可以更新一个 driveItem(文件)并将其放在特定的共享点驱动器中。该应用程序作为守护程序运行(无需用户登录)。
为此,我使用这个入口点:
PUT /drives/{drive-id}/items/{item-id}/content
Run Code Online (Sandbox Code Playgroud)
我尝试使用主类进行编码并传递现有参数。要更新文档,我调用方法更新文档:
UpdateDocumentResponseModel updatedDocument = fileGraphs.updateDocument(token, DRIVELIBID, DOCUMENTID, INPUTPATH, DOCUPDATE);
Run Code Online (Sandbox Code Playgroud)
被调用的方法旨在构建 URL 并为 PUT 请求准备数据:
public UpdateDocumentResponseModel updateDocument(String accessToken,
String driveLibId,
String documentId,
String inpuPath,
String docName) throws MalformedURLException {
String fullPath = inpuPath + docName;
URL url = new URL("https://graph.microsoft.com/v1.0/drives/" + driveLibId + "/items/" + documentId + "/content");
return requestsBuilder.updateDocument(accessToken, url, fullPath);
}
Run Code Online (Sandbox Code Playgroud)
现在在这个阶段我必须提出请求:
public UpdateDocumentResponseModel updateDocument(String accessToken, URL url, String fullPath) {
UpdateDocumentResponseModel returnValue = new UpdateDocumentResponseModel();
try {
CloseableHttpClient client = …Run Code Online (Sandbox Code Playgroud) 我并不是真正的 C# 专家,我有一个 C# 中的 post httpRequest 需要开发,为此我创建了这个方法,它接受一个 Uri、一个对象和一个不记名令牌。
该方法旨在构建调用请求:
private HttpClient client = new HttpClient();
public async Task<UserResponse> CreateUser(Uri url, UserRequest userRequest, string token)
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
string requestObject = JsonConvert.SerializeObject(userRequest);
Console.WriteLine("My Object: " + requestObject);
var req = new HttpRequestMessage(HttpMethod.Post, url);
req.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
req.Content = new StringContent(
requestObject,
Encoding.UTF8,
"application/json"
);
Console.WriteLine(req.ToString());
var response = await client.SendAsync(req);
string output = await response.Content.ReadAsStringAsync();
Console.WriteLine(JsonConvert.DeserializeObject(output));
UserResponse returnValue = JsonConvert.DeserializeObject<UserResponse>(output);
return returnValue;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我不确定我是否正确传递了标题内容。返回响应是一条错误消息,告诉我没有经过身份验证。
谢谢
我有剩余模型,用于构建发送的 JSON。
休息模型
@Getter @Setter
@ToString
public class OrderRequestModel {
private String orderKeyId;
private String paymentMode;
private double totalAmount;
private List<ProductRequestModel> orderProducts;
private UserDetailsRequestModel seller;
private Date createdAt;
}
Run Code Online (Sandbox Code Playgroud)
ProductRequestModel 类似
@Getter @Setter
@ToString
public class ProductRequestModel {
private String productKeyId;
private String name;
private double price;
private int qty;
private String imgPath;
private CategoryRequestModel category;
}
Run Code Online (Sandbox Code Playgroud)
我将模型传递到与数据库相关的 DTO 层(它们包含一个长 ID):
@Getter @Setter
@ToString
public class OrderDto implements Serializable {
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private static final long serialVersionUID = 1L;
private …Run Code Online (Sandbox Code Playgroud) 我正在使用 Springboot 和 PostgreSQL 12 开发一个 API。我使用 hibernate 创建了一个用户表,有问题的实体字段如下:
@Column(columnDefinition = "BOOLEAN NOT NULL DEFAULT FALSE")
private Boolean emailVerificationStatus = false;
Run Code Online (Sandbox Code Playgroud)
我的表似乎已正确生成:
create table users (
id int8 generated by default as identity,
email varchar(120) not null,
email_verification_status boolean default false not null,
email_verification_token varchar(255),
encrypted_password varchar(255) not null,
first_name varchar(50) not null,
last_name varchar(50) not null,
user_id varchar(255) not null,
primary key (id)
)
Run Code Online (Sandbox Code Playgroud)
我的问题是在运行应用程序时收到一条错误消息:
org.hibernate.PropertyValueException: not-null property references a null or transient value : fr.mycompany.app.io.entity.UserEntity.emailVerificationStatus
Run Code Online (Sandbox Code Playgroud)
默认情况下,当我创建用户时,它会发送一个空值。我可以通过在服务层中将值设置为 false 来解决这个问题,但这不是很优雅。另外,当我删除选项 …
我有一个由多个 sql 请求产生的数组数组。首先,我在 foreach 中发出一个 sql 请求,以获得我需要的所有数据
foreach ($users as $user) {
// Two different Eloquent requests
$todo = User::select().....where('users.id' = $id);
$done = User::select().....where('users.id' = $id);
// I have operation on Collection that work fine ...
$totalTimes = $todo->toBase()->sum('dureeformation') ;
$spendTimes = $done->toBase()->sum('dureeformation') ;
$remainingTimes = $totalTimes - $spendTimes;
$all[] = ['user_id' => $id, 'totalTime' => $totalTimes, 'spendTime' => $spendTimes,'remainingTime' => $remainingTimes ];
}
Run Code Online (Sandbox Code Playgroud)
我的问题如下......在foreach之外我显示值并且我有这个数组数组......
array:16 [?
0 => array:4 [?
"user_id" => 1
"totalTime" => 465
"spendTime" => …Run Code Online (Sandbox Code Playgroud) 我有一个带有身份验证系统和后端仪表板的应用程序。默认情况下,路由显示身份验证组件:
{
path: "/",
name: "Authentication",
component: Auth
},
Run Code Online (Sandbox Code Playgroud)
App.view 包含一旦登录我被重定向到另一个 vue 组件“home”:
{
path: "/dashboard",
name: "home",
component: Home,
},
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好。在这个主页组件中,我有一些带菜单的 HTML,我想在同一页面中显示组件。
这是主页模板中的 html 示例
<div>
<router-link :to="'/dashboard/user'">User</router-link>
<router-link :to="'/dashboard/stats'">Stats</router-link>
<app-user></app-user>
<app-stats></app-stats>
</div>
Run Code Online (Sandbox Code Playgroud)
我还在路由器中为这些组件创建了路由,但在单击链接时它会显示一个白页。我刚开始使用 vue.js,我相信它很容易管理。我的目标是根据显示的页面显示组件。
.net-core ×1
c# ×1
collections ×1
docker ×1
hibernate ×1
java ×1
laravel ×1
modelmapper ×1
postgresql ×1
vue-router ×1
vue.js ×1