现在我有一个实体对象和一个DTO.当我做一个简单的例子时,存储库返回一个对象数组列表:findById().有没有办法轻松地将返回类型映射为自定义DTO对象而不是始终返回实体对象?
示例如下:
@Query("Select f.id, f.name from Food f where f.id = :id")
public List<Object[]> findById(@Param("id") String id);
Run Code Online (Sandbox Code Playgroud)
我的DTO对象如下:
FoodDto{
private String id;
private String name;
}
Run Code Online (Sandbox Code Playgroud)
现在我只能获得存储库以返回List <Object []>类型.
为什么将构造函数从Mammal重置为Cat很重要?我一直在玩这个代码,并没有发现任何"错误"构造函数的负面影响.
function Mammal(name){
this.name=name;
this.offspring=[];
}
Cat.prototype = new Mammal(); // Here's where the inheritance occurs
Cat.prototype.constructor=Cat; // Otherwise instances of Cat would have a constructor of Mammal
function Cat(name){
this.name=name;
}
Run Code Online (Sandbox Code Playgroud)
例如:
function Mammal(name){
this.name=name;
this.offspring=[];
}
Cat.prototype = new Mammal(); // Here's where the inheritance occurs
function Cat(name){
this.name=name;
this.hasFur = true;
}
c1 = new Cat();
alert(c1.hasFur); //returns true;
Run Code Online (Sandbox Code Playgroud) 当我有如下代码:
self = [super init]
Run Code Online (Sandbox Code Playgroud)
自我指向超级?如果是这样,你为什么要这样?如果我的实例对象具有变量"someVal",我将无法通过[self someVal]来实现它.正确?
当self指向super时,我如何使用self来获取实例变量?
我正在查看此页面上的代码和解释,但我不太明白。https://www.geeksforgeeks.org/copy-constructor-in-cpp/
下面是我感到困惑的例子。为什么会str2.change("GeeksforGeeks");导致 str1 也改变?我问是因为change与复制构造函数完全相同。他们都为 s 分配了一个新的字符数组。
#include<iostream>
#include<cstring>
using namespace std;
class String
{
private:
char *s;
int size;
public:
String(const char *str = NULL); // constructor
~String() { delete [] s; }// destructor
void print() { cout << s << endl; } // Function to print string
void change(const char *); // Function to change
};
String::String(const char *str)
{
size = strlen(str);
s = new char[size+1];
strcpy(s, str);
}
void String::change(const char *str) …Run Code Online (Sandbox Code Playgroud)