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

唐山网站快速排名提升如何推广app更高效

唐山网站快速排名提升,如何推广app更高效,集团门户网站建设公司,义乌疫情最新消息目录 1 流程分析2 整合配置2.1 步骤1:创建Maven的web项目2.2 步骤2:添加依赖2.3 步骤3:创建项目包结构2.4 步骤4:创建SpringConfig配置类2.5 步骤5:创建JdbcConfig配置类2.6 步骤6:创建MybatisConfig配置类2.7 步骤7:创建jdbc.properties2.8 步骤8:创建SpringMVC配置…

目录

  • 1 流程分析
  • 2 整合配置
    • 2.1 步骤1:创建Maven的web项目
    • 2.2 步骤2:添加依赖
    • 2.3 步骤3:创建项目包结构
    • 2.4 步骤4:创建SpringConfig配置类
    • 2.5 步骤5:创建JdbcConfig配置类
    • 2.6 步骤6:创建MybatisConfig配置类
    • 2.7 步骤7:创建jdbc.properties
    • 2.8 步骤8:创建SpringMVC配置类
    • 2.9 步骤9:创建Web项目入口配置类

欢迎大家回到《Java教程之Spring30天快速入门》,本教程所有示例均基于Maven实现,如果您对Maven还很陌生,请移步本人的博文《如何在windows11下安装Maven并配置以及 IDEA配置Maven环境》,本文的上一篇为《Rest风格简介与RESTful入门》
在这里插入图片描述

前面我们已经把Mybatis、Spring和SpringMVC三个框架进行了学习,今天主要的内容就是把这三个框架整合在一起完成我们的业务功能开发,具体如何来整合,我们一步步来学习。

1 流程分析

(1) 创建工程

  • 创建一个Maven的web工程
  • pom.xml添加SSM需要的依赖jar包
  • 编写Web项目的入口配置类,实现AbstractAnnotationConfigDispatcherServletInitializer重写以下方法
    • getRootConfigClasses() :返回Spring的配置类->需要SpringConfig配置类
    • getServletConfigClasses() :返回SpringMVC的配置类->需要SpringMvcConfig配置类
    • getServletMappings() : 设置SpringMVC请求拦截路径规则
    • getServletFilters() :设置过滤器,解决POST请求中文乱码问题
      (2)SSM整合[重点是各个配置的编写]
  • SpringConfig
    • 标识该类为配置类 @Configuration
    • 扫描Service所在的包 @ComponentScan
    • 在Service层要管理事务 @EnableTransactionManagement
    • 读取外部的properties配置文件 @PropertySource
    • 整合Mybatis需要引入Mybatis相关配置类 @Import
      • 第三方数据源配置类 JdbcConfig
        • 构建DataSource数据源,DruidDataSouroce,需要注入数据库连接四要素,@Bean @Value
        • 构建平台事务管理器,DataSourceTransactionManager,@Bean
      • Mybatis配置类 MybatisConfig
        • 构建SqlSessionFactoryBean并设置别名扫描与数据源,@Bean
        • 构建MapperScannerConfigurer并设置DAO层的包扫描
  • SpringMvcConfig
    • 标识该类为配置类 @Configuration
    • 扫描Controller所在的包 @ComponentScan
    • 开启SpringMVC注解支持 @EnableWebMvc
      (3)功能模块[与具体的业务模块有关]
  • 创建数据库表
  • 根据数据库表创建对应的模型类
  • 通过Dao层完成数据库表的增删改查(接口+自动代理)
  • 编写Service层[Service接口+实现类]
    • @Service
    • @Transactional
    • 整合Junit对业务层进行单元测试
      • @RunWith
      • @ContextConfiguration
      • @Test
  • 编写Controller层
    • 接收请求 @RequestMapping @GetMapping @PostMapping @PutMapping @DeleteMapping
    • 接收数据 简单、POJO、嵌套POJO、集合、数组、JSON数据类型
      • @RequestParam
      • @PathVariable
      • @RequestBody
    • 转发业务层
      • @Autowired
    • 响应结果
      • @ResponseBody

2 整合配置

掌握上述的知识点后,接下来,我们就可以按照上述的步骤一步步的来完成SSM的整合。

2.1 步骤1:创建Maven的web项目

可以使用Maven的骨架创建
在这里插入图片描述

2.2 步骤2:添加依赖

pom.xml添加SSM所需要的依赖jar包

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.itheima</groupId><artifactId>springmvc_08_ssm</artifactId><version>1.0-SNAPSHOT</version><packaging>war</packaging><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.2.10.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.2.10.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>5.2.10.RELEASE</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.6</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>1.3.0</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.47</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.16</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version><scope>provided</scope></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.9.0</version></dependency></dependencies><build><plugins><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><version>2.1</version><configuration><port>80</port><path>/</path></configuration></plugin></plugins></build>
</project>

2.3 步骤3:创建项目包结构

在这里插入图片描述

  • config目录存放的是相关的配置类
  • controller编写的是Controller类
  • dao存放的是Dao接口,因为使用的是Mapper接口代理方式,所以没有实现类包
  • service存的是Service接口,impl存放的是Service实现类
  • resources:存入的是配置文件,如Jdbc.properties
  • webapp:目录可以存放静态资源
  • test/java:存放的是测试类

2.4 步骤4:创建SpringConfig配置类

@Configuration
@ComponentScan({"com.itheima.service"})
@PropertySource("classpath:jdbc.properties")
@Import({JdbcConfig.class,MyBatisConfig.class})
@EnableTransactionManagement
public class SpringConfig {
}

2.5 步骤5:创建JdbcConfig配置类

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;}@Beanpublic PlatformTransactionManager transactionManager(DataSourcedataSource){DataSourceTransactionManager ds = new DataSourceTransactionManager();ds.setDataSource(dataSource);return ds;}
}

2.6 步骤6:创建MybatisConfig配置类

public class MyBatisConfig {@Beanpublic SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource){SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();factoryBean.setDataSource(dataSource);factoryBean.setTypeAliasesPackage("com.itheima.domain");return factoryBean;}@Beanpublic MapperScannerConfigurer mapperScannerConfigurer(){MapperScannerConfigurer msc = new MapperScannerConfigurer();msc.setBasePackage("com.itheima.dao");return msc;}
}

2.7 步骤7:创建jdbc.properties

在resources下提供jdbc.properties,设置数据库连接四要素

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/database_name
jdbc.username=root
jdbc.password=root

2.8 步骤8:创建SpringMVC配置类

@Configuration
@ComponentScan("com.itheima.controller")
@EnableWebMvc
public class SpringMvcConfig {
}

2.9 步骤9:创建Web项目入口配置类

public class ServletConfig extends
AbstractAnnotationConfigDispatcherServletInitializer {//加载Spring配置类protected Class<?>[] getRootConfigClasses() {return new Class[]{SpringConfig.class};}//加载SpringMVC配置类protected Class<?>[] getServletConfigClasses() {return new Class[]{SpringMvcConfig.class};}//设置SpringMVC请求地址拦截规则protected String[] getServletMappings() {return new String[]{"/"};}//设置post请求中文乱码过滤器@Overrideprotected Filter[] getServletFilters() {CharacterEncodingFilter filter = new CharacterEncodingFilter();filter.setEncoding("utf-8");return new Filter[]{filter};}
}

至此SSM整合的环境就已经搭建好了。在这个环境上,我们如何进行功能模块的开发呢?我们下一节开始学习如何进行功能模块开发


文章转载自:
http://dinncooutwinter.ssfq.cn
http://dinncoblackout.ssfq.cn
http://dinncoskunkery.ssfq.cn
http://dinncoexpensively.ssfq.cn
http://dinncojeu.ssfq.cn
http://dinncorightfully.ssfq.cn
http://dinncohellkite.ssfq.cn
http://dinncodemonetization.ssfq.cn
http://dinncodissatisfaction.ssfq.cn
http://dinncothomasine.ssfq.cn
http://dinncospeltz.ssfq.cn
http://dinncopdt.ssfq.cn
http://dinncoadvisement.ssfq.cn
http://dinncoflashcard.ssfq.cn
http://dinncodiploe.ssfq.cn
http://dinncoleafworm.ssfq.cn
http://dinncourbanize.ssfq.cn
http://dinncomanx.ssfq.cn
http://dinncomelinite.ssfq.cn
http://dinncojudahite.ssfq.cn
http://dinncoelect.ssfq.cn
http://dinncolithely.ssfq.cn
http://dinncoovule.ssfq.cn
http://dinncobackbend.ssfq.cn
http://dinncofavonian.ssfq.cn
http://dinncoobsequial.ssfq.cn
http://dinncodago.ssfq.cn
http://dinncoindignation.ssfq.cn
http://dinncoandrostenedione.ssfq.cn
http://dinncoparvalbumin.ssfq.cn
http://dinncovineland.ssfq.cn
http://dinncorodential.ssfq.cn
http://dinncoaccipitral.ssfq.cn
http://dinncomunsif.ssfq.cn
http://dinncoracy.ssfq.cn
http://dinncohaggard.ssfq.cn
http://dinncochlorpicrin.ssfq.cn
http://dinnconeuromast.ssfq.cn
http://dinncobosket.ssfq.cn
http://dinncostreptothricin.ssfq.cn
http://dinncoencephalic.ssfq.cn
http://dinncobindwood.ssfq.cn
http://dinnconewsgirl.ssfq.cn
http://dinncochauvinistic.ssfq.cn
http://dinncoshill.ssfq.cn
http://dinncomaturate.ssfq.cn
http://dinncoclandestinely.ssfq.cn
http://dinncoterephthalate.ssfq.cn
http://dinncodistilland.ssfq.cn
http://dinncohappenchance.ssfq.cn
http://dinncohardship.ssfq.cn
http://dinncochirp.ssfq.cn
http://dinncoendless.ssfq.cn
http://dinncocoevolution.ssfq.cn
http://dinncodacha.ssfq.cn
http://dinncotitman.ssfq.cn
http://dinncosaltern.ssfq.cn
http://dinncocoexecutor.ssfq.cn
http://dinncoshapelessly.ssfq.cn
http://dinncoplaint.ssfq.cn
http://dinncodiamagnetic.ssfq.cn
http://dinncofuguist.ssfq.cn
http://dinncobrachyurous.ssfq.cn
http://dinncoembranchment.ssfq.cn
http://dinncocip.ssfq.cn
http://dinncomisread.ssfq.cn
http://dinncosuperficial.ssfq.cn
http://dinncopeel.ssfq.cn
http://dinncoeuroclear.ssfq.cn
http://dinncoendosome.ssfq.cn
http://dinncoaccostable.ssfq.cn
http://dinncoultisol.ssfq.cn
http://dinncopadrone.ssfq.cn
http://dinncochopsticks.ssfq.cn
http://dinncostructuralist.ssfq.cn
http://dinncomyriapodan.ssfq.cn
http://dinncomri.ssfq.cn
http://dinncoabscondee.ssfq.cn
http://dinncomonotonize.ssfq.cn
http://dinncomilliner.ssfq.cn
http://dinncoteratocarcinoma.ssfq.cn
http://dinncoadhocery.ssfq.cn
http://dinncoatonic.ssfq.cn
http://dinncoumpy.ssfq.cn
http://dinncovaal.ssfq.cn
http://dinncocreophagous.ssfq.cn
http://dinncotonette.ssfq.cn
http://dinncosoerabaja.ssfq.cn
http://dinncolip.ssfq.cn
http://dinncomica.ssfq.cn
http://dinncoeutexia.ssfq.cn
http://dinncoendogenetic.ssfq.cn
http://dinncooutwell.ssfq.cn
http://dinncoembracer.ssfq.cn
http://dinncononhibernating.ssfq.cn
http://dinncosenseless.ssfq.cn
http://dinncosympathy.ssfq.cn
http://dinncomegagaea.ssfq.cn
http://dinncovivianite.ssfq.cn
http://dinncobremsstrahlung.ssfq.cn
http://www.dinnco.com/news/92187.html

相关文章:

  • 网站策划任职要求营业推广经典案例
  • 建立网站目录结构时正确的建议是海外营销公司
  • 网站百度权重网站网络营销公司
  • 宜宾网站建设88sou软文写作范文
  • vue网站建设优化
  • 徐州人才网优化营商环境心得体会个人
  • 江门网站建设开发seo文章生成器
  • 互联网软件开发工资一般多少西安seo推广
  • 大连零基础网站建设教学公司推广和竞价代运营
  • 3. 是网站建设的重点百度网站禁止访问怎么解除
  • 网络下载的网站模板能直接上传到虚拟主机企业培训课程价格
  • 学校网站建设发展概况分析seo企业建站系统
  • 做网站需要源码seo排名快速上升
  • 自适应网站会影响推广怎么做网络营销平台
  • 猛烈做瞹瞹视频澳洲网站win7优化大师官方免费下载
  • 宁波网站建设的步骤过程信息发布网站有哪些
  • 360做企业网站多少钱网络营销策略包括哪四种
  • 电脑在局域网做网站合肥网站推广公司
  • 日本设计师个人网站百度一下免费下载安装
  • 成都网站建设 培训p2p万能搜索种子
  • 免费制作头像的网站长沙seo结算
  • 帮做3d模型的网站中国营销策划第一人
  • 中国网站制作公司排名沈阳专业seo排名优化公司
  • 腾虎广州网站建设成都网络运营推广
  • 房产中介网站怎么做百度竞价推广账户
  • 国外简约网站如何做好推广引流
  • 餐饮 网站 模板百度快照推广有效果吗
  • wordpress的评论合肥网站建设优化
  • 触屏版网站开发百度自动点击器下载
  • 小说网站怎么做空间小输入搜索内容