controller層的單元測試

2021-09-29 19:51:19 字數 1081 閱讀 1545

base的測試類,其他所有測試類繼承這個類:

import org.junit.before;

import org.junit.test;

import org.junit.runner.runwith;

import org.springframework.beans.factory.annotation.autowired;

import org.springframework.test.context.contextconfiguration;

import org.springframework.test.context.junit4.springjunit4classrunner;

import org.springframework.test.web.servlet.mockmvc;

import org.springframework.test.web.servlet.setup.mockmvcbuilders;

@runwith

(springjunit4classrunner.

class

)//使用junit4進行測試

@contextconfiguration

(locations =

)public

class

baseunit

@before

public

void

before()

@test

public

void

test()

throws exception

}

@slf4j

public

class

testcontrollertest

extends

baseunit

}

這邊修改請求的方法型別:get請求就get,put就put.引數的話,如果是json的話,就.content().

controller層的單元測試

base的測試類,其他所有測試類繼承這個類 import org.junit.before import org.junit.test import org.junit.runner.runwith import org.springframework.beans.factory.annotatio...

controller層和service層的作用

1.在controller和service裡都寫那些 controller,從字面上理解是控制器,所以它是負責業務排程的,所以在這一層應寫一些業務的排程 而具體的業務處理應放在service中去寫,而且service不單純是對於dao的增刪改查的呼叫,service是業務層,所以應該更切近於具體業務...

Controller層返回json的格式

ajax3 responsebody public list ajaxtest3 假如集合裡面存的不是物件,而是基本資料型別如下 ajax3 3 responsebody public list ajaxtest3 3 當我返回乙個字串時 value ajax4 produces text html...