Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
推送20天前修改的代码(忘记推送了)
主要是删除不必要的文件。
  • Loading branch information
zhanglei-workspace committed Oct 9, 2016
1 parent 80ab11f commit a5fc0e1
Show file tree
Hide file tree
Showing 42 changed files with 434 additions and 1,275 deletions.
17 changes: 0 additions & 17 deletions 2#Java入门项目/lyons.eaby.new/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
log4j.rootLogger=debug,Console

log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
log4j.logger.org.apache=debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>
<!--
<settings>
<setting name="useGeneratedKeys" value="false"/>
<setting name="useColumnLabel" value="true"/>
</settings>
<typeAliases>
<typeAlias alias="UserAlias" type="org.apache.ibatis.submitted.complex_property.User"/>
</typeAliases>
-->

<!-- mybatis默认自动关闭数据库连接 关于mybatis详细资料:http://www.mybatis.org/mybatis-3/zh/configuration.html -->

<environments default="development">
<environment id="development">
<transactionManager type="JDBC">
<property name="" value=""/>
</transactionManager>
<!-- 连接本地oracle数据库信息 -->
<dataSource type="UNPOOLED">
<property name="driver" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
<property name="username" value="scott"/>
<property name="password" value="tiger"/>
</dataSource>
</environment>
</environments>

<!-- 整合资源,将其他的配置文件添加进 ,路径也是从src写起-->
<mappers>
<mapper resource="resources/sql/Goods.xml"/>
<mapper resource="resources/sql/Order.xml"/>
<mapper resource="resources/sql/Classify.xml"/>
<mapper resource="resources/sql/User.xml"/>
</mappers>

</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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="lyons.dao.GoodsClassifyDao">

<resultMap type="lyons.goods.entity.GoodsClassify" id="ClassifyResult">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="gname" jdbcType="VARCHAR" property="gname"/>

<!-- 作为子表时使用该标签(多对一)。与collection语法一致
<association property="#" resultMap=""/>
-->
</resultMap>

<!-- <sql id="columns"></sql> -->
</mapper>
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<?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="lyons.dao.GoodsDao"><!-- 面向接口编程。与此类关联,作为空间名 -->

<!-- 数据库中Goods表与javaBean的变量名对应关系 -->
<!-- type:对应java对应表的实体类名 id:别名(可以与select等的id重名)-->
<resultMap type="lyons.goods.entity.Goods" id="GoodsResult">

<!-- (id:数据库表主键 result:数据库表普通的列) property:javaBean中字段对应的变量名字-->
<!-- column:与查询的列名相同并非数据库里面的列名。比如select id a from 表名 查询的列名用了别名a那么就得对应的修改column="a"-->
<id column="commodity_number" jdbcType="INTEGER" property="commodity_number"/>
<result column="commodity_name" jdbcType="VARCHAR" property="commodity_name"/>
<result column="commodity_made" jdbcType="VARCHAR" property="commodity_made"/>
<result column="commodity_price" jdbcType="DOUBLE" property="commodity_price"/>
<result column="commodity_balance" jdbcType="INTEGER" property="commodity_balance"/>
<result column="commodity_pic" jdbcType="VARCHAR" property="commodity_pic"/>
<result column="commodity_id" jdbcType="INTEGER" property="commodity_id"/>

<!-- 作为主表时使用该标签。 collection:代表对应一个集合 resultMap:引用Classify.XML的映射关系 配置这个的原因是引用子表查询了 -->
<collection property="goodsClassifyList" resultMap="lyons.dao.GoodsClassifyDao.ClassifyResult" /><!-- 一对多 空间名.id -->

</resultMap>



<!-- 定义常量 。写出查询的列代替*效率高-->
<sql id="columns">SELECT commodity_number,commodity_name,commodity_made,commodity_price,commodity_balance,commodity_pic,commodity_id
FROM commodity
</sql>

<!-- 解释: id:为该sql语句起一个名字(用于SqlFaction调用该sql语句)resultMap:对应上述resultMap的id -->
<!-- select查出来的信息放到<resultMap>对应的property变量名中 -->
<select id="goodsAllList" resultMap="GoodsResult">
<include refid="columns"/> <!-- 引用<sql>中定义的常量 -->
</select>
<!-- "src/resources/MybatisConfiguration.xml" parameterType:根据条件查询,传递来的参数的类型 -->
<select id="queryGoodsByKey" parameterType="String" resultMap="GoodsResult">
<include refid="columns"/>
WHERE commodity_name LIKE '%'|| #{_parameter} ||'%'
</select>


<!-- (关键字||分类)or(关键字&&分类) 查询 --> <!-- 多表联立不用别名是为了方便,详情见上面配置column加的注释 -->
<!-- 如果引用了外表,并且与主表的查询的列名相同,那么就不得不使用别名加以区分。目的:防止查询的列在column中多对一 -->
<select id="queryGoodsByKeyClassify" parameterType="lyons.goods.entity.Goods" resultMap="GoodsResult">
<include refid="columns"/>
INNER JOIN classify
ON commodity.commodity_id = classify.gid

<if test="commodity_name != null and !(&quot;&quot;.equals(commodity_name.trim()))">
AND commodity.commodity_name LIKE '%'|| #{commodity_name} ||'%'
</if>
<if test="commodity_id > 0" >
AND commodity.commodity_id = #{commodity_id}
</if>
</select>

<!-- 批量更新商品数量 -->
<update id="updateGoods" parameterType="java.util.List">

begin
<foreach collection="list" item="item" index="index" separator=";" >
update commodity
<set>
<if test="item.commodity_balance!=null and item.commodity_balance!=''">
commodity_balance = ${item.commodity_balance},
</if>
</set>
where commodity_number = ${item.commodity_number}
</foreach>
;end;

</update>


<!--
<delete id="deleteOneGoodsById" parameterType="int">
DELECT FROM commodity
where commodity_number = #{_parameter}
</delete>
<update id="#" parameterType="lyons.goods.entity.Goods">
UPDATE commodity
<set> 与where标签效果一样
<if test="#">
</if>
<if test="#" >
</if>
</set>
</update>
-->

<!-- 使用自增主键的方法 useGeneratedKeys设置为true keyProperty:存储到的数据库中字段对应的java实体类的变量名-->
<!-- <insert id="#" parameterType="lyons.goods.entity.Goods" useGeneratedKeys="true" keyProperty="commodity_number">
</insert>
-->

<!-- 知识扩充 -->

<!-- 多功能的拼接条件,会了语法,自己去创造神奇.本项目中暂不使用大招 -->
<!-- <trim prefix="where" prefixOverrides="and|or" suffixOverrides="">
</trim>
-->

<!-- 实现switch case -->
<!--
<choose>
<when test=""></when>
<when test=""></when>
<otherwise></otherwise>
</choose>
-->

<!--
客官,<select><update>等等查询语句中的 resultMap 可以用resultType代替,你造吗?
这样的话就不用在xml中配置resultMap了,它会根据resultType="实体类名"中的变量名自动匹配
但是,但是,,,技能受限,不能用别名了
-->

<!--
TypeHandler="" 可以转换数据类型,达到数据库中的字段与java实体类中字段的转换后对应
-->

<!--
xxxMap xxxType
这两个家门狗族是不是总是傻傻分不清?请看虐狗大招:
Map系 :与配置映射关系有关
Type系:与java类型有关。
-->

<!--
${} 不是预编译的,而是直接赋值传进来的值
区别于预编译 #{}
-->



<!--
<select id="version" parameterType="long" resultType="int">
SELECT version FROM user WHERE id = #{id,jdbcType=INTEGER}
</select>
<insert id="insert" parameterType="UserAlias" useGeneratedKeys="false">
INSERT INTO user
( id,
username,
password,
administrator
)
VALUES
( #{id},
#{username,jdbcType=VARCHAR},
#{password.encrypted:VARCHAR},
#{administrator,jdbcType=BOOLEAN}
)
</insert>
<update id="update" parameterType="UserAlias">
UPDATE user SET
username = #{username,jdbcType=VARCHAR},
password = #{password.encrypted,jdbcType=VARCHAR},
administrator = #{administrator,jdbcType=BOOLEAN}
WHERE
id = #{id,jdbcType=INTEGER}
</update>
-->
<!-- Unique constraint check
<select id="isUniqueUsername" parameterType="map" resultType="boolean">
SELECT (count(*) = 0)
FROM user
WHERE ((#{userId,jdbcType=BIGINT} IS NOT NULL AND id != #{userId,jdbcType=BIGINT}) OR #{userId,jdbcType=BIGINT} IS
NULL) --><!-- other than me --><!--
AND (username = #{username,jdbcType=VARCHAR})
</select>
-->
</mapper>
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?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="lyons.dao.OrderDao">

<resultMap type="lyons.order.entity.Order" id="OrderResult">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="username" jdbcType="VARCHAR" property="userName"/>
<result column="orderDate" jdbcType="DATE" property="orderDate"/>
<result column="commodity_name" jdbcType="VARCHAR" property="commodity_name"/>
<result column="commodity_price" jdbcType="DOUBLE" property="commodity_price"/>
<result column="sum" jdbcType="INTEGER" property="sum"/>
</resultMap>

<sql id="columnsSelect">SELECT id,username,orderDate,orderDate,commodity_name,commodity_price,sum FROM orderform</sql>

<!-- 查询订单系 -->

<!-- 搞个小分页 -->
<select id="queryOrderAllList" parameterType="lyons.order.entity.Order" resultMap="OrderResult">
<include refid="columnsSelect"></include>
<!-- select * from
(
select commodity.*,rownum num
from commodity
where rownum &lt;= #{_parameter}
)
where num &gt;= #{_paramete}
-->
</select>

<!-- 自己配置该resultMap的原因是 id="OrderResult" 无对应的返回类型 没配置成功的原因可能是 resultMap代替parameterMap
<resultMap type="java.util.Map" id="queryOrderSum">
<result column="commodity_name" jdbcType="VARCHAR" property="commodity_name"/>
<result column="SUM(sum)" jdbcType="VARCHAR" property="SUM(sum)"/>
</resultMap>
-->
<select id="queryOrderListByuserName" parameterType="String" resultMap="OrderResult">
<include refid="columnsSelect"/>
<where>
<!-- 传来String类型以及基本数据类型时的参数获取方式: #{_parameter} -->
<if test="_parameter != null and !(&quot;&quot;.equals(_parameter.trim()))">
username = #{_parameter}
</if>
</where>
<!--
GROUP BY ${commodity_name} 查询出来的相同数据没有相加
HAVING SUM(sum)>0
-->
</select>


<!-- parameterType:自定义的对象类型(注意文件夹间用点间隔) test=: 与实体类中的变量名对应-->
<!-- <where> 自动拼接where 1=1、and 等等 -->
<select id="queryOrderByKeyName" parameterType="lyons.order.entity.Order" resultMap="OrderResult">
<include refid="columnsSelect"/>
<where>
<if test="keyWord != null and !(&quot;&quot;.equals(keyWord.trim()))"><!-- 注意and代表&& 双引号的表示 -->
commodity_name LIKE '%'|| #{keyWord} ||'%'
</if>
<if test="userName != null and !(&quot;&quot;.equals(userName.trim()))">
username = #{userName} <!-- #{变量名} 取值 -->
</if>
</where>
</select>


<!-- 删除订单系 -->
<delete id="deleteOrderOneById" parameterType="int" >

DELETE FROM orderform WHERE id = #{_parameter}

</delete>

<delete id="deleteOrderBatch" parameterType="java.util.List">

DELETE FROM orderform WHERE id
IN(
<!-- collection:指向集合 item:迭代出来的项 separator:自定义分割符-->
<foreach collection="list" index="" item="item" separator=",">
#{item}
</foreach>
)

</delete>



<!-- 插入订单系 -->
<!-- 批量插入数据 sql不熟悉的可以参考博客:http://www.voidcn.com/blog/mingtianhaiyouwo/article/p-5959712.html -->
<insert id="insertOrderBatch" parameterType="java.util.List"> <!-- 传来的是 List<order> ,所以是集合collection -->

INSERT INTO orderForm(username,commodity_name,commodity_price,sum)
<foreach collection="collection" item="item" separator="UNION ALL"> <!-- 注意集合:collection="collection" -->
(
SELECT
'${item.userName}','${item.commodity_name}',${item.commodity_price},${item.sum}
from dual
)
</foreach>
</insert>

</mapper>
Loading

0 comments on commit a5fc0e1

Please sign in to comment.