发表于: 2021-01-26 23:46:52
1 1241
今天完成的事情:
写前后台SQL语句,重新编写dao,service,serviceImpl
明天计划的事情:
编写controller
遇到的问题:
暂无
收获:
SQL:
Banner:
<resultMap id="BaseResultMap" type="com.kbk.model.Banner">
<constructor>
<idArg column="id" javaType="java.lang.Long" jdbcType="BIGINT" />
<arg column="cover" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="url" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="status" javaType="byte[]" jdbcType="BIT" />
<arg column="created_time" javaType="java.lang.Long" jdbcType="BIGINT" />
<arg column="update_time" javaType="java.lang.Long" jdbcType="BIGINT" />
<arg column="update_by" javaType="java.lang.String" jdbcType="VARCHAR" />
</constructor>
</resultMap>
<sql id="Base_Column_List">
id, cover, url, status, created_time, update_time, update_by
</sql>
<!-- 前台,查找banner列表 -->
<select id="selectBannerList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from banner
</select>
Message:
<?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.kbk.dao.MessageMapper">
<resultMap id="BaseResultMap" type="com.kbk.model.Message">
<constructor>
<idArg column="id" javaType="java.lang.Long" jdbcType="BIGINT" />
<arg column="work_id" javaType="java.lang.Long" jdbcType="BIGINT" />
<arg column="tourist_name" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="status" javaType="byte[]" jdbcType="BIT" />
<arg column="role_id" javaType="java.lang.Long" jdbcType="BIGINT" />
<arg column="created_time" javaType="java.lang.Long" jdbcType="BIGINT" />
<arg column="updated_time" javaType="java.lang.Long" jdbcType="BIGINT" />
<arg column="contents" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="reply_id" javaType="java.lang.Long" jdbcType="BIGINT" />
</constructor>
</resultMap>
<!-- 前台,游客留言的方法 -->
<insert id="insertMessage" parameterType="com.kbk.model.Message" useGeneratedKeys="true">
insert into message(contents,tourist_name,created_time,work_id) values (#{contents},#{touristName},#{createTime},#{workId})
</insert>
TitleMapper:
<!-- 前台,查询全部一级导航 -->
<select id="selectFirst" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
t.name
from title
where id = #{id,jdbcType=BIGINT}
</select>
<!-- 查询全部一级导航 -->
<select id="selectSecond" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
t.name
from title
where parent_id = #{parent_id,jdbcType=BIGINT}
</select>
WorkMapper:
<!-- 前台 -->
<!--多字段模糊查询-->
<select id="selectByKeyword" parameterType="java.util.Map" resultMap="BaseResultMap">
SELECT
w.id,w.name,w.introduction,w.thumbnail
FROM
work w
<where>
<if test="keywords != null and keywords != ''">
AND CONCAT(IFNULL(name,''),IFNULL(introduction,'')) LIKE CONCAT('%', #{thumbnail},'%')
</if>
</where>
</select>
<!--单表查询作品详情-->
<select id="selectWorksById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from work
where id = #{id,jdbcType=BIGINT}
</select>
接口:
package com.kbk.dao;
import com.kbk.model.Banner;
import java.util.List;
public interface BannerMapper {
/**
* 查找banner列表
* @param
* @return Banner
*/
List<Banner> selectBannerList();
}
package com.kbk.dao;
import com.kbk.model.Title;
import java.util.List;
public interface TitleMapper {
/**
* 查找一级作品分类列表
* @param id
* @return TitleMapper
*/
List<TitleMapper> selectFirst(int id);
/**
* 根据二级作品分类id查找改分类下的所有作品
* @param parent_id
* @return TitleMapper
*/
TitleMapper selectSecond(int parent_id);
}
package com.kbk.dao;
import com.kbk.model.Work;
import java.util.List;
public interface WorkMapper {
/**
*多字段模糊查询
* @Param [keyword]
* @return java.util.List<com.kbk.model.Works>
**/
List<Work> selectByKeyword(String keyword);
/**
* 单表查询作品表(无留言)
* @param id
* @return
*/
Work selectWorksById(int id);
}
实现类:
package com.kbk.service.Impl;
import com.kbk.dao.BannerMapper;
import com.kbk.model.Banner;
import com.kbk.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
public class BannerServiceImpl implements BannerService {
@Autowired
BannerMapper bannerMapper;
@Override
public List<Banner> selectBannerList() {
return bannerMapper.selectBannerList();
}
}
package com.kbk.service.Impl;
import com.kbk.dao.MessageMapper;
import com.kbk.model.Message;
import com.kbk.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
public class MessageServiceImpl implements MessageService {
@Autowired
MessageMapper messageMapper;
@Override
public int insertMessage(Message message) {
return messageMapper.insertMessage(message);
}
}
下面类似,就不添加了
评论