Spring(13):新增功能:超市订单的供应商表查询 and 根据供应商名称查询供应商信息--解释(下)

本文介绍如何使用Spring框架实现超市订单的供应商表查询及根据供应商名称查询供应商信息的功能。主要涉及ClassPathXmlApplicationContext的配置加载、getBean方法的使用以及sqlSession的selectList方法进行数据查询。

2017/12/31

承接上文:Spring(13):新增功能:超市订单的供应商表查询 and 根据供应商名称查询供应商信息--功能实现(上)(http://blog.youkuaiyun.com/qq_29166327/article/details/78943953)


Spring框架下的相关函数:

1、ClassPathXmlApplicationContext构造方法:

ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-mybatis.xml");

ClassPathXmlApplicationContext

public ClassPathXmlApplicationContext(String configLocation)
                               throws BeansException
Create a new ClassPathXmlApplicationContext, loading the definitions from the given XML file and automatically refreshing the context.

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
Return an instance, which may be shared or independent, of the specified bean.

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)
Retrieve a list of mapped objects from the statement key and parameter.

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)
Retrieve a list of mapped objects from the statement key and 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:
List of mapped object




评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

后台技术汇

对你的帮助,是对我的最好鼓励。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值