springAop原理代理模式 1:Target
注解的种类: @resource(为成员变量注入值)
@compant @service @respority @controller 四个特性是一样的
<context:component-scan base-package="com.shuiming"></context:component-scan> 作用1:扫描所有的bean 等价于<bean id="xxxx" class="xxxxxx"> 2:为所有的Bean的成员变量注入值. @Component(value="clinic") public class Clinic { private String name; private int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; }
}
关键代码
package com.shuiming.controller;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import org.springframework.stereotype.Controller; import org.springframework.stereotype.Repository; import org.springframework.ui.Model; import org.springframework.web.WebApplicationInitializer; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController;
import com.shuiming.bean.Clinic; import com.shuiming.service.BussinessService; @RestController @RequestMapping("spring") public class SpringMvcDispatcher { private BussinessService bussiness; /@Autowired/ @Resource(name="clinic") private Clinic clinic; /* @RequestMapping(method = RequestMethod.POST) public void welcomeHandler(@RequestParam String name,@RequestParam String password) { System.out.println(bussiness); System.out.println(name); System.out.println(password); } / @RequestMapping(method = RequestMethod.POST) public String welcomeHandler(@ModelAttribute("clinic") Clinic clinic) { / System.out.println(bussiness); */ System.out.println(clinic.getName()); return "welcome"; }
/@RequestMapping("/vets") public ModelMap vetsHandler() { return new ModelMap(this.clinic.getVets()); }/
}