SQL语言基础
Posted 一叶知秋.
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL语言基础相关的知识,希望对你有一定的参考价值。
依赖注入(dependency injection):是Spring框架核心ioc(inversion of control)的具体实现
注入bean
通过set的方式
package com.example.demo.service.impl;
import com.example.demo.dao.UserDao;
import com.example.demo.service.UserService;
public class UserServiceImpl implements UserService {
private UserDao userDao;
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
@Override
public void save() {
userDao.save();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="userDao" class="com.example.demo.dao.UserDao" />
<bean id="userServiceImpl" class="com.example.demo.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao"/>
</bean>
</beans>
备注:
- name="userDao"中的userDao是根据setUserDao的UserDao(首字母变小写)来的
通过p命名空间的方式
p命名空间注入的本质就是set注入
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="userDao" class="com.example.demo.dao.UserDao" />
<bean id="userServiceImpl" class="com.example.demo.service.impl.UserServiceImpl" p:userDao-ref="userDao"/>
</beans>
备注:
- userDao-ref中的userDao是根据setUserDao的UserDao(首字母变小写)来的
通过构造器的方式
package com.example.demo.service.impl;
import com.example.demo.dao.UserDao;
import com.example.demo.service.UserService;
public class UserServiceImpl implements UserService {
private UserDao userDao;
public UserServiceImpl(UserDao userDao) {
this.userDao = userDao;
}
@Override
public void save() {
userDao.save();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="userDao" class="com.example.demo.dao.UserDao" />
<bean id="userServiceImpl" class="com.example.demo.service.impl.UserServiceImpl">
<constructor-arg name="userDao" ref="userDao"/>
</bean>
</beans>
备注:
- name="userDao"中的userDao是根据public UserServiceImpl(UserDao userDao)(构造器参数名)来的
注入普通数据类型,集合等
以上是关于SQL语言基础的主要内容,如果未能解决你的问题,请参考以下文章