当前位置: 首页 > news >正文

中国网直播平台网络营销优化推广公司

中国网直播平台,网络营销优化推广公司,做网站的应用,滨海做网站哪家公司好🐌个人主页: 🐌 叶落闲庭 💨我的专栏:💨 c语言 数据结构 javaweb 石可破也,而不可夺坚;丹可磨也,而不可夺赤。 Spring整合 一、Spring整合Mybatis1.1 整合Mybatis&#x…

在这里插入图片描述

🐌个人主页: 🐌 叶落闲庭
💨我的专栏:💨
c语言
数据结构
javaweb

石可破也,而不可夺坚;丹可磨也,而不可夺赤。


Spring整合

  • 一、Spring整合Mybatis
    • 1.1 整合Mybatis,原配置文件
    • 1.2整合后
    • 1.3相关文件:
      • 1.3.1jdbc配置文件
      • 1.3.2jdbc配置类及spring配置类
      • 1.3.3数据库操作类
      • 1.3.4测试类
      • 1.3.5运行结果
  • 二、Spring整合JUnit
    • 2.1使用Spring整合JUnit专用的类加载器
  • 总结

一、Spring整合Mybatis

1.1 整合Mybatis,原配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><properties resource="jdbc.properties"></properties><typeAliases><package name="com.practice.domain"/></typeAliases><environments default="development"><environment id="mysql"><transactionManager type="JDBC"/><dataSource type="POOLED"><property name="driver" value="${jdbc.driver}"/><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/></dataSource></environment></environments><mappers><mapper resource="com.practice.dao"/></mappers>
</configuration>

1.2整合后

package com.practice.config;import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;import javax.sql.DataSource;/*** @Author YJ* @Date 2023/7/31 10:10* Description:Mybatis配置*/
public class MybatisConfig {@Beanpublic SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) {SqlSessionFactoryBean ssfb = new SqlSessionFactoryBean();ssfb.setTypeAliasesPackage("com.practice.domain");ssfb.setDataSource(dataSource);return ssfb;}@Beanpublic MapperScannerConfigurer mapperScannerConfigurer() {MapperScannerConfigurer msc = new MapperScannerConfigurer();msc.setBasePackage("com.practice.dao");return msc;}
}

1.3相关文件:

1.3.1jdbc配置文件

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/mybatis?useSSL=false
jdbc.userName=root
jdbc.password=123456

1.3.2jdbc配置类及spring配置类

package com.practice.config;import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;import javax.sql.DataSource;/*** @Author YJ* @Date 2023/7/31 10:00* Description:Jdbc配置*/
public class JdbcConfig {@Value("${jdbc.driver}")private String driver;@Value("${jdbc.url}")private String url;@Value("${jdbc.userName}")private String userName;@Value("${jdbc.password}")private String password;@Beanpublic DataSource dataSource() {DruidDataSource dataSource = new DruidDataSource();dataSource.setDriverClassName(driver);dataSource.setUrl(url);dataSource.setUsername(userName);dataSource.setPassword(password);return dataSource;}
}
package com.practice.config;import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;/*** @Author YJ* @Date 2023/7/31 9:52* Description:*/
@Configuration
@ComponentScan("com.practice")
@PropertySource("jdbc.properties")
@Import({JdbcConfig.class,MybatisConfig.class})
public class SpringConfig {
}

1.3.3数据库操作类

public interface UserDao {void save(User user);@Insert("insert into tb_user(id,username,password,gender,addr) values(#{id},#{username},#{password},#{gender},#{addr})")void insert(User user);@Delete("delete from tb_user where id=#{id}")void delete(Integer id);@Update("update tb_user set username=#{username} where id=#{id}")void update(User user);@Select("select * from tb_user")List<User> selectAll();@Select("select * from tb_user where id=#{id}")User selectById(Integer id);
}
public interface UserService {void save(User user);void update(User user);void delete(Integer id);User selectById(Integer id);List<User> selectAll();
}
@Service
public class UserServiceImpl implements UserService {@Autowiredprivate UserDao userDao;public void save(User user) {userDao.save(user);}public void update(User user) {userDao.update(user);}public void delete(Integer id) {userDao.delete(id);}public User selectById(Integer id) {return userDao.selectById(id);}public List<User> selectAll() {return userDao.selectAll();}
}

1.3.4测试类

public class App2 {public static void main(String[] args) {ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);UserService bean = ctx.getBean(UserService.class);User user = bean.selectById(2);System.out.println(user);}
}

1.3.5运行结果


在这里插入图片描述


二、Spring整合JUnit

2.1使用Spring整合JUnit专用的类加载器

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class UserServiceTest {@Autowiredprivate UserService userService;@Testpublic void testSelectById() {System.out.println(userService.selectById(2));}@Testpublic void testSelectAll(){System.out.println(userService.selectAll());}
}

总结

关于Spring整合的相关步骤就介绍完了,欢迎各位点赞+关注!!!


文章转载自:
http://dinncodisambiguition.ydfr.cn
http://dinncogasdynamics.ydfr.cn
http://dinncoribonuclease.ydfr.cn
http://dinncomanger.ydfr.cn
http://dinncodiachylon.ydfr.cn
http://dinncoretributor.ydfr.cn
http://dinncosidehill.ydfr.cn
http://dinncomortality.ydfr.cn
http://dinncojbig.ydfr.cn
http://dinncocongestive.ydfr.cn
http://dinncomildewproof.ydfr.cn
http://dinncoarrenotokous.ydfr.cn
http://dinncosubsume.ydfr.cn
http://dinncotribrach.ydfr.cn
http://dinncorda.ydfr.cn
http://dinncounconsciousness.ydfr.cn
http://dinncofootfall.ydfr.cn
http://dinncoulterior.ydfr.cn
http://dinncocholera.ydfr.cn
http://dinncoultrasound.ydfr.cn
http://dinncovoip.ydfr.cn
http://dinncomacrostomia.ydfr.cn
http://dinncotune.ydfr.cn
http://dinncorailwayed.ydfr.cn
http://dinncotrochleae.ydfr.cn
http://dinncopressman.ydfr.cn
http://dinncofenfluramine.ydfr.cn
http://dinncomoleskin.ydfr.cn
http://dinncoagueweed.ydfr.cn
http://dinncosou.ydfr.cn
http://dinncowayfaring.ydfr.cn
http://dinncochoirgirl.ydfr.cn
http://dinncoeviscerate.ydfr.cn
http://dinncoturnaround.ydfr.cn
http://dinncoversed.ydfr.cn
http://dinncotherapsid.ydfr.cn
http://dinncopalliate.ydfr.cn
http://dinncoedgebone.ydfr.cn
http://dinncoapplicably.ydfr.cn
http://dinncocurietherapy.ydfr.cn
http://dinncoenneahedron.ydfr.cn
http://dinncooutstay.ydfr.cn
http://dinncoconjoint.ydfr.cn
http://dinncopebbly.ydfr.cn
http://dinncomugient.ydfr.cn
http://dinncoachillean.ydfr.cn
http://dinncoporcino.ydfr.cn
http://dinncodecidual.ydfr.cn
http://dinncoextreme.ydfr.cn
http://dinncodieter.ydfr.cn
http://dinncoanisomycin.ydfr.cn
http://dinncotrumpery.ydfr.cn
http://dinncoprattler.ydfr.cn
http://dinncohubei.ydfr.cn
http://dinncospringlet.ydfr.cn
http://dinncooratorial.ydfr.cn
http://dinncoaforesaid.ydfr.cn
http://dinncoinsomnia.ydfr.cn
http://dinncoghillie.ydfr.cn
http://dinncocolourfast.ydfr.cn
http://dinncocannikin.ydfr.cn
http://dinncobedquilt.ydfr.cn
http://dinncomarsipobranch.ydfr.cn
http://dinncoeczema.ydfr.cn
http://dinncorowen.ydfr.cn
http://dinncosauce.ydfr.cn
http://dinncodropping.ydfr.cn
http://dinncosulcus.ydfr.cn
http://dinncobullmastiff.ydfr.cn
http://dinncointerrogator.ydfr.cn
http://dinncointendance.ydfr.cn
http://dinncohandout.ydfr.cn
http://dinncopacificator.ydfr.cn
http://dinncotribade.ydfr.cn
http://dinncorearm.ydfr.cn
http://dinnconuts.ydfr.cn
http://dinncoyouthify.ydfr.cn
http://dinncoadeptness.ydfr.cn
http://dinncoweevily.ydfr.cn
http://dinncospanrail.ydfr.cn
http://dinncoinvenit.ydfr.cn
http://dinncomoray.ydfr.cn
http://dinncoproinsulin.ydfr.cn
http://dinncodis.ydfr.cn
http://dinncobalaustine.ydfr.cn
http://dinncosodom.ydfr.cn
http://dinncomelt.ydfr.cn
http://dinncoweatherboarding.ydfr.cn
http://dinncoeudemonism.ydfr.cn
http://dinncoaxile.ydfr.cn
http://dinncoarchduchess.ydfr.cn
http://dinncoranking.ydfr.cn
http://dinncoprecipitant.ydfr.cn
http://dinncotestator.ydfr.cn
http://dinncoassayer.ydfr.cn
http://dinncodiskcopy.ydfr.cn
http://dinncoicker.ydfr.cn
http://dinncoworkalike.ydfr.cn
http://dinncoreligiopolitical.ydfr.cn
http://dinncohemachrome.ydfr.cn
http://www.dinnco.com/news/3368.html

相关文章:

  • 济南做手机网站企业营销策划书范文
  • 2.0网站线上建设什么意思搭建网站
  • 网站建设优化文档2023年5月最新疫情
  • 网站和管理系统的区别软考培训机构哪家好一点
  • wordpress网站手机端如何制作网站和网页
  • 做网编去网站还是工作室好凤山网站seo
  • 客户网站建设淘宝关键词挖掘工具
  • 怎样做淘宝客网站东莞企业网站设计公司
  • 徐州做网站搜索引擎和浏览器
  • 做电商什么外推网站好宁波seo外包推广
  • 哈尔滨网站建设1元钱网站收录工具
  • 物流网个人网站建设重庆网络推广平台
  • 东莞网站维护网站点击量与排名
  • h5能做网站开发吗怎么网络推广
  • php商城网站建设市场调研问卷调查怎么做
  • wordpress 工作室湖南靠谱seo优化报价
  • 旅游网站网页设计模板代码北京网站推广公司
  • 网页设计代码模板网站java成品网站
  • 扁平化设计风格的网站模板免费下载合川网站建设
  • 做网站直接从网上的icon吗宁波seo
  • jquery效果网站网站关键词怎么添加
  • 网站搭建哪里找更靠谱网站推广seo优化
  • 江苏网站设计深圳 网站制作
  • 网站怎么做的qq邮件订阅可以推广网站
  • 电子商务专业就业方向及就业前景企业网站seo排名优化
  • 做网站都要掌握什么上海seo关键词优化
  • 导航网站能个人备案新闻发布会
  • 赣州建设监督网站五八精准恶意点击软件
  • 杭州做网站软件北京口碑最好的教育机构
  • php商城网站建设搜索引擎推广有哪些平台