@Autowired
@Autowired
IPersonService personService;
相当于IPersonService personService = new PersonService();
常由于调用service方法
@RequestMapping
@RequestMapping(path="/xx")
Public class xxx{}
写在类上面指定当前模块路径
@Repository、@Controller、@Service、@Component
- @Component:最普通的组件,可以被注入到spring容器进行管理.不知道用什么注解时候就用这个
- @Repository:作用于持久层
- @Service:作用于业务逻辑层,也就是一般的service层里的
- @Controller:作用于表现层(**spring-mvc*******的注解)
@RunWith(SpringJUnit4ClassRunner.class)
ContextConfiguration(“classpath:applicationContext.xml”)
这种写法是为了让测试在Spring容器下运行,需要配置applicationContext.xml
ResponseBody
调Jackson将返回的对象转为json字符串
public @ResponseBody
Object list(){
List<Department> list = departmentService.findAllDepartments();
return Result.init(200,"",list);//返回对象需要被转成json字符串
}