发表于: 2016-11-11 11:01:24

5 2063


(昨天不知道老大看我的日志和评论,有点不敬的地方,请见谅。)

一.今天完成的事情

    1.完成Spring配置IOC(与MyBatis的整合) (请各位前辈指点,并指出我项目中不符合规范的部分 看如下           代码和配置)

       (看完Spring的三种配置方式之后,我的选择是尽量用注解加XML配置的混合方式)

      我项目的目录:

             

  Spring和MyBatis整合后,我只用到一个配置文件application.xml:

  

<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:aop="http://www.springframework.org/schema/aop"

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

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

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

http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

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

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

     <!-- 引入jdbc配置文件 -->  

     <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

        <property name="locations">

            <list>

               <value>properties/*.properties</value>

                <!--要是有多个配置文件,只需在这里继续添加即可 -->

            </list>

        </property>

    </bean>

    <!-- 配置数据源 -->

    <bean id="dataSource"

        class="org.springframework.jdbc.datasource.DriverManagerDataSource">

        <!-- 不使用properties来配置 -->

        <!-- <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 

            <property name="url" value="jdbc:mysql://localhost:3306/xiuzhenyuan" /> 

            <property name="username" value="root" /> 

            <property name="password" value="wj521" /> -->

       <!-- 使用properties来配置 -->

        <property name="driverClassName">

            <value>${jdbc_driverClassName}</value>

        </property>

        <property name="url">

            <value>${jdbc_url}</value>

        </property>

        <property name="username">

            <value>${jdbc_username}</value>

        </property>

        <property name="password">

            <value>${jdbc_password}</value>

        </property>

    </bean>

     <!-- 自动扫描了所有的XxxxMapper.xml对应的mapper接口文件,这样就不用一个一个手动配置Mpper的映射了,只要Mapper接口类和Mapper映射文件对应起来就可以了。 -->

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

        <property name="basePackage"

            value="com.wangsx.dao" />

    </bean> 

    <!-- 配置Mybatis的文件 ,mapperLocations配置**Mapper.xml文件位置,configLocation配置mybatis-config文件位置-->

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

        <property name="dataSource" ref="dataSource" />

        <!-- <property name="mapperLocations" value="classpath:mapper/*.xml"/> -->  

        <!-- <property name="configLocation" value="mybatis/mybatis-config.xml" /> -->

    </bean>

    <!-- 自动扫描注解的bean -->

    <context:component-scan base-package="com.wangsx.service" />

</beans>

二.明天的计划

      1.学习 Rest接口风格 (1和2说了三天啦,一直没有学没有看,明天再不看不做,把我变成猪)懒猪

      2.使用SpringMVC完成REST接口。

      3.看其他前辈做完任务一关于Spring+MyBatis的日志。(看他们的项目各种规范和和编码风格)

三.遇到的问题

   1.对service和Impl的差别模棱两可(有人提到了三层架构,看后更不明确啦)

   

   

public class StudentServiceImpl implements StudentService {


private StudentMapper studentMapper;

public Student selectStudentById(int id) {

return studentMapper.selectStudentById(id);

}

public void insertStudent(Student student) {

studentMapper.insertStudent(student);

}

public void deleteStudentById(int id) {

studentMapper.deleteStudentById(id);

}

public void updateStudentById(Student student) {

studentMapper.updateStudentById(student);

}

       我这样建立目录和类,不是service和impl的区别吗???(求指点。。。)

四.收获

    1.Spring容器提供三中配置元数据。(只是了解,没有每种方式都做实验。我认为自己感觉是那么回事就         可以啦, 忘记了吗?我回答:我忘记啦!)

  1.           1.1 XML配置文件

  2.           1.2 基于注解的配置

  3.            1.3 基于java的配置@Configuration,@Bean

  4.      2.Spring与MyBatis整合时。(使用了XML配置文件和基于注解配置混合的方式)

  5.      3.感谢施星的指点。并让我去了解三层架构。(谢谢)

五.总结

 1.今天看了一篇不错的Spring+mybatis整合的美文。我按照博客上的配置自己的项目。

 2.今天下午又受虐啦,1点跑很远去面试,晚上将近7点回来。被虐的死死的。我很认真的做着笔试题,

  结果面试官看都没看试卷一眼,好吧,开始问吧。java+框架+linux(我回答只是了解),最后问我对   前端很熟吗?回答:了解。  如果给你时间学前端,你将会学什么?  回答:nodeJs和Jquery和A     AngularJs都是建立在Js的基础上的,我会把JS基础打好,然后其他的都不是问题。

  面试官:笑笑,你有别的问题吗?没有,就回去等消息吧。

 思考:企业到底想要什么人啊?全栈吗?什么都必须会吗?没看出来哥的潜力吗?

    (算法不行,做完第六个任务,抽一半时间搞算法。算法真的好烂)毕业,我找不到工作吗?拒掉自      己不想做的工作,有错吗???没错,加油... 我能行


返回列表 返回列表
评论

    分享到