2017/12/31
承接上文:Spring(13):新增功能:超市订单的供应商表查询 and 根据供应商名称查询供应商信息--功能实现(上)
Spring框架下的相关函数:
1、ClassPathXmlApplicationContext构造方法:
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-mybatis.xml");
ClassPathXmlApplicationContext
public ClassPathXmlApplicationContext(String configLocation) throws BeansException
Parameters:
configLocation
- resource location
Throws:
BeansException
- if context creation failed
2、getBean()方法:
ProviderService providerService = (ProviderService) ctx.getBean("providerServiceImpl");
getBean
public Object getBean(String name) throws BeansException
Description copied from interface: BeanFactory
This method allows a Spring BeanFactory to be used as a replacement for the Singleton or Prototype design pattern. Callers may retain references to returned objects in the case of Singleton beans.
Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.
Specified by:
getBean
in interface
BeanFactory
Parameters:
name
- the name of the bean to retrieve
Returns:
an instance of the bean Throws:
NoSuchBeanDefinitionException
- if there is no bean definition with the specified name
BeansException
- if the bean could not be obtained
sqlSession 类的相关函数:
【根据查询是否需要传参来确定】
1、selectList
<E> List<E> selectList(String statement)
Type Parameters:
E
- the returned list element type
Parameters:
statement
- Unique identifier matching the statement to use.
Returns:
List of mapped object
或:
2、selectList
<E> List<E> selectList(String statement, Object parameter)
Type Parameters:
E
- the returned list element type
Parameters:
statement
- Unique identifier matching the statement to use.
parameter
- A parameter object to pass to the statement.
Returns: