zoukankan      html  css  js  c++  java
  • Java程序员的日常——SpringMVC+Mybatis开发流程、推荐系统

    今天大部分时间都在写业务代码,然后算是从无到有的配置了下spring与mybatis的集成。

    SpringMVC+Mybatis Web开发流程

    配置数据源

    在applicationContext.xml中引入数据源的配置:

    <context:component-scan base-package="com.test" ></context:component-scan>
    
    <context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true" />
    
    <import resource="spring-my-datasource.xml"/>
    

    在spring-my-datasource.xml中配置数据源相关的内容:

    <!-- 配置数据源 使用的是ali的durid-->
    <bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        <property name="url" value="${url}" />
    	<property name="username" value="${username}" />
    	<property name="password" value="${password}" />
    	<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
    	<property name="initialSize" value="1" />
    	<property name="maxActive" value="80" />
    	<property name="minIdle" value="10" />
    	<property name="maxWait" value="60000" />
    	<property name="testOnBorrow" value="false" />
    	<property name="testOnReturn" value="false" />
    	<property name="testWhileIdle" value="true" />
    	<property name="timeBetweenEvictionRunsMillis" value="1000" />
    	<property name="minEvictableIdleTimeMillis" value="10000" />
    	<property name="removeAbandoned" value="true" />
    	<property name="removeAbandonedTimeout" value="3600" />
    	<property name="logAbandoned" value="true" />
    	<property name="filters" value="mergeStat" />
    	<property name="validationQuery" value="select 1 from dual"/>
    </bean>	
    <!-- 配置sessionFactory -->
    <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
    	<!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
    	<property name="typeAliasesPackage" value="com.test.entity" />
    	<!-- 显式指定Mapper文件位置 -->
    	<property name="mapperLocations" value="classpath:mybatis/**/*Mapper.xml" />
    </bean>
    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    
    <!-- 拦截器方式配置事物 -->
    <tx:advice id="transactionAdvice" transaction-manager="transactionManager">
        <tx:attributes>
    	    <tx:method name="*" read-only="true" />
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut id="transactionPointcut" expression="execution(* com.test.service.*.*(..))" />
    	<aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
    </aop:config>
    

    配置完成后,工程的目录结构如下:

    com.test
    ---controller(存放controller类)
    ---dao(存放mybaits mapper接口)
    ---service(存放service)
    
    mybatis
    --testMapper.xml
    

    在controller中设置相应的链接:

    @RestController
    @RequestMapping("/test")
    public class testController {
    
        @Autowired
    	private TestService testService;
    	
    	@RequestMapping(value = "abc/123")
    	public Page getDataProfilingDetail(HttpServletRequest request, @ModelAttribute TestDto testDto){
    	    return testService.getSomething(testDto);
    	}
    }
    

    其中Dto是自己封装的参数对象:

    public class TestDto{
        private String a;
        public void setA(String a){
            this.a = a;
        }
        public String getA(){
            return a;
        }
    }
    

    然后编写Service代码:

    @Service
    public class TestService {
    
        @Autowired
    	private TestMapper testMapper;
    	
    	public Integer getSomething(TestDto testDto){
    		return testMapper.getSomething(testDto);
    	}
    }
    

    然后是相应的Mapper接口:

    public interface TestMapper {
    	public Integer getSomething(@Param(value="testDto")TestDto testDto);
    }
    

    最后配置上mybatis的配置文件即可:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.test.dao.TestMapper">
    	<select id="getSomething"  resultType="Map">
    		select * from xxx
    	</select>
    

    关于百分点推荐系统

    下午的时候去参加了百分点的推荐系统的交流会,算是对推荐系统有了很多的了解。

    相关的技术点:

    • 1 百分点通过sass服务,接通全网的线上数据。
    • 2 通过1可以达到跨终端、跨站的联合推荐,并且是毫秒级延迟的。比如你在某站看中了口红,那么换一个电商,可能还会推荐给你口红;再比如在手机上看到了某个产品,也可以同步到web端。
    • 3 这种跨终端、跨站的推荐,可以通过两种方式实现。一种是精准推荐,即需要用户登录过,然后绑定终端信息与用户信息,这样就可以进行跨站、终端的推荐了。另外还可以通过网站的cookie来实现跨站的推荐同步;另一种就是模糊推荐,是根据大量的操作习惯、无线网络等信息进行判断的。
    • 4 推荐算法上最常用的就是协同过滤...A与B和C都有相似的购买行为,那么B和C有相似行为的D与A也同样保持相似行为。

    通过这些推荐算法:

    • 一方面可以在首页保证用户的留存,不会一进来就跳出。
    • 另一方面,在移动端等有限的位置,可以更精准的推销给用户产品。
    • 另外,还可以做一些去留存的功能。比如仓库里面堆积了很多过时的产品,可以通过推荐去库存。

    总的来说,有舍就有得。想要共享全网数据,就需要自己也奉献出来数据。这种取舍还是需要企业进行衡量的。

  • 相关阅读:
    【JS】限制两个或多个单选框最多只能选择一个
    Markdown基本语法
    【thinkphp5】 分页样式修改
    Vscode 修改为中文语言
    【linux】Crontab 定时任务 使用实例
    【微信开发】 模板消息发送
    二维数组转化为字符串,中间用,隔开
    【golang】 go语言之环境搭建+ 第一个go语言程序
    【PHPstudy】安装Composer
    【LNMP】基于阿里云的https免费证书配置
  • 原文地址:https://www.cnblogs.com/xing901022/p/5846899.html
Copyright © 2011-2022 走看看