CMS--看点咨讯(三)

一 .编写项目流程:

1.确定需求-----确定要实现的功能
2.画E-R图,设计数据库
3.确定项目框架:定义接口,定义工具类

在这里插入图片描述

4.编写代码

4.1.级联删除步骤:
(1) .在bean包下新建一个文件夹ex包,作为某一个bean对象的扩展类.
在这里插入图片描述
(2) .在src/main/resource/mapper包新建一个文件夹ex,为自定义的扩展类添加对应的XXXEXMapper.xml文件,
在这里插入图片描述
(3) com.example.demo.mapper包中新建一个ex扩展包,在包中定义好所有自定义的扩展类所对应的接口文件
在这里插入图片描述
注:为了在重建mybatis逆向工程的时候可以保存好自定义的类,所以一般情况下都把自定义的类放到ex包下,防止其被覆盖.

CategoryExMapper.xml:
	     <?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.example.demo.mapper.ex.CategoryExMapper">
		  <resultMap id="BaseResultMap" type="com.example.demo.bean.ex.CategoryEx">
		    <id column="id" jdbcType="INTEGER" property="id" />
		    <result column="code" jdbcType="BIGINT" property="code" />
		    <result column="name" jdbcType="VARCHAR" property="name" />
		    <collection property="articles" ofType="com.example.demo.bean.Article"
					column="id" select="selectAllArticleByCategoryId" >
		    </collection>
		  </resultMap>
		  <select id="findAllCategoryEx" resultMap="BaseResultMap">
		    select id,name,code from cms_category 
		    </select>
		   <select id="findCategoryExById" resultMap="BaseResultMap" >
			select * from cms_category where id=#{id}
		   </select>
		    <select id="selectAllArticleByCategoryId" resultType="com.example.demo.bean.Article"> 
		    select * from cms_article where category_id=#{id}
		    </select>
		</mapper>
CategoryExMapper.java
		public interface CategoryExMapper {
			/**
			 * 实现查询所有栏目及其包含的文章信息
			 * */
			List<CategoryEx> findAllCategoryEx() throws CustomerException;
			/**
			 * 实现根据id查询对应的栏目及文章信息
			 * */
			CategoryEx findCategoryExById(Integer id) throws CustomerException;
			}
5.项目整合,测试阶段
6.部署上线,运维
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值