今天大部分時間都在寫業務代碼,然后算是從無到有的配置了下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也同樣保持相似行為。
通過這些推薦算法:
- 一方面可以在首頁保證用戶的留存,不會一進來就跳出。
- 另一方面,在移動端等有限的位置,可以更精准的推銷給用戶產品。
- 另外,還可以做一些去留存的功能。比如倉庫里面堆積了很多過時的產品,可以通過推薦去庫存。
總的來說,有舍就有得。想要共享全網數據,就需要自己也奉獻出來數據。這種取舍還是需要企業進行衡量的。