今天完成的事情:
了解生成的SQL语句,搞清楚项目分层依赖的问题
明天计划的事情:
解决依赖分开的问题,service接口,实现类。测试
遇到的问题:
在父模块中,我没有添加MYSQL依赖,我直接在子模块-core中pom.xml中添加的。我认为这个其他模块不会用到这个,都是通过core子模块来连接数据库的,且service模块添加了core模块的依赖
例:
收获:
了解生成的SQL语句,各个作用,增加标签:
<?xml version="1.0" encoding="UTF-8"?>
<mapper namespace="com.kbk.dao.UserMapper">
<resultMap id="BaseResultMap" type="com.kbk.model.User">
<constructor>
<idArg column="id" javaType="java.lang.Long" jdbcType="BIGINT" />
<arg column="user_name" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="passwrod" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="role" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="created_time" javaType="java.lang.Long" jdbcType="BIGINT" />
<arg column="updated_time" javaType="java.lang.Long" jdbcType="BIGINT" />
<arg column="created_by" javaType="java.lang.String" jdbcType="VARCHAR" />
</constructor>
</resultMap>
<!-- 复用的SQL语句 -->
<sql id="Base_Column_List">
id, user_name, passwrod, role, created_time, updated_time, created_by
</sql>
<!-- 根据主键查找 -->
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from user
where id = #{id,jdbcType=BIGINT}
</select>
<!-- 根据主键删除 -->
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from user
where id = #{id,jdbcType=BIGINT}
</delete>
<!-- 根据主键增加 -->
<insert id="insert" parameterType="com.kbk.model.User">
insert into user (id, user_name, passwrod,
role, created_time, updated_time,
created_by)
values (#{id,jdbcType=BIGINT}, #{userName,jdbcType=VARCHAR}, #{passwrod,jdbcType=VARCHAR},
#{role,jdbcType=VARCHAR}, #{createdTime,jdbcType=BIGINT}, #{updatedTime,jdbcType=BIGINT},
#{createdBy,jdbcType=VARCHAR})
</insert>
<!-- 插入选择性,当条件成立,if中的SQL语句会和外面SQL语句拼接到一起
trim标签的作用:灵活配置添加前缀、后缀,删除前缀、后缀
语法:使用<trim>代替<set>
<trim prefix="添加前缀" suffix="添加后缀" prefixOverride="删除前缀" suffixOverride="删除后缀":-->
<insert id="insertSelective" parameterType="com.kbk.model.User">
insert into user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="userName != null">
user_name,
</if>
<if test="passwrod != null">
passwrod,
</if>
<if test="role != null">
role,
</if>
<if test="createdTime != null">
created_time,
</if>
<if test="updatedTime != null">
updated_time,
</if>
<if test="createdBy != null">
created_by,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="userName != null">
#{userName,jdbcType=VARCHAR},
</if>
<if test="passwrod != null">
#{passwrod,jdbcType=VARCHAR},
</if>
<if test="role != null">
#{role,jdbcType=VARCHAR},
</if>
<if test="createdTime != null">
#{createdTime,jdbcType=BIGINT},
</if>
<if test="updatedTime != null">
#{updatedTime,jdbcType=BIGINT},
</if>
<if test="createdBy != null">
#{createdBy,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<!-- 通过主键选择更新
set标签的作用是:去除逗号,-->
<update id="updateByPrimaryKeySelective" parameterType="com.kbk.model.User">
update user
<set>
<if test="userName != null">
user_name = #{userName,jdbcType=VARCHAR},
</if>
<if test="passwrod != null">
passwrod = #{passwrod,jdbcType=VARCHAR},
</if>
<if test="role != null">
role = #{role,jdbcType=VARCHAR},
</if>
<if test="createdTime != null">
created_time = #{createdTime,jdbcType=BIGINT},
</if>
<if test="updatedTime != null">
updated_time = #{updatedTime,jdbcType=BIGINT},
</if>
<if test="createdBy != null">
created_by = #{createdBy,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<!-- 通过主键更新所有数据 -->
<update id="updateByPrimaryKey" parameterType="com.kbk.model.User">
update user
set user_name = #{userName,jdbcType=VARCHAR},
passwrod = #{passwrod,jdbcType=VARCHAR},
role = #{role,jdbcType=VARCHAR},
created_time = #{createdTime,jdbcType=BIGINT},
updated_time = #{updatedTime,jdbcType=BIGINT},
created_by = #{createdBy,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
=====
发现自己使用的是spring-boot,了解spring-boot,用一辆汽车来举例的话:
如果我们想组装一辆汽车,我们需要发动机、传动、轮胎、底盘、外壳、座椅、内饰等各种部件,然后把它们装配起来。Spring就相当于提供了一系列这样的部件,但是要装好汽车上路,还需要我们自己动手。而Spring Boot则相当于已经帮我们预装好了一辆可以上路的汽车,如果有特殊的要求,例如把发动机从普通款换成涡轮增压款,可以通过修改配置或编写少量代码完成。
使用spring-boot,它会自动导入很多依赖,让你自己不用去导入过多的依赖,这些依赖都是采用默认配置,如果需要修改版本,在pom.xml文件中自己添加就好了
===============
Spring Boot和Spring的关系就是整车和零部件的关系,它们不是取代关系,试图跳过Spring直接学习Spring Boot是不可能的。
我spring还没学好,还是先使用spring,之后再来使用spring-boot
===
注意,是根据这个来导入的
—- app-parent
|– pom.xml (pom)
|
|– app-dao
| |– pom.xml (jar)
|
|– app-service
| |– pom.xml (jar)
|
|– app-web
|– pom.xml (war)
注意他们的packaging类型,有jar,war和pom三种
dao–作为jar导入–>service–作为jar导入–>web–build成war项目–>运行
========
在父模块添加pom.xml依赖:
<?xml version="1.0" encoding="UTF-8"?>
<modelVersion>4.0.0</modelVersion>
<modules>
<module>kbk_controller</module>
<module>kbk_service</module>
<module>kbk_core</module>
</modules>
<groupId>com.kbk</groupId>
<artifactId>kbk_parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>kbk_parent</name>
<properties>
<!--项目内模块-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<!--通用部分-日志文件-->
<junit.version>4.12</junit.version>
<slf4j-api.version>1.7.5</slf4j-api.version>
<slf4j-log4j12.version>1.7.12</slf4j-log4j12.version>
<log4j.version>1.2.17</log4j.version>
<commons-logging.version>1.2</commons-logging.version>
<!--Spring-->
<spring.version>4.3.0.RELEASE</spring.version>
<aspectjweaver.version>1.9.5</aspectjweaver.version>
<cglib.version>2.2</cglib.version>
<springframework.version>5.2.6.RELEASE</springframework.version>
<!--mybatis-->
<mybatis.version>3.3.0</mybatis.version>
<mybatis-spring.version>1.2.3</mybatis-spring.version>
<asm.version>3.3.1</asm.version>
<c3p0.version>0.9.1.2</c3p0.version>
<!--spring mvc-->
<jstl.version>1.2</jstl.version>
<servlet-api.version>3.0.1</servlet-api.version>
<jsp-api.version>2.2</jsp-api.version>
<standard.version>1.1.2</standard.version>
<!--json包-->
<json-lib.version>2.4</json-lib.version>
<jsontaglib.version>0</jsontaglib.version>
<!--Java基本对象方法的工具类包-->
<commons-lang3.version>3.9</commons-lang3.version>
</properties>
<dependencyManagement>
<dependencies>
<!--单元测试-->
<!--JUit-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!--test-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${springframework.version}</version>
</dependency>
<!--Spring-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>${cglib.version}</version>
</dependency>
<!-- web层 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectjweaver.version}</version>
</dependency>
<!--DAO层 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${springframework.version}</version>
</dependency>
<!-- DAO-MyBatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis-spring.version}</version>
</dependency>
<!--mybatis 其他包-->
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>${asm.version}</version>
</dependency>
<!--c3p0数据包-->
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>${c3p0.version}</version>
</dependency>
<!--日志文件-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-api.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-log4j12.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!--公共记录包-->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${commons-logging.version}</version>
</dependency>
<!--servlet web(spring-mvc)-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>${standard.version}</version>
</dependency>
<!--json包-->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>${json-lib.version}</version>
<classifier>jdk15</classifier>
</dependency>
<!--备注:这个json包是下载了本地电脑上,打包到服务器上时,需要更换版本-->
<dependency>
<groupId>com-json-jsontaglib</groupId>
<artifactId>jsontaglib</artifactId>
<version>${jsontaglib.version}</version>
</dependency>
<!-- 是处理Java基本对象方法的工具类包,该类包提供对字符、数组等基本对象的操作,弥补了java.lang api基本处理方法上的不足。 -->
<dependency>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
子模块(kbk_service层)依赖:
controller和service 在加上dao层的各个依赖分开吗?
可这样配置(resources)怎么分?
===
评论