小编Mac*_*zyk的帖子

创建一个JSON对象以在Spring Boot测试中发布

我想编写基本测试来在具有JSON有效负载的/ users URL上执行POST请求以创建用户.我找不到如何将新对象转换为JSON,到目前为止有这么多,这显然是错误的,但解释了目的:

@Test public void createUser() throws Exception {
    String userJson = new User("My new User", "myemail@gmail.com").toJson();
    this.mockMvc.perform(post("/users/").contentType(userJson)).andExpect(status().isCreated());
Run Code Online (Sandbox Code Playgroud)

spring json spring-boot

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

Docker-compose:nginx不适用于django和gunicorn

我一直在尝试在docker-compose中设置一个环境,其中有几个容器:

  • Django的
  • Nginx的
  • Postgres的
  • DbData
  • 存储

我使用了以下配置:

 app:
  restart: always
  build: src
  expose:
    - "8000"
  links:
    - postgres:postgres
  volumes_from:
    - storage_files_1
  env_file: .env
  command: gunicorn barbell.wsgi:application \
            -b 0.0.0.0:8000 -w 4

nginx:
  restart: always
  build: nginx
  ports:
    - "80:80"
    - "443:443"
  volumes_from:
    - storage_files_1
  links:
    - app:app

postgres:
  restart: always
  image: postgres:latest
  volumes_from:
    - storage_data_1
  ports:
    - "5432:5432"
Run Code Online (Sandbox Code Playgroud)

我的启用nginx站点的配置文件如下所示:

server {

    listen 80;
    server_name localhost;
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    location /static {
        alias /static/;
        autoindex on;
    }

    location / { …
Run Code Online (Sandbox Code Playgroud)

nginx uwsgi gunicorn docker docker-compose

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

如何阻止vim在80后创建一个新行

我使用vim作为Python IDE以及我的Octopress的一些markdown编辑器.它每80个字符创建一个新行.我试图关闭它(启用工作包装)所以典型的文本文件的版本不会这么痛苦.

这是我的.vim配置:

filetype off
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()

set foldmethod=indent
set foldlevel=99

map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h

map <leader>td <Plug>TaskList

map <leader>g :GundoToggle<CR>

syntax on                           " syntax highlighing
filetype on                          " try to detect filetypes
filetype plugin indent on    " enable loading indent file for filetype

let g:pyflakes_use_quickfix = 0

let g:pep8_map='<leader>8'

au FileType python set omnifunc=pythoncomplete#Complete
let g:SuperTabDefaultCompletionType = "context"

set number
set completeopt=menuone,longest,preview

set autochdir
let NERDTreeChDirMode=2
map <leader>n :NERDTreeToggle<CR> …
Run Code Online (Sandbox Code Playgroud)

vim config

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

Spring MVC中的PUT请求

我正在尝试PUT在Spring MVC中编写一个简单的请求方法.我得到以下内容:

@RequestMapping(value = "/users/{id}", method = RequestMethod.PUT) 
public @ResponseBody User updateUser(@PathVariable("id") long id, 
                                     String name, 
                                     String email) {
        User user = repository.findOne(id);
        user.setName(name);
        user.setEmail(email);
        System.out.println(user.toString());
        repository.save(user);
        return user; 
} 
Run Code Online (Sandbox Code Playgroud)

这显然是错误的,因为它返回以下内容:

User{id=1, name='null', email='null'}
Run Code Online (Sandbox Code Playgroud)

我也试过@RequestBody注释,但这也没有帮助.任何想法我在这里做错了将不胜感激.

java spring spring-mvc

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

标签 统计

spring ×2

config ×1

docker ×1

docker-compose ×1

gunicorn ×1

java ×1

json ×1

nginx ×1

spring-boot ×1

spring-mvc ×1

uwsgi ×1

vim ×1