首页 Web入门
文章
取消

Web入门

1.SpringBootWeb快速入门

image-20240110160539636

注意:java版本与jdk版本不一致

image-20240110162112495

image-20240110162347593

注意:创建不了java.class文件

这里没有创建Java选项的可以在目录Java那里点击鼠标右键选择将目录标记为——»源代码根目录

image-20240110163231410

2.创建springboot

image-20240110165254273

新建一个controller.hello.class,并编写以下代码,在浏览器说如localhost:8080/hello就可以访问到

image-20240110170845578

3.HTTp协议

image-20240110171143964

image-20240110172243067

image-20240110190259295

image-20240110190349914

image-20240110190452567

image-20240110190620527

image-20240110190759383

状态嘛大全:

[HTTP - 状态Status - 开发者手册 - 腾讯云开发者社区-腾讯云 (tencent.com)](https://cloud.tencent.com/developer/chapter/13553)

4.Web服务器

image-20240111201508039

如何将项目布置到tomcat中

image-20240111201634398

image-20240111201750934

启动tomcat

访问

image-20240111201844962

Tomcat介绍

image-20240111201954580

image-20240111204910287

image-20240111204948356

image-20240111204956995

image-20240111205015933

dispatcherServlet叫做核心控制器或者前端控制器

image-20240111205321441

请求响应

原始方式

image-20240111205846984

SpringBoot方式

image-20240111205914049

image-20240111210110274

总结

image-20240111210246984

简单实体对象

image-20240111210549172

复杂实体对象

image-20240111210609725

数组集合参数

image-20240111211110546

集合请求方式

image-20240111211238933

image-20240111211533881

日期参数

image-20240111211611815

JSON参数

利用RequestBody注解

image-20240111211842691

image-20240111212204659

响应数据

image-20240111212600225

  • 不便管理
  • 难以维护

统一的响应结果

image-20240111213323130

请求-响应

image-20240111214255018

小demo

image-20240111214911810

  • 复用性差
  • 难以维护

分层解耦

image-20240111215006143

image-20240111215036111

image-20240112132113974

IOC&DI入门

image-20240112132522415

  • 这个对象怎么交给容器进行管理–》控制反转
  • 容器怎么为程序提供它所依赖的资源–》依赖注入

image-20240112133131830

image-20240112133855388

  • 如果要切换实现类,只要将你想要切换的那个类加上@Component注解,将原来类的注解删掉就行

IOC详解

image-20240112134844582

image-20240112134905275

Bean组件扫描

image-20240112135220581

扫描不到包,有两个解决办法

  1. 在启动程序中,手动设置包扫描,手动设置之后,之前的包也需要手动设置一遍,比如:com.itheimaimage-20240112135443180
  2. 把所有包都放在启动类所在包的下面

Di详解

springboot中Autowired注解是什么作用?

在Spring Boot中,@Autowired 是一个用于自动装配DI的注解。它用于告诉Spring容器在需要某个类型的Bean时,通过自动装配的方式来提供该类型的实例。

image-20240112140951022

image-20240112141012920

image-20240112141055827

动态sql写法

select

1
2
3
4
5
6
7
8
9
10
11
12
<select id="page" resultType="SetMeal">
    select * from setmeal
    <where>
        <if test="name != null">
        and name like concat('%',#{name},'%') </if>
        <if test="categoryId != null">
        and category_Id = #{categoryId}</if>
        <if test="status != null">
        and status = #{status}</if>
    </where>
    order by create_time desc
</select>

update

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<update id="updateDish" useGeneratedKeys="true" keyProperty="id" parameterType="Dish">
    update dish
    <set>
        <if test="name != null">name = #{name},</if>
        <if test="categoryId != null">category_Id = #{categoryId},</if>
        <if test="price != null">price = #{price},</if>
        <if test="image != null">image = #{image},</if>
        <if test="description != null">description = #{description},</if>
        <if test="createTime != null">create_Time = #{createTime},</if>
        <if test="updateTime != null">update_Time = #{updateTime},</if>
        <if test="createUser != null">create_User = #{createUser},</if>
        <if test="updateUser != null">update_User = #{updateUser},</if>
        <if test="status != null">status =#{status},</if>
    </set>
    where id = #{id}
</update>
本文由作者按照 CC BY 4.0 进行授权
热门标签