小编lch*_*lch的帖子

创建javascript原型继承链的不同方法

function Parent(parentName){
  this.name = parentName;
}

Parent.prototype.printName = function(){
  console.log(this.name);
}

var p = new Parent("Parent");
console.log(p);

function Child(parentName, childName){
  Parent.call(this, parentName);
  this.name = childName; 
}

1. Child.prototype = Object.create(Parent.prototype);
2. Child.prototype = Parent.prototype;

var c = new Child("Parent","Child");
console.log(c);
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我上面的语句1和2之间的区别吗。无论哪种方式,子对象都可以调用c.printName();。

javascript prototype-chain

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

Django celery 击败任务不起作用

芹菜.py

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from django.conf import settings

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TwitterApiProxy.settings')

app = Celery('TwitterApiProxy')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)


@app.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
    # Calls test('hello') every 10 seconds.
    sender.add_periodic_task(10.0, hello_test.s('hello'), name='add every 10')


@app.task
def hello_test(arg):
    print(arg)
Run Code Online (Sandbox Code Playgroud)

设置.py

CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'America/Los_Angeles'
Run Code Online (Sandbox Code Playgroud)

我想每 10 秒打印一次“你好”。所以celery -A TwitterApiProxy beat在我的终端中运行时,我看到如下:

LocalTime -> 2018-04-06 23:27:09
Configuration ->
    . broker -> …
Run Code Online (Sandbox Code Playgroud)

python django celery django-celery celerybeat

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

使用pyenv安装python后找不到python3命令

我用pyenv安装了特定版本的python。pyenv version在终端输入时,我看到了3.5.0 (set by /Users/lcherukuri/.python-version)。但是当我打字的时候python3我得到了python3 command not found。如何解决这个问题?找不到pip3

python pip pyenv

5
推荐指数
3
解决办法
4472
查看次数

Spring 安全角色无法转换为授予权限

用户.java

public class User implements Serializable{
    @Id
    @Size(min=5,max=15)
    @Column(name="username", unique=true)
    private String username;

    @OneToMany(mappedBy="user")
    private Collection<Role> roles;

public User(User user) {
        this.username=user.username;
        this.roles=user.getRoles();
    }
}
Run Code Online (Sandbox Code Playgroud)

角色.java

public class Role implements Serializable{
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;

    private String role;

    @ManyToOne
    @JoinColumn(name="username")
    private User user;
}
Run Code Online (Sandbox Code Playgroud)

UserServiceImpl.java

public class UserServiceImpl implements UserServiceDetails {

    private UserRepo userRepo;

    @Autowired
    public void setUserRepo(UserRepo userRepo) {
        this.userRepo = userRepo;
    }

    @Override
    public UserDetails loadUserByUsername(String username)
            throws UsernameNotFoundException {
        User user=userRepo.findUserByUsername(username);
        if(user == null) {
            throw …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security

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

SessionStorage和json对象

user: {firstName: "loki", lastName: "ch"}
Run Code Online (Sandbox Code Playgroud)

我将此用户存储在会话存储中.

$window.sessionStorage.user = user;
Run Code Online (Sandbox Code Playgroud)

当我用它取回它时 $window.sessionStorage.user,我得到了:

[object Object] 
Run Code Online (Sandbox Code Playgroud)

我想要JSON.有什么建议?

javascript json session-storage

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

Spring REST @RequestMapping实践

@RestController
@RequestMapping(value = "/players")
public class REST {

    @RequestMapping(method = RequestMethod.GET)
    public List<Player> getAll() {
        return service.getAll();
    }

    @RequestMapping(method = RequestMethod.GET, params = {"team", "score"})
    public List<Player> getByPlayerAndScore(@RequestParam(value = "team") String team, 
                                                @RequestParam(value = "score", required = false) int score) {
        return service.getByPlayerAndScore(team, score);
    }
}
Run Code Online (Sandbox Code Playgroud)

Q1:我期待第一种方法为url"/ players"工作(按预期工作)和第二种方法为url工作("/ players?team = xyz","/ players?team = xyz&score = 1000").spring使用method1 for"/ players?team = xyz".即使我指定得分为可选,除非我指定2个参数,弹簧是不使用第二种方法.如何解决这个问题以及编写控制器方法来处理这些类型请求的最佳方法是什么,用户可以发送不同的可用参数集(例如param1和param2,只有param1,只有param2等).

Q2:对于具有不同参数集的第二类查询,如何在DAO层中编写数据库查询.我应该编写单独的方法,每个方法使用不同的查询或一个方法使用多个if语句(如果用户发送'团队'将团队添加到数据库查询,如果用户发送'分数'将其添加到数据库查询......)

java spring spring-mvc

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

解释python Singleton类

class Singleton:

    instance = None

    def __new__(cls):
        if cls.instance is None:
            cls.instance = super().__new__(cls)
        return cls.instance

singleton_obj1 = Singleton()
singleton_obj2 = Singleton()

print(singleton_obj1)
print(singleton_obj2)
Run Code Online (Sandbox Code Playgroud)

产量

<__main__.Singleton object at 0x10dbc0f60>
<__main__.Singleton object at 0x10dbc0f60>
Run Code Online (Sandbox Code Playgroud)

有人可以解释这一行究竟发生了什么cls.instance = super().__new__(cls).哪一行代码有助于创建这个类Singleton

python singleton

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

使用过滤方法过滤Laravel雄辩的集合

  $events=Event::all();
  if (isset($scheduling) && $scheduling!=="All")
  {
     $events = $events->filter(function($event) use ($scheduling)
     {
        return $event->where('scheduling',$scheduling);
      });
   }
  $events=$events->get();
Run Code Online (Sandbox Code Playgroud)

可以有人纠正这个代码.内部过滤器不起作用.无论是否应用过滤器,结果都是相同的.我需要根据条件应用这样的批量过滤器

php laravel laravel-4 laravel-5

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

如何使用POSTMAN客户端发布凭据以创建基于cookie的会话

我正在使用postman客户端对JIRA API进行REST调用.它说"将您的凭据发布到http://jira.example.com:8090/jira/rest/auth/1/session "以获得SESSION.我尝试使用Form-data,application/x-www-form-urlencoded,raw等进行发布.没有任何效果.这是正确的方法.

以下是我正在遵循的教程:https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-cookie-based-认证

authentication cookies rest jira postman

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

如何默认在一行中导出命名导入?

index.js

import { Human } from 'test';

export default Human;
Run Code Online (Sandbox Code Playgroud)

我正在Human从中导入一个命名的出口test。我正在default从导出人,index.js以便允许其他人从而index.js不是导入人test

例如:

import Human from 'index';
Run Code Online (Sandbox Code Playgroud)

如何将以上2条语句组合index.js成一行?

javascript object ecmascript-6

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