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也同样保持相似行为。

通过这些推荐算法:

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

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


本文转自博客园xingoo的博客,原文链接:Java程序员的日常——SpringMVC+Mybatis开发流程、推荐系统,如需转载请自行联系原博主。

相关文章
|
1月前
|
缓存 前端开发 Java
Spring MVC 面试题及答案整理,最新面试题
Spring MVC 面试题及答案整理,最新面试题
88 0
|
1月前
ssm(Spring+Spring mvc+mybatis)——updateDept.jsp
ssm(Spring+Spring mvc+mybatis)——updateDept.jsp
10 0
|
1月前
ssm(Spring+Spring mvc+mybatis)——showDept.jsp
ssm(Spring+Spring mvc+mybatis)——showDept.jsp
9 0
|
29天前
Mybatis+mysql动态分页查询数据案例——分页工具类(Page.java)
Mybatis+mysql动态分页查询数据案例——分页工具类(Page.java)
21 1
|
1月前
|
SQL JavaScript Java
springboot+springm vc+mybatis实现增删改查案例!
springboot+springm vc+mybatis实现增删改查案例!
25 0
|
1月前
|
SQL Java 数据库连接
挺详细的spring+springmvc+mybatis配置整合|含源代码
挺详细的spring+springmvc+mybatis配置整合|含源代码
40 1
|
29天前
Mybatis+mysql动态分页查询数据案例——工具类(MybatisUtil.java)
Mybatis+mysql动态分页查询数据案例——工具类(MybatisUtil.java)
15 1
|
10天前
|
数据采集 前端开发 Java
数据塑造:Spring MVC中@ModelAttribute的高级数据预处理技巧
数据塑造:Spring MVC中@ModelAttribute的高级数据预处理技巧
22 3
|
10天前
|
存储 前端开发 Java
会话锦囊:揭示Spring MVC如何巧妙使用@SessionAttributes
会话锦囊:揭示Spring MVC如何巧妙使用@SessionAttributes
13 1
|
10天前
|
前端开发 Java Spring
数据之桥:深入Spring MVC中传递数据给视图的实用指南
数据之桥:深入Spring MVC中传递数据给视图的实用指南
29 3