java回顾:ssm整合、纯注解开发

news2025/6/10 2:59:52

目录

一、搭建环境 

1.1、spring环境搭建 

 1.1.1 测试SpringIOC环境

 1.2、搭建Mybatis环境(原生mybatis)

二、Spring整合mybatis

三、Spring整合SpringMVC

四、SSM执行流程

五、纯注解开发配置文件模板


声明:

SpringMVC:
    注解 + XML
        注解: @Controller + @RequestMapping
        xml: 总控制器 视图解析 开启注解扫描
Spring:
    IOC: 
        全XML
        半XML半注解 ★
        全注解
    AOP:
        XML
Mybatis:
    核心配置 + sql映射xml
    核心配置 + 注解 ★
-----------------------
1.搭建Spring环境 IOC
2.搭建Mybatis环境 核心配置+sql映射xml
3.Spring和Mybatis整合
    加入Spring的AOP
4.搭建SpringMVC环境
5.整合SpringMVC和Spring整合

一、搭建环境 

1.1、spring环境搭建 

maven依赖:


    <properties>
        <!-- 定义变量 -->
        <spring-version>5.0.2.RELEASE</spring-version>
    </properties>

    <dependencies>
        <!-- spring核心jar包 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring-version}</version>
        </dependency>
        <!-- Mybatis jar包 -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.5</version>
        </dependency>
        <!-- Spring整合jdbc的jar包 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring-version}</version>
        </dependency>
        <!-- spring和junit的整合坐标 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring-version}</version>
        </dependency>
        <!-- springmvc的坐标 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring-version}</version>
        </dependency>
        <!-- mysql驱动包 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <!-- spring整合mybatis的坐标 -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.0</version>
        </dependency>
        <!-- aspectJ坐标 切入点表达式-->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.13</version>
        </dependency>
        <!-- junit的整合坐标 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <!-- Servlet的jar包 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <!-- jsp的jar包 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- jstl的jar包-->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- druid jar包 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.13</version>
        </dependency>
        <!-- c3p0 jar包 -->
        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>
        
         <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.20</version>
        </dependency>
    </dependencies>

数据库:

CREATE TABLE `account2` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(40) DEFAULT NULL,
  `money` float DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

INSERT INTO `account2` VALUES ('1', 'tom', '1000');
INSERT INTO `account2` VALUES ('2', 'rose', '1000');
INSERT INTO `account2` VALUES ('3', 'jack', '1000');

实体类:                                                                        

@Data//getting、setting、equals、canEqual、hashCode、toString
@AllArgsConstructor
@NoArgsConstructor
public class Account {
    //基本类型int有默认值 可能会干扰代码
    private Integer id;
    private String name;
    private Float money;
}

service:

public interface AccountService {
    List<Account> findAll();
}

@Service("accountService")
public class AccountServiceImpl implements AccountService {
    @Override
    public List<Account> findAll() {
        System.out.println("findAll方法被调用");
        return null;
    }
}

applicationContext.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- 开启包扫描 -->
    <context:component-scan base-package="com.hhy"/>
</beans>

 1.1.1 测试SpringIOC环境

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class TestSpring {

    @Resource(name = "accountService")
    private AccountService acS;

    @Test
    public void t1() {
        acS.findAll();
    }
}

 1.2、搭建Mybatis环境(原生mybatis)

xml模板可以去mybatis官网复制

mybatis – MyBatis 3 | 入门  

AccountDao.java

public interface AccountDao {
    List<Account> findAll();
}

AccountDao.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hhy.dao.AccountDao">
    <!--resultType="account"此处使用了别名,因为在mybatisConfig中使用了<typeAliases>扫包-->
    <select id="findAll" resultType="account">
<!--    <select id="findAll" resultType="com.hhy.pojo.Account">-->
        select * from account;
    </select>
</mapper>

mybatisConfig.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <!-- 1.配置需要解析的properties文件 -->
    <properties resource="jdbc.properties"></properties>
    <!-- 2.批量给pojo取别名 -->
    <typeAliases>
        <package name="com.hhy.pojo"></package>
    </typeAliases>
    <!-- 3.配置连接数据的环境 -->
    <environments default="development">
        <environment id="development">
            <!-- 使用JDBC默认的事务管理 -->
            <transactionManager type="JDBC" />
            <!-- 配置连接池, POOLED:使用Mybatis的连接池 -->
            <dataSource type="POOLED">
                <property name="driver" value="${jdbc.driverClass}" ></property>
                <property name="url" value="${jdbc.url}" ></property>
                <property name="username" value="${jdbc.userName}"></property>
                <property name="password" value="${jdbc.password}"></property>
            </dataSource>
        </environment>
    </environments>
    <!-- 4.配置sql映射文件的位置 -->
    <mappers>
        <!-- 配置sql映射文件所在的包
            要求:
                sql映射文件的名称要和dao接口的名称保持一致
                sql映射文件的包路径要和接口的包路径保持一致
         -->
        <package name="com.hhy.dao" ></package>
    </mappers>
</configuration>

jdbc.properties:

jdbc.userName=root
jdbc.password=123456
jdbc.url=jdbc:mysql:///test0908
jdbc.driverClass=com.mysql.jdbc.Driver

测例:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class TestMybatis {

    @Resource(name = "accountService")
    private AccountService acS;

    @Test
    public void t1() throws IOException {
        //1.获取核心配置文件的文件流对象
        InputStream is = Resources.getResourceAsStream("mybatisConfig.xml");
        //2.获取SqlSessionFactory会话工厂对象
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        //3.获取SqlSession会话对象
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //4.获取接口的代理对象
        AccountDao mapper = sqlSession.getMapper(AccountDao.class);
        //5.调用方法执行
        List<Account> list = mapper.findAll();
        for (Account account : list) {
            System.out.println(account);
        }
        System.out.println(list);
        //6.关闭流
        sqlSession.close();
        is.close();
    }
}

二、Spring整合mybatis

注释mybatisConfig.xml文件,全部配置在applicationContext.xml文件中。

AccountServiceImpl:

@Service("accountService")
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;

    @Override
    public List<Account> findAll() {
        System.out.println("findAll方法被调用");
        return accountDao.findAll();
    }
}

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       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"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <!-- 开启包扫描 -->
    <context:component-scan base-package="com.hhy"/>
    <!--引入外部jdbc.properties资源-->
    <context:property-placeholder location="classpath:jdbc.properties"/>
    <!--配置数据源-->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <!--此处如需使用jdbc.properties中值,需引入-->
        <property name="url" value="${jdbc.url}"/>
        <property name="driverClassName" value="${jdbc.driverClass}"/>
        <property name="username" value="${jdbc.userName}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>
    <!--配置spring整合mybatis-->
    <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--在mybatisConfig.xml配置的数据源不属于spring管理的方式,需重新配置-->
        <property name="dataSource" ref="dataSource"/>
        <!-- 2.批量给pojo取别名 -->
        <property name="typeAliasesPackage" value="com.hhy.pojo"/>
        <!--引入mybatis核心配置文件-->
<!--        <property name="configLocation" value="classpath:mybatisConfig.xml"/>-->
    </bean>
    <!--配置接口扫描:dao加入ioc管理,spring扫描mapper的方式-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.hhy.dao"/>
    </bean>
    <!-- TODO:Spring的AOP 托管Mybatis的事务控制 -->
    <!-- 配置事务管理器对象 -->
    <!--此处id名要与事务注解内部AliasFor注解名相同-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <!--事务-->
<!--    <tx:advice id="myAdvice" transaction-manager="transactionManager">-->
<!--        <tx:attributes>-->
<!--            <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>-->
<!--            <tx:method name="*" propagation="REQUIRED" read-only="false"/>-->
<!--        </tx:attributes>-->
<!--    </tx:advice>-->
<!--     &lt;!&ndash;配置AOP&ndash;&gt;-->
<!--    <aop:config>-->
<!--        &lt;!&ndash;配置切面&ndash;&gt;-->
<!--        <aop:pointcut id="pt" expression="execution(* com.hhy.service.impl.*.*(..))"/>-->
<!--        <aop:advisor advice-ref="myAdvice" pointcut-ref="pt"></aop:advisor>-->
<!--    </aop:config>-->
    <!-- 开启AOP注解的支持 -->
    <aop:aspectj-autoproxy/>
    <!--开启事务注解驱动-->
    <tx:annotation-driven/>
</beans>

AccountServiceImpl.java

@Service("accountService")
@Transactional(propagation = Propagation.REQUIRED ,readOnly = false)
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public List<Account> findAll() {
        System.out.println("findAll方法被调用");
        return accountDao.findAll();
    }
}

测例:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class TestSpring {

    @Resource(name = "accountService")
    private AccountService acS;

    @Test
    public void t1() {
        final List<Account> all = acS.findAll();
        System.out.println("all = " + all);
    }
}

三、Spring整合SpringMVC

spring的配置项applicationContext.xml扫描dao和service层,为父容器,

而springMVC的配置项专门扫描controller层,为子容器,子容器可以调用父容器的bean,controller注入service,service为父容器的bean。

pom.xml新增依赖:

<!--json格式所需要的依赖-->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.9.8</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.8</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.8</version>
        </dependency>

 applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       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"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <!-- 开启包扫描 -->
    <context:component-scan base-package="com.hhy">
        <!--排除controller层的bean,springmvc会单独扫描
        (此处expression可以进入@controller右键复制全限定名)-->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <!--引入外部jdbc.properties资源-->
    <context:property-placeholder location="classpath:jdbc.properties"/>
    <!--配置数据源-->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <!--此处如需使用jdbc.properties中值,需引入-->
        <property name="url" value="${jdbc.url}"/>
        <property name="driverClassName" value="${jdbc.driverClass}"/>
        <property name="username" value="${jdbc.userName}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>
    <!--配置spring整合mybatis-->
    <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--在mybatisConfig.xml配置的数据源不属于spring管理的方式,需重新配置-->
        <property name="dataSource" ref="dataSource"/>
        <!-- 2.批量给pojo取别名 -->
        <property name="typeAliasesPackage" value="com.hhy.pojo"/>
        <!--引入mybatis核心配置文件-->
<!--        <property name="configLocation" value="classpath:mybatisConfig.xml"/>-->
    </bean>
    <!--配置接口扫描:dao加入ioc管理,spring扫描mapper的方式-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.hhy.dao"/>
    </bean>
    <!-- TODO:Spring的AOP 托管Mybatis的事务控制 -->
    <!-- 配置事务管理器对象 -->
    <!--此处id名要与事务注解内部AliasFor注解名相同-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <!--事务-->
<!--    <tx:advice id="myAdvice" transaction-manager="transactionManager">-->
<!--        <tx:attributes>-->
<!--            <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>-->
<!--            <tx:method name="*" propagation="REQUIRED" read-only="false"/>-->
<!--        </tx:attributes>-->
<!--    </tx:advice>-->
<!--     &lt;!&ndash;配置AOP&ndash;&gt;-->
<!--    <aop:config>-->
<!--        &lt;!&ndash;配置切面&ndash;&gt;-->
<!--        <aop:pointcut id="pt" expression="execution(* com.hhy.service.impl.*.*(..))"/>-->
<!--        <aop:advisor advice-ref="myAdvice" pointcut-ref="pt"></aop:advisor>-->
<!--    </aop:config>-->
    <!-- 开启AOP注解的支持 -->
    <aop:aspectj-autoproxy/>
    <!--开启事务注解驱动-->
    <tx:annotation-driven/>
</beans>

springmvc.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       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"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <!--开启包扫描,springmvc专用,仅扫描controller层bean-->
    <context:component-scan base-package="com.hhy.controller"/>
    <!--配置视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
    <!-- 配置注解驱动 -->
    <mvc:annotation-driven/>
    <!-- 配置静态资源不做拦截 -->
    <mvc:default-servlet-handler/>
</beans>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <!--配值servletContext共享域:通知spring:父容器的位置-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <!--配置监听器(tomcat启动),tomcat一启动就触发加载applicationContext.xml-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!--配置核心控制器(前端控制器/调度控制器/总控制器)servlet-->
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- 配置SpringMVC的核心配置文件/资源 -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springmvc.xml</param-value>
        </init-param>
        <!--配置servlet加载时机-->
        <load-on-startup>1</load-on-startup>
    </servlet>
    <!--配置映射规则-->
    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <!--给前端控制器配置的路径为 / (缺省匹配)可以匹配浏览器发送的所以请求
             注意: jsp除外-->
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- 在web.xml中配置springMVC编码过滤器 -->
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <!-- 设置过滤器中的属性值 -->
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <!-- 过滤所有请求 -->
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- 配置静态资源处理 -->
<!--    <servlet-mapping>-->
<!--        <servlet-name>default</servlet-name>-->
<!--        <url-pattern>*.html</url-pattern>-->
<!--        <url-pattern>*.css</url-pattern>-->
<!--        <url-pattern>*.js</url-pattern>-->
<!--        <url-pattern>*.png</url-pattern>-->
<!--    </servlet-mapping>-->
</web-app>

AccountController.java:

@Controller
public class AccountController {

    @Resource(name = "accountService")
    private AccountService accS;

    @RequestMapping(value = "/account/findAll")
    @ResponseBody
    public List<Account> findAll(){
        List<Account> all = accS.findAll();
        return all;
    }
}

四、SSM执行流程

当服务器启动时,只会加载web项目的核心配置文件 ------ web.xml。

web.xml中配置servletContext共享域,及监听器,监听器(监听tomcat启动),tomcat一启动就触发加载applicationContext.xml,获取父容器。

web.xml中配置servlet,tomcat解析自动创建DispatcherServlet对象调用初始化方法,拿到springmvc.xml文件,形成子容器。

父容器扫包service及dao层且排除controller层,子容器单独扫controller层。

五、纯注解开发配置文件模板

https://blog.csdn.net/m0_56678122/article/details/128388031

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/104825.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

[streamlit]数据科学科研工作者的神器,必须要推荐一下

1. 前言 做科研当然要有过硬的专业知识&#xff0c;但是也少不了一些辅助&#xff0c;才能最大程度发挥我们的能力。因此&#xff0c;除去我们模型性能优秀&#xff0c;结果良好以外&#xff0c;如何进行一个好的展示&#xff0c;也是非常有必要的。那么今天&#xff0c;我们就…

推荐系统:基于ConvNCF推荐算法的推荐系统实现 代码+数据详细教程

1.案例知识点 推荐系统任务描述:通过用户的历史行为(比如浏览记录、购买记录等等)准确的预测出用户未来的行为;好的推荐系统不仅如此,而且能够拓展用户的视野,帮助他们发现可能感兴趣的却不容易发现的item;同时将埋没在长尾中的好商品推荐给可能感兴趣的用户。ConvNCF推…

西瓜书-决策树

决策树 决策树划分时&#xff0c;当前属性集为空&#xff0c;或所有样本在所有属性上取值相同&#xff0c;将结点标记为叶节点&#xff0c;其类别标记为当前样本集中样本数最多的类。 决策树算法的核心在于&#xff1a;选择最优划分属性 判别分类的三种情形&#xff1a; 当前…

[前端攻坚]:详解call、apply、bind的实现

call apply bind 的实现的面试中几乎必定出现的一些内容&#xff0c;今天来用一篇文章整理一下这里的内容&#xff0c;加深一下JS基础知识体系。同时文章也被收录到我的《JS基础》专栏中&#xff0c;欢迎大家点击收藏加关注。 call的实现 call() 方法使用一个指定的 this 值和单…

Oracle Ask Tom分区学习系列: 面向开发者的分区(Partitioning)教程

Oracle Partitioning: A Step-by-Step Introduction for Developers是Oracle数据库开发者课程之一。 Development with Oracle Partitioning/使用 Oracle 分区进行开发 Partitioning in the database reflects the same way we handle large tasks in the real world. When a t…

Redis分布式锁的10个坑

前言 大家好&#xff0c;我是田螺。 日常开发中&#xff0c;经常会碰到秒杀抢购等业务。为了避免并发请求造成的库存超卖等问题&#xff0c;我们一般会用到Redis分布式锁。但是使用Redis分布式锁&#xff0c;很容易踩坑哦~ 本文田螺哥将给大家分析阐述&#xff0c;Redis分布式…

如何优化 MySQL 服务器

有一些数据库服务器的优化技术&#xff0c;主要是管理系统配置而不是调整 SQL 语句。它适用于那些希望确保服务器的性能以及可伸缩性的 DBA&#xff0c;以及适用于启动安装脚本建立数据库和运行 MySQL 自己进行开发、测试等以提生产力的开发人员。 系统因素 一些系统级方面也会…

推荐几个方法教你学会怎样制作视频剪辑

随着时代的发展&#xff0c;新媒体行业的壮大&#xff0c;应该不少小伙伴每天都需要制作视频剪辑吧&#xff0c;有些可能是因为从事短视频行业&#xff0c;每天就需要发送视频内容&#xff0c;才能吸引观众&#xff0c;也有些可能只是想单纯分享一些生活视频。那你知道如何制作…

List接口-ArrayList、LinkedList和Vector

1.List 接口和常用方法 1.1List 接口基本介绍 import java.util.ArrayList; import java.util.List;public class List_ {SuppressWarnings({"all"})public static void main(String[] args) {//1. List集合类中元素有序(即添加顺序和取出顺序一致)、且可重复 [案例]…

Linux网络编程之socket通信

Linux网络编程之socket通信 一、socket相关函数使用 1.1 IP地址转换函数&#xff1a; 小端法&#xff1a;&#xff08;pc本地存储&#xff09; 高位存高地址&#xff0c;低位存低地址。 大端法&#xff1a;&#xff08;网络存储&#xff09; 高位存低地址&#xff0c;低位存…

13基于多目标粒子群算法的微电网优化调度(matlab程序)

参考文献 基于多目标粒子群算法的微电网优化调度——王金全&#xff08;2014电网与清洁能源&#xff09; 主要内容 针对光伏电池、风机、微型燃气轮机、柴油发电机以及蓄电池组成的微电网系统的优化问题进行研究&#xff0c;在满足系统约束条件下&#xff0c;建立了包含运行…

day25【代码随想录】左叶子之和、找树左下角的值、从中序与后序遍历序列构造二叉树、从中序与前序遍历序列构造二叉树、最大二叉树

文章目录前言一、左叶子之和&#xff08;力扣404&#xff09;1、递归遍历2、非递归遍历二、找树左下角的值&#xff08;力扣513&#xff09;1、迭代法&#xff08;层序遍历&#xff09;2、递归法三、从中序与后序遍历序列构造二叉树&#xff08;力扣106&#xff09;四、从中序与…

微服务框架 SpringCloud微服务架构 微服务面试篇 54 微服务篇 54.1 SpringCloud常见组件有哪些?

微服务框架 【SpringCloudRabbitMQDockerRedis搜索分布式&#xff0c;系统详解springcloud微服务技术栈课程|黑马程序员Java微服务】 微服务面试篇 文章目录微服务框架微服务面试篇54 微服务篇54.1 SpringCloud常见组件有哪些&#xff1f;54 微服务篇 54.1 SpringCloud常见组…

【验证码逆向专栏】某片滑块、点选验证码逆向分析

声明 本文章中所有内容仅供学习交流使用&#xff0c;不用于其他任何目的&#xff0c;不提供完整代码&#xff0c;抓包内容、敏感网址、数据接口等均已做脱敏处理&#xff0c;严禁用于商业用途和非法用途&#xff0c;否则由此产生的一切后果均与作者无关&#xff01; 本文章未…

30岁了想转行学Python,来得及吗?

是否来得及要看决心有多大&#xff0c;行动力有多强。一般来说&#xff0c;只要目标明确&#xff0c;足够自律&#xff0c;心理强大&#xff0c;做任何事情都是来得及的&#xff0c;当下就是最好的开始。30岁真的不算啥&#xff0c;有人四五十岁才开始奋斗&#xff0c;依然能过…

C语言之内存管理(十七)(转世灵童现世)

上一篇: C语言入门篇之轮回法器&#xff08;十六&#xff09;&#xff08;指针第五卷&#xff09; 逐梦编程&#xff0c;让中华屹立世界之巅。 简单的事情重复做,重复的事情用心做,用心的事情坚持做&#xff1b; 文章目录前言一、内存管理具体介绍1.作用域2.生命周期的定义3.局…

为什么说学人工智能一定要学Python?

有很多人在问博主&#xff0c;为什么人工智能学习要用Python&#xff1f;运行速度慢不好之类的&#xff0c;今天就让博主谈谈自己的感受。 先来说说前景 随着“大数据”“云计算”“人工智能”等等科技的兴起&#xff0c;IT行业在今后三到五年将会迎来一个高速发展期。这也就意…

QT调用python传递图像和二维数组,并接受python返回值(图像)

任务目的&#xff1a; 用QT调用python代码&#xff0c;将QT读取的图像(Mat矩阵)作为参数传入python中&#xff0c;将QT的二维数组作为参数传递给python&#xff0c;python接收QT传入的图像进行计算&#xff0c;将结果返回给QT。 实现过程 1.新建QT项目 说明&#xff1a;QT的…

[Cortex-M3]-5-cache uncache

目录 1 cache的引入 2 cache的工作原理 3 cache使用限制 1 cache的引入 程序运行的流程&#xff08;很简单&#xff09;&#xff1a; 程序编译&#xff1a;存放在flash&#xff1b;程序加载&#xff1a;程序加载到内存&#xff1b;程序运行&#xff1a;指令从内存复制到CP…

【产品人卫朋】自媒体运营的5个阶段,以及增长策略

本篇内容以微信公众号为例讲解自媒体的运营策略。 建立一个快速发展的微信公众号&#xff0c;需要多长时间呢&#xff1f; 有些人在一年内就可以建立一个蓬勃发展的公众号&#xff0c;而其他人则可能需要两年、三年甚至是五年的时间。 在发展的过程中&#xff0c;你的公众号将经…