小编Ser*_*sky的帖子

Angular2动态输入字段在输入更改时失去焦点

我正在制作一个动态的表格.A Field有一个值列表.每个值都由一个字符串表示.

export class Field{
    name: string;
    values: string[] = [];
    fieldType: string;
    constructor(fieldType: string) {this.fieldType = fieldType;}
}
Run Code Online (Sandbox Code Playgroud)

我的组件中有一个函数,它为字段添加了一个新值.

addValue(field){
    field.values.push("");
}
Run Code Online (Sandbox Code Playgroud)

值和按钮在我的HTML中显示如下.

<div id="dropdown-values" *ngFor="let value of field.values; let j=index">
    <input type="text" class="form-control" [(ngModel)]="field.values[j]" [name]="'value' + j + '.' + i"/><br/>
</div>
<div class="text-center">
    <a href="javascript:void(0);" (click)="addValue(field)"><i class="fa fa-plus-circle" aria-hidden="true"></i></a>
</div>
Run Code Online (Sandbox Code Playgroud)

只要在输入值中写入一些文本,输入就会失去焦点.如果我向字段添加许多值,并且我在一个值输入中写入一个字符,则输入将失去焦点,并且字符将写入每个输入.

javascript angular2-forms angular2-ngmodel ngfor angular

43
推荐指数
1
解决办法
2万
查看次数

访问Android上的Unity StreamingAssets

我编写了一些代码来获取StreamingAssets中文件夹内的所有文件夹,然后获取该文件夹中的所有文件.它在Windows上运行良好,但我无法在Android上运行它.

这是代码:

foreach (string s in Directory.GetDirectories(model.path + "/Levels")) {
        GameObject el = (GameObject)Instantiate(listButton, Vector3.zero, Quaternion.identity);
        el.transform.SetParent(grid1.transform);
        string[] words = s.Split('/');
        #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
                            words = s.Split('\\');
        #endif
        el.GetComponentInChildren<Text>().text = words[words.Length - 1];
        el.GetComponent<Button>().onClick.AddListener(() => {
            MapSizeButtonClick(Int32.Parse(el.GetComponentInChildren<Text>().text));
        });
    }
Run Code Online (Sandbox Code Playgroud)

由于'\',我不得不为Windows添加#if UNITY_STANDALONE_WIN.

然后对于该文件夹中的文件,我写了这个:

foreach (string s in Directory.GetFiles(model.path + "/Levels/" + model.mapSize + "/" + model.colorNumber)) {
        string[] words = s.Split('/');
        #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
                    words = s.Split('\\');
        #endif
        words = words[words.Length - 1].Split('.');
        if (words[1] == "json") {
            GameObject …
Run Code Online (Sandbox Code Playgroud)

directory android assets unity-game-engine unity5

6
推荐指数
1
解决办法
1万
查看次数

Spring Rest API验证应该在DTO还是在实体中?

应该在Spring Boot Rest API中使用哪个层进行验证.我有一些模型,端点和DTO.我在DTO中添加了一些@NotNull@Size注释.我@Valid在端点中添加了注释以及@RequestParam注释.

但现在我想知道我是否应该在@Entity课堂上进行验证?我觉得这将是一个重复的代码.但我读到一层不应该依赖另一层.

java validation rest spring spring-mvc

6
推荐指数
2
解决办法
3039
查看次数

使用 VueJS 热重载期间,Webpack 速度缓慢,“95% 发出 CopyPlugin”

在热重载期间,Webpack 会卡住95% emitting CopyPlugin几秒钟。

我的公共文件夹中有很多文件,大部分是图像(大约 1GB),它们必须显示在我的 VueJS 应用程序上。如果我删除它们,我就不再有问题了。

这是我的package.json依赖项:

{ 
  ...
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "core-js": "^3.6.4",
    "register-service-worker": "^1.7.1",
    "vue": "^2.6.11",
    "vue-router": "^3.1.6"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.3.0",
    "@vue/cli-plugin-eslint": "~4.3.0",
    "@vue/cli-plugin-pwa": "~4.3.0",
    "@vue/cli-plugin-router": "~4.3.0",
    "@vue/cli-service": "~4.3.0",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.2.2",
    "sass": "^1.26.3",
    "sass-loader": "^8.0.2",
    "vue-template-compiler": "^2.6.11"
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我的 vue.config.js 文件:

const path = require("path");

function resolveSrc(_path) {
  return path.join(__dirname, _path);
}
// vue.config.js …
Run Code Online (Sandbox Code Playgroud)

webpack vue.js vue-cli

6
推荐指数
1
解决办法
1376
查看次数

Django Rest Framework - 单元测试图像文件上传

我正在尝试对上传REST API的文件进行单元测试.我在网上找到了一些使用Pillow生成图像的代码,但它无法序列化.

这是我生成图像的代码:

image = Image.new('RGBA', size=(50, 50), color=(155, 0, 0))
file = BytesIO(image.tobytes())
file.name = 'test.png'
file.seek(0)
Run Code Online (Sandbox Code Playgroud)

然后我尝试上传这个图片fille:

return self.client.post("/api/images/", data=json.dumps({
     "image": file,
     "item": 1
}), content_type="application/json", format='multipart')
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

<ContentFile: Raw content> is not JSON serializable
Run Code Online (Sandbox Code Playgroud)

如何变换枕头图像以使其可序列化?

django rest django-rest-framework

5
推荐指数
1
解决办法
2762
查看次数

手动将 @Entity 转换为投影接口

所以我大部分时间都在使用 Spring Data Repositories。但我遇到了一个用例,我无法使用 Spring 存储库来检索我需要返回给客户端的实体。所以我的类ResourceEntity是一个 Spring 数据实体。我想将这个实体作为ResourceProjection接口返回。

@Getter
@Setter
@NoArgsConstructor
@Entity
public class ResourceEntity{
    private Long id;
    private String name;
    private String anotherFieldThatIsNotInTheProjection;
}

public interface ResourceProjection {
    Long getId();
    String getName();
}
Run Code Online (Sandbox Code Playgroud)

通常对于 Spring 存储库,我会定义类似的内容:

public interface ResourceRepository extends PagingAndSortingRepository<ResourceEntity, Long> {
    Optional<ResourceProjection> getById(Long id);
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我无法使用 Spring Data 生成的“自动代理”来自动实现实体数据的投影。

所以我的问题是:有没有办法“手动”将实体转换为投影?

我想到的另一个解决方案是返回实体并使用 @JsonIgnore 之类的 Jackson 注释来防止返回一些数据,但这对于我的代码编写方式来说并不是最佳的。

否则,我始终可以创建一个 DTO 类来填充来自实体的数据。但由于我已经为其他目的创建了投影,所以我想避免创建第二个“DTO”。

java spring hibernate spring-data spring-data-jpa

5
推荐指数
1
解决办法
3506
查看次数

MySQL for Python 2.7

我正在寻找一种在Windows 7 64位下使用MySQL和Python 2.7的工具.

我搜索了一下这些:

MySQLdb - _http://sourceforge.net/projects/mysql-python/ 
SQLAlchemy - _http://www.sqlalchemy.org/ 
SQLObject - _http://sqlobject.org/ 
ourSQL - _http://pythonhosted.org/oursql/ 
Connector/Python - _http://dev.mysql.com/downloads/connector/python/1.0.html 
SQLite - _http://www.sqlite.org/ 
Psycopg2 - _http://wiki.postgresql.org/wiki/Psycopg2_Tutorial (postgreSQL)
pandaSQL - _https://github.com/yhat/pandasql 
python-sql - _https://code.google.com/p/python-sql/ 
SnakeSQL - http://pythonweb.org/projects/snakesql/
Run Code Online (Sandbox Code Playgroud)

您有什么推荐的吗 ?

谢谢 !

安托万

python mysql sqlite python-2.7

4
推荐指数
1
解决办法
2万
查看次数

Jquery .on('input',function(){...}); 不与IE合作

我在Chrome上有一个完美的jquery功能,但它不适用于IE ...每次我在文本框#form中更改某些内容时,服务器都会获取获取AJAX请求但不在IE上

$("#form").on('input', function() {
    $("#value").val($("#value").val().toUpperCase());
    var postdata = {value: $("#value").val()} ;
    $.get('/search', postdata, function(data) {
        var result = ("Type : " + data['type'] + "<br/>Project name : " + data['project_name'] + "<br/>Project version : " + data['project_version'] + "<br/>Product name : " + data['product_name'] + "<br/>Product version : " + data['product_version'] + "<br/>Lib op : " + data['libop'])
        $("#print").html(result) ;
    });
});
Run Code Online (Sandbox Code Playgroud)

你有解决方案吗?

谢谢 !最好的祝福,

Servietsky

javascript jquery internet-explorer

3
推荐指数
1
解决办法
9020
查看次数

Unity表面着色器不会在自身上投射阴影

我是着色器的新手,我正在尝试为一些非常简单的低聚水制作着色器。我创建了这个简单的表面着色器,它可以更改顶点高度。

着色器

问题在于,它没有收到gif中所见的阴影,并且边缘上有奇怪的行为。

我究竟做错了什么?

Shader "Ramble/LowPolyWater" {
    Properties {
        _MainTex ("Texture", 2D) = "white" {}
        _Color ("Main Color", Color) = (1,1,1,1)
        _Emission ("Emission", Color) = (1,1,1,1)
        _ScrollYSpeed("Scroll y speed", Float) = 0.1
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        CGPROGRAM

        #pragma surface surf Lambert vertex:vert

        struct Input {
            float2 uv_MainTex;
        };

        sampler2D _MainTex;
        fixed4 _Color;
        fixed4 _Emission;
        float _ScrollYSpeed;

        void vert (inout appdata_full v)
        {
            v.vertex.z += frac(sin( dot(v.vertex.xyz ,float3(12.9898,78.233,45.5432) )) * 43758.5453) * sin(_Time.y) * _ScrollYSpeed;
        }

        void surf (Input …
Run Code Online (Sandbox Code Playgroud)

shader cg unity-game-engine

3
推荐指数
1
解决办法
973
查看次数

在平面地图上随机生成块

我试图在平面地图上随机生成块,并使它们不会相互重叠.我已经制作了一个地图大小(500x500)的矩阵(c#数组),这些块的比例在1到5之间.代码可以工作但是如果生成的块与另一个块重叠,它就会被破坏而不会在其他地方重新生成.

我尝试生成的1000个块中只有大约80个不与另一个块重叠.

这是地图的图片,生成了大约80个块,绿色方块是块

地图

void generateElement(int ratio, int minScale, int maxScale, GameObject g) {
    bool elementFound = false;
    for (int i = 0; i < ratio * generationDefault; i++) {
        GameObject el;
        // Randomly generate block size and position
        int size = Random.Range(minScale, maxScale + 1);
        int x = Random.Range(0, mapSizex + 1 - size);
        int y = Random.Range(0, mapSizey + 1 - size);

        // Check if there is already an element 
        for (int j = x; j < x + …
Run Code Online (Sandbox Code Playgroud)

c# random dictionary generator unity-game-engine

2
推荐指数
1
解决办法
698
查看次数

使用drawImage缩放上面的画布

我正在尝试制作一个带有 2 个画布的像素编辑器。第一个画布显示包含像素的第二个画布。第一个画布使用drawImage来定位和缩放第二个画布。

当第二个画布缩放得小于其原始尺寸时,它开始出现故障。

这是以原始尺寸显示的画布。当我放大时,第二个画布变得更大,一切都完美运行。

正常比例

然而,当我缩小时,网格和背景(透明度)的表现非常奇怪。

规模较小

规模更小

要在第一个画布上绘制第二个画布,我使用该函数

ctx.drawImage(drawCanvas, offset.x, offset.y, width * pixelSize, height * pixelSize);
Run Code Online (Sandbox Code Playgroud)

我读过多次迭代中的缩放可能会提供更好的图像质量,但我不确定画布。

当用户缩小时,我可以以较低的分辨率完全重绘第二个画布,但这对 CPU 来说有点沉重。

还有我不知道的更好的解决方案吗?

html javascript css canvas

1
推荐指数
1
解决办法
1133
查看次数

用Spring调试Jackson

我刚刚在Spring REST API的多个文件中编写了一些代码,现在出现Jackson错误。

org.springframework.context.ApplicationContextException: Unable to start 

embedded container; nested exception is 

org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:168) ~[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:160) ~[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
        ... 11 common frames omitted
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.autoconfigure.web.HttpMessageConverters org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.messageConverters; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could …
Run Code Online (Sandbox Code Playgroud)

spring jackson spring-boot

0
推荐指数
3
解决办法
4478
查看次数

Spring Data 未能延迟初始化角色集合,无法初始化代理 - 无会话

我正在使用 Spring Boot 制作 API,但我似乎从未设法初始化惰性集合。对我有用的唯一解决方案是将其更改为热切,但这不是解决方案。

@Entity
@Getter
@Setter
@NoArgsConstructor
@Table(name = "user")
public class UserEntity {

    @Id
    @GeneratedValue
    private Long id;

    @Column(unique = true)
    String email;

    @ElementCollection(fetch = LAZY)
    List<String> roles = new ArrayList<>();

    public UserEntity(String email) {
        this.email = email;
    }
}
Run Code Online (Sandbox Code Playgroud)
@Order(Ordered.LOWEST_PRECEDENCE)
@Component
public class AuthFilter extends OncePerRequestFilter {

    Logger LOG = LoggerFactory.getLogger(AuthFilter.class);

    @Autowired
    UserRepository userRepository;

    @Override
    @Transactional
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

        if(authentication != null && …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jpa spring-boot

0
推荐指数
1
解决办法
956
查看次数