手把手教你搭建SSH框架(Eclipse版),你想学的都在这里

4、导入所需Jar包


本期教程用最原始的方法手动导入项目所需Jar包。手动导入会存在Jar包版本冲突等很多问题,建议直接下载使用。在公众号【C you again】后台回复“Jar”自行下载,若不能正常下载,请在后台私信。

将下载好的Jar包复制到WebContent–>WEB-INF–>lib文件夹下,然后选中所有Jar包–>鼠标右击–>Build Path–>Add to Build Path。

5、添加相关配置文件


完成以上基本步骤后,接下来就是SSH整合的关键步骤了。

首先在项目的WebContent–>WEB-INF下的web.xml文件中加入以下配置,如果没有web.xml文件就需要自己新建一个。

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xmlns=“http://java.sun.com/xml/ns/javaee”

xmlns:web=“http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd”

xsi:schemaLocation=“http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd”

id=“WebApp_ID” version=“2.5”>

test.jsp

contextConfigLocation

classpath*:application.xml

org.springframework.web.context.ContextLoaderListener

CharacterEncodingFilter

org.springframework.web.filter.CharacterEncodingFilter

encoding

utf-8

CharacterEncodingFilter

/*

springMvc

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath*:springmvc.xml

1

springMvc

/

完成web.xml的配置后,在前面建好的resources文件夹下新建application.xml,具体解释看文件内部。

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=“http://www.springframework.org/schema/beans”

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xmlns:context=“http://www.springframework.org/schema/context” xmlns:tx=“http://www.springframework.org/schema/tx”

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

<context:component-scan base-package=“com.cya”/>

<bean id=“propertyConfigurer”

class=“org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”>

classpath*:dbconfig.properties

<bean id=“dataSource” class=“com.alibaba.druid.pool.DruidDataSource”

destroy-method=“close”>

<bean id=“sqlSessionFactory”

class=“org.springframework.orm.hibernate3.LocalSessionFactoryBean”>

${hibernate.dialect}

${hibernate.show_sql}

${hibernate.format_sql}

${hibernate.hbm2ddl.auto}

classpath*:hibernate.cfg.xml

<bean id=“transactionManager”

class=“org.springframework.jdbc.datasource.DataSourceTransactionManager”>

<tx:annotation-driven transaction-manager=“transactionManager”/>

接着在resources文件夹下新建springmvc.xml,代码如下:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=“http://www.springframework.org/schema/beans”

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xmlns:context=“http://www.springframework.org/schema/context”

xmlns:mvc=“http://www.springframework.org/schema/mvc”

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<context:component-scan base-package=“com.cya.controller” />

<mvc:annotation-driven />

<bean id=“multipartResolver”

class=“org.springframework.web.multipart.commons.CommonsMultipartResolver”>

同上面的步骤,继续在resources文件夹下新建hibernate.cfg.xml、dbconfig.properties、log4j.properties三个文件。

hibernate.cfg.xml文件:

<?xml version="1.0" encoding="UTF-8"?>

dbconfig.properties文件:

#database connection config

jdbc.driver = com.mysql.jdbc.Driver

jdbc.url = jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&useSSL=false

jdbc.username = root

jdbc.password = root

#hibernate config

hibernate.dialect = org.hibernate.dialect.MySQLDialect

hibernate.show_sql = true

hibernate.format_sql = true

hibernate.hbm2ddl.auto = update

log4j.properties文件:

Set root logger level to error

log4j.rootLogger=INFO, Console, File

Console appender definition

All outputs currently set to be a ConsoleAppender.

log4j.appender.Console=org.apache.log4j.ConsoleAppender

log4j.appender.Console.layout=org.apache.log4j.PatternLayout

log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c{3}] %m%n

#log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n

File appender definition

log4j.appender.File=org.apache.log4j.DailyRollingFileAppender

log4j.appender.File.File=spring.log

log4j.appender.File.Append=false

log4j.appender.File.layout=org.apache.log4j.PatternLayout

log4j.appender.File.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n

至此,所有的整合步骤已经完成了,最后的目录结构如下所示,接下来就是设计测试用例了。

6、测试项目能否正常运行


完成上述步骤后,接下来就测试下整合是否成功吧!

在src–>com.cya.entity下创建Person.java实体类

package com.cya.entity;

public class Person {

private int id;

private String name;

private int age;

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

}

在resources下新建mapping目录,用来保存所有的数据库映射文件。mapping目录下创建映射文件:Person.hbm.xml,具体配置如下:

<?xml version="1.0" encoding="utf-8"?>

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加V获取:vip1024b (备注Java)
img

面试结束复盘查漏补缺

每次面试都是检验自己知识与技术实力的一次机会,面试结束后建议大家及时总结复盘,查漏补缺,然后有针对性地进行学习,既能提高下一场面试的成功概率,还能增加自己的技术知识栈储备,可谓是一举两得。

以下最新总结的阿里P6资深Java必考题范围和答案,包含最全MySQL、Redis、Java并发编程等等面试题和答案,用于参考~

重要的事说三遍,关注+关注+关注!

历经30天,说说我的支付宝4面+美团4面+拼多多四面,侥幸全获Offer

image.png

更多笔记分享

历经30天,说说我的支付宝4面+美团4面+拼多多四面,侥幸全获Offer

[外链图片转存中…(img-k8Mx0js1-1712030919180)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加V获取:vip1024b (备注Java)
[外链图片转存中…(img-koprz04n-1712030919181)]

面试结束复盘查漏补缺

每次面试都是检验自己知识与技术实力的一次机会,面试结束后建议大家及时总结复盘,查漏补缺,然后有针对性地进行学习,既能提高下一场面试的成功概率,还能增加自己的技术知识栈储备,可谓是一举两得。

以下最新总结的阿里P6资深Java必考题范围和答案,包含最全MySQL、Redis、Java并发编程等等面试题和答案,用于参考~

重要的事说三遍,关注+关注+关注!

[外链图片转存中…(img-4A2E2UCz-1712030919181)]

[外链图片转存中…(img-LRt8URuR-1712030919182)]

更多笔记分享

[外链图片转存中…(img-ErS4FMxV-1712030919182)]

  • 20
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当然可以!以下是手把手搭建 YOLOv5 的步骤: 1. 准备工作: - 确保你的电脑已经安装了 Python 3.8 或更高本。 - 安装 PyTorch:可以根据你的操作系统和 CUDA 本选择合适的安装命令,例如: ```shell pip install torch torchvision torchaudio ``` - 安装其他依赖库: ```shell pip install opencv-python matplotlib numpy ``` 2. 下载 YOLOv5 源代码: - 在终端中运行以下命令来克隆 YOLOv5 仓库: ```shell git clone https://github.com/ultralytics/yolov5.git ``` 3. 安装依赖库: - 进入 yolov5 目录: ```shell cd yolov5 ``` - 安装依赖库: ```shell pip install -r requirements.txt ``` 4. 准备数据集: - 准备好你的训练数据集,并将图像和对应的标签文件放入一个文件夹中。 5. 配置模型和数据: - 编辑 `yolov5/models/yolov5s.yaml` 文件,根据你的需求进行配置,例如设置 `nc` 参数为你的类别数量。 - 编辑 `data.yaml` 文件,设置 `train` 和 `val` 的路径,并配置类别数量和类别名称。 6. 训练模型: - 在终端中运行以下命令来开始训练模型: ```shell python train.py --img 640 --batch 16 --epochs 100 --data data.yaml --cfg models/yolov5s.yaml --weights '' ``` - 这个命令将使用默认参数来训练 YOLOv5 模型,你可以根据需要进行调整。 7. 测试模型: - 在终端中运行以下命令来测试模型效果: ```shell python detect.py --source your_image.jpg --weights runs/train/exp/weights/best.pt --conf 0.4 ``` - 这个命令将使用训练好的模型对指定图像进行目标检测,你可以调整 `--conf` 参数来控制检测结果的置信度阈值。 以上就是搭建 YOLOv5 的基本步骤,希望对你有帮助!如果有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值