我在这里阅读了 Spring Data Binder 的全面解释:/sf/answers/259409881/
我的问题需要更多的知识,让我强调一下:
我有具有复杂字段的 Person 对象 - 例如与街道和数字字段的联系。所以我们可以这样描述:
public class Contact {
private String street;
private int number;
// setters & getters
};
public class Person {
private String name;
private int age;
private Contact contact;
// setters & getters
};
Run Code Online (Sandbox Code Playgroud)
我认识到 spring 将其表示为 html 表单,如下输入字段:
姓名、年龄、contact.street、contact.number
我认为,当它返回时,它可以将它放回 Person 对象。
我想“雇用”Spring Binder 来为我提供的文本数据创建对象(不是 HttpRequest 对象)。例如我有文件:
name age street number
John 22 MHDrive 2187
Will 32 MHDrive 3212
Run Code Online (Sandbox Code Playgroud)
我可以提供上面的任何结构并想要获取 Person 对象:)
例如
Person p = springBinderSomething({{"name","John"},{"age","22"},{"street","MHDrive"},{"number","2187"}}, Person.class); …Run Code Online (Sandbox Code Playgroud) 我有一个自定义模型,当某些单元格的值发生更改时,它会不时发出 dataChanged() 信号。这本身就很有效,并且视图会根据需要进行更新。
但后来我尝试在中间插入一个 QSortFilterProxyModel 以允许在我的视图上进行排序(不需要过滤),显然 dataChanged() 信号不是通过代理模型中继的。
据我所知,这是 QSortFilterProxyModel 的预期行为,除了子类化 QSortFilterProxyModel 之外,还有其他解决方案吗?只是添加一个槽来中继 dataChanged() 信号并相应地映射项目?
就我而言,它非常简单,因为一次仅更新一个单元格或整个列,但没有其他奇怪的东西,因此映射索引应该非常简单......
我有个问题。我有我的控制器“DashboardNB2Controller”,我的视图“index.cshtml”,我想在我的“index.cshtml”中集成一个名为“_PartialView.cshtml”的部分视图。两个视图都位于同一文件夹中。在我的控制器中,我的部分视图中有用于数据库操作的“ActionResult _PartialView”。
但是,如果我将部分视图集成到索引视图中,则操作结果“_PartialView”不起作用。我没有得到任何结果。我的数据库的查询是正确的。我检查了这个。
这是我的代码
我的控制器与部分视图的 ActionResult
public ActionResult _PartialView()
{
var lastMessages= (from t in db.view_tbl_message
orderby t.Date descending
select t).Take(10);
ViewModelDashboard model = new ViewModelDashboard();
model.view_tbl_message = lastMessages.ToList();
return PartialView("_PartialView", model);
}
Run Code Online (Sandbox Code Playgroud)我的index.cshtml
@model AisWebController.Areas.Statistics.Models.ViewModelDashboard
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<br />
@{Html.Action("_PartialView", "DashboardNB2");}
<br />
Run Code Online (Sandbox Code Playgroud)
还有我的 _PartialView.cshtml
@model WebApplication.Areas.Stats.Models.ViewModelDashboard
<table class="table table-bordered">
<tr>
<th>
Date
</th>
<th>
User
</th>
<th>
Message
</th>
</tr>
@foreach (var item in Model.view_tbl_message)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Date
</td> …Run Code Online (Sandbox Code Playgroud) model-view-controller asp.net-mvc partial-views razor c#-4.0
我有一个简单的问题
我正在开发聊天系统服务,但我遇到了一些有趣的事情。
我目前是这样操作的:
第一张表:
[Messages] :
SenderID(user),
RecipientID(user),
Content(string)
Run Code Online (Sandbox Code Playgroud)
当然,每次用户向其他用户发送消息时,我都会将其添加到表中。但我想到如果一个表有一百万行,它会变得一团糟
所以我想到了另一种方式:
第一张表:
[Conversation]
ConversationID,
USER1(user),
USER2(user)
Run Code Online (Sandbox Code Playgroud)
第二个表:
[Messages] in which I have
ConversationID,
Content(string)
Run Code Online (Sandbox Code Playgroud)
所以基本上,我问,我应该使用哪种配置?
我需要一个静态方法将 DataTables(动态)转换为 List(又是动态实体)这是我的代码帮助将被理解
public static ICollection<System.Data.Entity.Core.Objects.DataClasses.EntityObject> DtToEntity(DataTable DataTable,System.Data.Entity.Core.Objects.DataClasses.EntityObject EntityObject)
{
ICollection<System.Data.Entity.Core.Objects.DataClasses.EntityObject> _list = null;
System.Data.Entity.Core.Objects.DataClasses.EntityObject _tempClass;
foreach (DataRow dataRow in DataTable.Rows)
{
foreach(DataColumn dataColumn in DataTable.Columns)
{
foreach (var attribute in EntityObject.GetType().GetProperties())
{
if (attribute.Name == dataColumn.ColumnName && attribute.GetType().Equals(dataColumn.GetType()))
{
return _list;
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我看到有人建议将 MVC 与洋葱架构一起实施。但两者如何共存呢?它们不是两种不同的架构吗?例如,Onion设计中的Controller在哪里?
我理解不止一种设计模式的组合,因为它们服务于不同的目的(行为、创建等),并且可以在系统的不同模块中独立实现,但我不知道如何实现两种不同的架构。
architecture model-view-controller design-patterns software-design onion-architecture
我目前正在使用 Laravel 重建我的 vanilla-PHP-App,但遇到以下问题。我有多个数据库表,代表单词类别(名词、动词、副词……)。对于每个表,我创建了一个单独的模型、一个route::resource 和一个单独的资源控制器。例如:
NomenController.php
public function show($id)
{
$vocab = Nomen::find($id);
return view('glossarium.vocab_update', compact('vocab'));
}
Run Code Online (Sandbox Code Playgroud)
和
动词控制器.php
public function show($id)
{
$vocab = Verb::find($id);
return view('glossarium.vocab_update', compact('vocab'));
}
Run Code Online (Sandbox Code Playgroud)
...除了 Model 类之外,它们本质上是相同的。
我不想为每个模型创建一个单独的控制器,它的作用完全相同。解决这个问题最简单、最优雅的方法是什么?我是否应该创建一个 VocabController.php 并为模型名称添加一个参数,例如:
Route::resource('/vocab/{category}', 'VocabController');
Run Code Online (Sandbox Code Playgroud)
然后在这个控制器中添加一个构造函数方法,例如
public function __construct ($category) {
if ($category == 'nomen') {
$this->vocab = App\Nomen;
}
else if ($category == 'verb') {
$this->vocab = App\Verb;
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有更简单的方法可以做到这一点。我可以通过路由模型绑定来做到这一点吗?
提前致谢
我有一个在 docker 容器上运行的 spring boot mvc 应用程序。容器运行得很好,但是当我尝试在浏览器上访问应用程序时,我收到 Whitelabel 错误页面,指出它找不到 /WEB-INF/views/***.jsp。下面是我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jay.webapp</groupId>
<artifactId>LoginModel</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>LoginModel</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
</dependency> …Run Code Online (Sandbox Code Playgroud) 我尝试过
System.Net.Dns.GetHostEntry(HttpContext.Connection.RemoteIpAddress.ToString()).ToString();
Run Code Online (Sandbox Code Playgroud)
但这没有用。我也尝试过使用
PCName = Dns.GetHostEntry(Request.ServerVariables["REMOTE_ADDR"]).HostName;
Run Code Online (Sandbox Code Playgroud)
但这对于核心似乎已被弃用
无法加载文件或程序集“Microsoft.CodeDom.Providers.DotNetCompilerPlatform,Version=1.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。(HRESULT 异常:0x80131040)
我安装了以下 dll 文件用于 WebApi 身份验证
Microsoft.Owin
Microsoft.Owin.Host.SystemWeb
Microsoft.Owin.Security.OAuth
Microsoft.Owin.Security
Microsoft.AspNet.Identity.Owin
Run Code Online (Sandbox Code Playgroud)
此错误仅会在托管环境中发生。它将在托管[哪台开发机器]和代码的本地机器上运行良好。
c# ×3
asp.net-mvc ×2
architecture ×1
asp.net-core ×1
c#-4.0 ×1
c++ ×1
docker ×1
java ×1
laravel ×1
messaging ×1
php ×1
qt ×1
razor ×1
spring ×1
spring-boot ×1
spring-mvc ×1