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

做网站费用多少钱网站排名易下拉霸屏

做网站费用多少钱,网站排名易下拉霸屏,百度给公司做网站效果咋样,展示类网站管理员1.纯注解开发【定义配置类的注解】 Confituration 表示该类是一个配置类 ComponentScan(“com.itheima”) 配置包扫描 PropertySource(“classpath:jdbc.properties”) 加载属性文件 Import(JdbcConfig.class) 加载其他配置类 2.spring整合mybatis【纯注解#xff0c;3个…1.纯注解开发【定义配置类的注解】 Confituration 表示该类是一个配置类 ComponentScan(“com.itheima”) 配置包扫描 PropertySource(“classpath:jdbc.properties”) 加载属性文件 Import(JdbcConfig.class) 加载其他配置类 2.spring整合mybatis【纯注解3个配置类】 1SpringConfig配置类 import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.PropertySource;Configuration //表示该类是一个配置类用来代替applicationContext.xml这个注解可以不写但是一般都写了 //context:component-scan base-packagecom.itheima/ ComponentScan(com.itheima) //Spring包扫描 //context:property-placeholder locationclasspath*:*.properties/ PropertySource(classpath:jdbc.properties) //加载属性文件 // import resourceclasspath:applicationContext-dao.xml/ Import(JdbcConfig.class) //引入分配置类 public class SpringConfig { } 2JdbcConfig配置类 import com.alibaba.druid.pool.DruidDataSource; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean;import javax.sql.DataSource;public class JdbcConfig {Value(${jdbc.driver})private String driverClassName;Value(${jdbc.url})private String url;Value(${jdbc.username})private String username;Value(${jdbc.password})private String password;Beanpublic DataSource dataSource() {DruidDataSource ds new DruidDataSource();ds.setDriverClassName(driverClassName);ds.setUrl(url);ds.setUsername(username);ds.setPassword(password);return ds;} } 3MybatisConfig 配置 import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.mapper.MapperScannerConfigurer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import javax.sql.DataSource;public class MybatisConfig {Beanpublic SqlSessionFactoryBean SqlSessionFactoryBean(Autowired DataSource dataSource){SqlSessionFactoryBean ssfb new SqlSessionFactoryBean();//1.注入连接池对象【必须】ssfb.setDataSource(dataSource);//2.加载MybatisConfig.xml核心配置文件// 如果核心配置文件中的内容都被抽取了那么就可以不用加载【可选】//ClassPathResource resource new ClassPathResource(classpath:MybatisConfig.xml);//ssfb.setConfigLocation(resource);//3 配置别名,如果是使用注解配置SQL语句可以不用配置别名【可选】//ssfb.setTypeAliasesPackage(com.itheima.bean);//4 加载映射配置文件如果映射配置文件和mapper接口在同一个包下并且同名那么会自动加载【可选】//ClassPathResource resource new ClassPathResource(classpath:StudentMapper.xml);//ssfb.setMapperLocations(resource);return ssfb;}Beanpublic MapperScannerConfigurer mapperScannerConfigurer(){MapperScannerConfigurer msc new MapperScannerConfigurer();msc.setBasePackage(com.itheima.mapper);return msc;} } 3.具体实现类及测试类 1StudentServiceImpl类 package com.itheima.service.impl;import com.itheima.bean.Student; import com.itheima.mapper.StudentMapper; import com.itheima.service.StudentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;import java.io.IOException; import java.util.List;Service(studentService) public class StudentServiceImpl implements StudentService {Autowiredprivate StudentMapper mapper;//注入StudentMapper的代理对象Overridepublic ListStudent selectAll() throws IOException {return mapper.selectAll();}Overridepublic Student selectById(Integer id) throws IOException {return mapper.selectById(id);}Overridepublic Integer insert(Student stu) throws IOException {return mapper.insert(stu);}Overridepublic Integer update(Student stu) throws IOException {return mapper.update(stu);}Overridepublic Integer delete(Integer id) throws IOException {return mapper.delete(id);} } 2studentMapper类 package com.itheima.mapper; import com.itheima.bean.Student; import org.apache.ibatis.annotations.*;import java.util.List; public interface StudentMapper {//查询全部Select(select * from student)public abstract ListStudent selectAll();//根据id查询Select(select * from student where id#{ID})public abstract Student selectById(Integer id);//新增数据Insert(insert into student values(null,#{name},#{age}))public abstract Integer insert(Student stu);//修改数据Update(update student set name#{name},age#{age} where id#{id})public abstract Integer update(Student stu);//删除数据Delete( delete from student where id#{id})public abstract Integer delete(Integer id); } 3jdbc.properties文件 jdbc.drivercom.mysql.jdbc.Driver jdbc.urljdbc:mysql://localhost:3306/mybatis #不加Jdbc系统会默认username为系统用户名 jdbc.usernameroot jdbc.password123456 ❤️-4测试类 获取容器方式为加载配置类 Testpublic void test1() throws IOException {//从美IOC中取studentService对象//ApplicationContext applicationContext new ClassPathXmlApplicationContext(applicationContext.xml);ApplicationContext applicationContext new AnnotationConfigApplicationContext(SpringConfig.class);StudentService studentService applicationContext.getBean(studentService, StudentService.class);ListStudent list studentService.selectAll();list.forEach(stu- System.out.println(stu));}打印结果 --------------------------------------------------------------------- Student{id1, name张三, age23} Student{id2, name李四, age24} Student{id15, name小郭, age22}4.spring整合junit单元测试 前提添加spring-test和junit依赖并且junit依赖的版本必须大于等于4.12版本。 【第一步】 !--junit--dependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.12/version/dependency!--Spring整合junit单元测试--!--junit的依赖至少要是4.12版本,可以是4.13等版本,否则出现如下异常--dependencygroupIdorg.springframework/groupIdartifactIdspring-test/artifactIdversion5.1.9.RELEASE/version/dependency【第二步】 spring的Junit测试类整合 import com.itheima.bean.Student; import com.itheima.config.SpringConfig; import com.itheima.service.StudentService; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import java.io.IOException; import java.util.List;//【第二步】使用spring中提供的单元测试运行类替换JVM中单元测试运行类 RunWith(SpringJUnit4ClassRunner.class) //【第三步】加载配置文件或者配置类[将bean对象注入容器] ContextConfiguration(classes {SpringConfig.class}) public class StudentJunit {Autowired//[将studentService采用set注入方式则不能new容器对象获取]private StudentService studentService;Testpublic void test1() throws IOException {ListStudent list studentService.selectAll();//断言测试与预期一致则通过反正爆出不同的地方Assert.assertEquals(24,list.size());}Testpublic void test2() throws IOException {Student stu studentService.selectById(20);Assert.assertEquals(陈锦涛,stu.getName());} }
http://www.pierceye.com/news/650325/

相关文章:

  • 盐田高端网站建设湖南网站seo营销多少费用
  • 福州建设招聘信息网站东莞房价将暴跌
  • 外包做网站的要求怎么写网站建设调查分析
  • 北京网站建设公司哪个最好鲜花网页设计模板
  • 汕头网站制作方法江苏网站设计公司
  • 免费1级做看网站上海策朋网站设计公司
  • 自贡做网站的公司wordpress网站加密码
  • 长春建设网站公司哪家好学校网站建设实施方案
  • 邯郸网站优化怎么用建设通网站会员共享密码
  • 怎么使自己做的网站有音乐简易 建站
  • 如何做免费网站制作郑州网站建设搜索优化
  • 北京网站制作17页谈谈对seo的理解
  • 西安专业建网站网站可信度必须做吗
  • 做神马网站如何做网站的推广
  • 如何提高网站排名的方法建设一个商业网站费用
  • 电商网站平台有哪些做自己的第一个网站
  • 源码资源下载站百度指数 多少流量 网站名
  • 合肥比较好的网站建设公司青阳网站建设
  • 上海地产网站建设甘肃建设厅网站二级建造师报名时间
  • 扬州网站建设推广泊头网站建设甘肃
  • 什么行业要做网站建设推广这些水墨网站设计欣赏
  • 渠道网站wap百度
  • 在网站上如何做天气预报栏wordpress 分类列表
  • 做网站需要投资多少钱做网站的销售团队
  • 苏州哪个公司做门户网站seo优化方案报价
  • 电力建设官方网站做网站送优化
  • 门户网站建设模式包括网站群和中企动力企业邮箱登陆首页
  • 做调查网站的问卷哪个给的钱高wordpress邮箱注册功能
  • 上海php网站开发基于php网站建设
  • 大丰专业做网站做旅游网站当地人服务赚钱吗