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

百度有做企业网站吗网盘资源免费观看

百度有做企业网站吗,网盘资源免费观看,做网站业务员怎么样,灵台县门户网站✅作者简介:2022年博客新星 第八。热爱国学的Java后端开发者,修心和技术同步精进。 🍎个人主页:Java Fans的博客 🍊个人信条:不迁怒,不贰过。小知识,大智慧。 💞当前专栏…

在这里插入图片描述

✅作者简介:2022年博客新星 第八。热爱国学的Java后端开发者,修心和技术同步精进。
🍎个人主页:Java Fans的博客
🍊个人信条:不迁怒,不贰过。小知识,大智慧。
💞当前专栏:SpringBoot 框架从入门到精通
✨特色专栏:国学周更-心性养成之路
🥭本文内容:SpringBoot 整合 JSP 和 MyBatis

文章目录

    • 💖 Spring Boot starter入门
    • 💖 SpringBoot基本设置
      • 6.1 SpringBoot设置端口号
      • 6.2 SpringBoot设置项目名
      • 6.3 SpringBoot配置文件的拆分
      • 6.4 SpringBoot开启日志
      • 6.5 SpringBoot实现热部署
      • 6.6 SpringBoot开启分页查询
    • 💖 springBoot对象管理
    • 💖 springBoot整合JSP
    • 💖 SpringBoot整合MyBatis

在这里插入图片描述

💖 Spring Boot starter入门

  传统的 Spring 项目想要运行,不仅需要导入各种依赖,还要对各种 XML 配置文件进行配置,十分繁琐,但 Spring Boot 项目在创建完成后,即使不编写任何代码,不进行任何配置也能够直接运行,这都要归功于 Spring Boot 的 starter 机制

  Spring Boot 将日常企业应用研发中的各种场景都抽取出来,做成一个个的 starter(启动器),starter 中整合了该场景下各种可能用到的依赖,用户只需要在 Maven 中引入 starter 依赖,SpringBoot 就能自动扫描到要加载的信息并启动相应的默认配置。starter 提供了大量的自动配置,让用户摆脱了处理各种依赖和配置的困扰。所有这些 starter 都遵循着约定成俗的默认配置,并允许用户调整这些配置,即遵循“约定大于配置”的原则

  并不是所有的 starter 都是由 Spring Boot 官方提供的,也有部分 starter 是第三方技术厂商提供的,例如 druid-spring-boot-starter 和 mybatis-spring-boot-starter 等等。当然也存在个别第三方技术,Spring Boot 官方没提供 starter,第三方技术厂商也没有提供 starter

  以 spring-boot-starter-web 为例,它能够为提供 Web 开发场景所需要的几乎所有依赖,因此在使用 Spring Boot 开发 Web 项目时,只需要引入该 Starter 即可,而不需要额外导入 Web 服务器和其他的 Web 依赖

    <!--SpringBoot父项目依赖管理--><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.5.13</version><relativePath/></parent><dependencies><!--导入 spring-boot-starter-web--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>...</dependencies>
</project>

  您可能会发现一个问题,即在以上 pom.xml 的配置中,引入依赖 spring-boot-starter-web 时,并没有指明其版本(version),但在依赖树中,我们却看到所有的依赖都具有版本信息,那么这些版本信息是在哪里控制的呢?

  其实,这些版本信息是由 spring-boot-starter-parent(版本仲裁中心) 统一控制的。

spring-boot-starter-parent

  spring-boot-starter-parent 是所有 Spring Boot 项目的父级依赖,它被称为 Spring Boot 的版本仲裁中心,可以对项目内的部分常用依赖进行统一管理。

<!--SpringBoot父项目依赖管理-->
<parent>  <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter-parent</artifactId>    <version>2.4.5</version>    
</parent>

  Spring Boot 项目可以通过继承 spring-boot-starter-parent 来获得一些合理的默认配置,它主要提供了以下特性:

  • 默认 JDK 版本(Java 8)
  • 默认字符集(UTF-8)
  • 依赖管理功能
  • 资源过滤
  • 默认插件配置
  • 识别 application.properties 和 application.yml 类型的配置文件

💖 SpringBoot基本设置

6.1 SpringBoot设置端口号

server:port: 8989 #配置端口

6.2 SpringBoot设置项目名

server:servlet:context-path: /springboot   #配置项目的虚拟路径(根路径) 项目名使用/开头

6.3 SpringBoot配置文件的拆分

spring:profiles:active: dev  #开发环境    

在这里插入图片描述

6.4 SpringBoot开启日志

# 显示sql
logging:level:cn.kgc.springboot.mapper: debug  #开启日志

6.5 SpringBoot实现热部署

  在web项目的开放过程中,通常我们每次修改完代码都需要重新启动项目,实现重新部署。但是随着项目越来越庞大,每次启动都是一个费时的事情。所以,热部署是一个非常构建的技术,有了热部署,可以极大提高我们的开发效率

spring-boot-devtools实现热部署

1.引入依赖

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId>
</dependency>

2.配置maven插件

<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><fork>true</fork> <!-- 如果devtools不生效  请设置该属性 --></configuration></plugin></plugins>
</build>

3.配置application.yml文件

devtools:restart:enabled: true #开启热部署

4.修改idea设置

File-Settings-Compiler 勾选 Build Project automatically

5.设置Registry

ctrl + shift + alt + / ,选择Registry,勾选Compiler autoMake allow when app running

6.6 SpringBoot开启分页查询

1.引入依赖:

<dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>1.2.12</version>
</dependency>----------------------------------------------<dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>1.2.10</version>
</dependency>

2.配置application.yml文件(可以不配置使用默认)

# pageHelper分页配置
pagehelper:helper-dialect: mysql  #数据库类型reasonable: true   #分页合理化 page<1 查询第一页 page >pageNumber 查询最后一页support-methods-arguments: true  # 支持mapper接口传递参数开启分页params: count=countSql  #用于从对象中根据属性名取值

3.编写控制器,业务层,持久化层进行测试

@Override
public PageInfo<User> getPage(int pageNum, int pageSize) {PageHelper.startPage(pageNum, pageSize);List<User> userList = userMapper.selectList();PageInfo<User> pageInfo = new PageInfo<>(userList);return pageInfo;
}

💖 springBoot对象管理

  • 管理对象

    spring中管理对象的方式:

    1.使用xml配置文件,在文件中使用bean标签设置对象的管理

    <bean id="" class="xxx.xxx.xxx"></bean>
    

    2.使用注解 @Component @Controller @Service @Repository
      
    springboot管理对象的方式:

    1.使用配置方式创建对象
      
      springboot支持使用 @Configuration 注解添加在配置类上,该类作为一个配置类,相当于spring的配置文件,该注解只能使用在类上。在配置类中方法上使用 @Bean 注解,相当于spring配置文件中的bean标签

    @Configuration
    public class MyConfiguration{@Beanpublic User getUser(){return new User();}@Beanpublic Student getStudent(){return new Student();}
    }
    

    2.使用原始的 spring 注解 @Component @Controller @Service @Repository

  • 属性注入

    spring 原始的注入方式

    1.set方式

    2.constructor

    3.自动注入

    name: tom
    age: 30
    price: 23.5
    sex: true
    birth: 2021/11/28 12:12:12
    array: 12,13,15,17
    list: 李四,lisi,tom
    map: "{'aa':30,'bb':'lisi'}" # 注入map使用json格式  取值的个数#{${map}}
    

    对象的注入

    object:name: lisiage: 20birth: 2021/11/24
    
    @Controller
    @RequestMapping("/inject2")
    @ConfigurationProperties("object")
    public class InjectController2 {private String name;private Integer age;private Date birth;public void setName(String name) {this.name = name;}public void setAge(Integer age) {this.age = age;}public void setBirth(Date birth) {this.birth = birth;}@RequestMapping("/inject")@ResponseBodypublic String inject(){System.out.println(name);System.out.println(age);System.out.println(birth);return  "ok";}
    }
    

    注意:添加一下依赖,可以再写yaml文件时提示,消除红色的警告提示。

    <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional>
    </dependency>
    

💖 springBoot整合JSP

引入依赖

<!--        标准标签库-->
<dependency><groupId>jstl</groupId><artifactId>jstl</artifactId><version>1.2</version>
</dependency>
<!--        让springboot内置的tomcat具有解析jsp的能力-->
<dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-jasper</artifactId>
</dependency>

配置视图解析器

spring:mvc:view:prefix: /suffix: .jsp

设置不重启项目 刷新jsp页面

server:servlet:jsp:init-parameters:development: true  # 修改jsp页面无需重新启动项目

集成后无法访问jsp页面解决方案

1.添加插件

<build><resources><!--注册webapp目录为资源目录--><resource><directory>src/main/webapp</directory><targetPath>META-INF/resources</targetPath><includes><include>**/*.*</include></includes></resource></resources><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins>
</build>

2.设置工作目录

在这里插入图片描述

3.插件启动

在这里插入图片描述

💖 SpringBoot整合MyBatis

引入依赖

<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.47</version>
</dependency>
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.3</version>
</dependency>
<dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.12</version>
</dependency>

编写配置文件

spring:datasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.jdbc.Driverusername: rootpassword: rooturl: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&characterEncoding=utf-8

mybatis配置

mybatis:mapper-locations: classpath:mapper/*.xml  #设置mapper文件的位置type-aliases-package: cn.kgc.springboot.entity # 起别名configuration:map-underscore-to-camel-case: true #开启驼峰命名

设置dao接口的扫描

1.在入口类上使用注解,完成扫描

@SpringBootApplication
@MapperScan("cn.kgc.springboot.dao") //扫描dao接口所在的包 同时生成代理对象 注入spring容器
public class Springday02Application {public static void main(String[] args) {SpringApplication.run(Springday02Application.class, args);}
}

  码文不易,本篇文章就介绍到这里,如果想要学习更多Java系列知识点击关注博主,博主带你零基础学习Java知识。与此同时,对于日常生活有困扰的朋友,欢迎阅读我的第四栏目:《国学周更—心性养成之路》,学习技术的同时,我们也注重了心性的养成。

在这里插入图片描述

http://www.lbrq.cn/news/2757457.html

相关文章:

  • 网站关键词在哪里添加虎门今日头条新闻
  • 做导航网站电商运营主要负责什么
  • 网站做全好吗4p营销理论
  • 电商网站是获取流量公司网站费用
  • 潮州网站seo推广职业培训机构排名前十
  • js网站分页怎么做seo推广效果
  • 企业网站建设经济效益分析有没有免费的seo网站
  • 做公司网站详细步骤6微信群推广网站
  • 装修平台网站百度竞价代运营
  • 做海报的网站有哪些seo高端培训
  • 能打开各种网站的浏览器app抖音广告代运营
  • 缤纷网站免费做服装seo常用的工具
  • 章贡区网站建设一个新品牌怎样营销推广
  • 网站备案名称几个字常用seo站长工具
  • 做商务网站服务google推广及广告优缺点
  • 网站建设公司渠道自己怎么做百度推广
  • 济南百度推广电话成都seo培训
  • 网站从设计到制作做一个公司网站大概要多少钱
  • 网站开发进度设计站长之家产品介绍
  • 做h5网站pc加手机版要多少钱学生网页制作成品
  • kotlin做网站seo免费培训视频
  • 记事本怎么做网站图片链接怎么进行网站关键词优化
  • 大庆公司做网站怎样制作网页设计
  • 自学编程网站广州seo优化公司
  • 上海做网站多少钱seo引擎优化是什么
  • 小榄公司网站建设著名的网络营销案例
  • 企业查查app下载seo搜索引擎优化课程总结
  • 哪个网站做废旧好手机百度收录提交入口
  • 武汉网站建设团队seo网站推广软件
  • 晋江网站开发谷歌推广新手教程
  • 数据结构(03)——线性表(顺序存储和链式存储)
  • 大厂 | 华为半导体业务部2026届秋招启动
  • Critic-V: VLM Critics Help Catch VLM Errors in Multimodal Reasoning(CVPR 2025)
  • 给纯小白的Python操作 PDF 笔记
  • 民法学学习笔记(个人向) Part.5
  • 【昇腾】单张48G Atlas 300I Duo推理卡MindIE+WebUI方式跑7B大语言模型_20250816