SSM框架的注解配置文件的优劣取舍

探索SSM理论的前提,应该是在对框架基础的运作方式有一定了解,以下是个人Android后台项目,用SSM框架快速搭建,以下是代码,主要 观察结构

代码结构:

model实体类

Idao抽象接口

Iservice抽象接口

daomapping数据库具体操作的配置文件

service服务类

controller控制器类

Article.java

package com.linuxidc.model; import java.util.Date; public class Article { private Integer id; private String title; private String author; private Date date; private Integer zan; private Integer pinglun; private Integer fenxiang; private String tag1; private String tag2; private String content; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title == null ? null : title.trim(); } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author == null ? null : author.trim(); } public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } public Integer getZan() { return zan; } public void setZan(Integer zan) { this.zan = zan; } public Integer getPinglun() { return pinglun; } public void setPinglun(Integer pinglun) { this.pinglun = pinglun; } public Integer getFenxiang() { return fenxiang; } public void setFenxiang(Integer fenxiang) { this.fenxiang = fenxiang; } public String getTag1() { return tag1; } public void setTag1(String tag1) { this.tag1 = tag1 == null ? null : tag1.trim(); } public String getTag2() { return tag2; } public void setTag2(String tag2) { this.tag2 = tag2 == null ? null : tag2.trim(); } public String getContent() { return content; } public void setContent(String content) { this.content = content == null ? null : content.trim(); } }

ArticleMapper.java

package com.linuxidc.dao; import java.util.List; import com.linuxidc.model.Article; public interface ArticleMapper { int deleteByPrimaryKey(Integer id); int insert(Article record); int insertSelective(Article record); Article selectByPrimaryKey(Integer id); int updateByPrimaryKeySelective(Article record); int updateByPrimaryKeyWithBLOBs(Article record); int updateByPrimaryKey(Article record); List<Article> getAll(); List<Article> getTitleList(String tag); }


ArticleMapping.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.linuxidc.dao.ArticleMapper" > <resultMap id="BaseResultMap" type="com.linuxidc.model.Article" > <id column="id" property="id" jdbcType="INTEGER" /> <result column="title" property="title" jdbcType="VARCHAR" /> <result column="author" property="author" jdbcType="VARCHAR" /> <result column="date" property="date" jdbcType="TIMESTAMP" /> <result column="zan" property="zan" jdbcType="INTEGER" /> <result column="pinglun" property="pinglun" jdbcType="INTEGER" /> <result column="fenxiang" property="fenxiang" jdbcType="INTEGER" /> <result column="tag1" property="tag1" jdbcType="VARCHAR" /> <result column="tag2" property="tag2" jdbcType="VARCHAR" /> </resultMap> <resultMap id="ResultMapWithBLOBs" type="com.linuxidc.model.Article" extends="BaseResultMap" > <result column="content" property="content" jdbcType="LONGVARCHAR" /> </resultMap> <sql id="Base_Column_List" > id, title, author, date, zan, pinglun, fenxiang, tag1, tag2 </sql> <sql id="Blob_Column_List" > content </sql> <select id="getAll" resultMap="BaseResultMap"> select * from article_t order by date desc </select> <select id="getTitleList" resultMap="BaseResultMap" parameterType="java.lang.String" > select * from article_t where tag1= #{tag,jdbcType=VARCHAR} or tag2= #{tag,jdbcType=VARCHAR} </select> <select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" > select <include refid="Base_Column_List" /> , <include refid="Blob_Column_List" /> from article_t where id = #{id,jdbcType=INTEGER} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > delete from article_t where id = #{id,jdbcType=INTEGER} </delete> <insert id="insert" parameterType="com.linuxidc.model.Article" > insert into article_t (id, title, author, date, zan, pinglun, fenxiang, tag1, tag2, content) values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{author,jdbcType=VARCHAR}, #{date,jdbcType=TIMESTAMP}, #{zan,jdbcType=INTEGER}, #{pinglun,jdbcType=INTEGER}, #{fenxiang,jdbcType=INTEGER}, #{tag1,jdbcType=VARCHAR}, #{tag2,jdbcType=VARCHAR}, #{content,jdbcType=LONGVARCHAR}) </insert> <insert id="insertSelective" parameterType="com.linuxidc.model.Article" > insert into article_t <trim prefix="(" suffix=")" suffixOverrides="," > <if test="id != null" > id, </if> <if test="title != null" > title, </if> <if test="author != null" > author, </if> <if test="date != null" > date, </if> <if test="zan != null" > zan, </if> <if test="pinglun != null" > pinglun, </if> <if test="fenxiang != null" > fenxiang, </if> <if test="tag1 != null" > tag1, </if> <if test="tag2 != null" > tag2, </if> <if test="content != null" > content, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides="," > <if test="id != null" > #{id,jdbcType=INTEGER}, </if> <if test="title != null" > #{title,jdbcType=VARCHAR}, </if> <if test="author != null" > #{author,jdbcType=VARCHAR}, </if> <if test="date != null" > #{date,jdbcType=TIMESTAMP}, </if> <if test="zan != null" > #{zan,jdbcType=INTEGER}, </if> <if test="pinglun != null" > #{pinglun,jdbcType=INTEGER}, </if> <if test="fenxiang != null" > #{fenxiang,jdbcType=INTEGER}, </if> <if test="tag1 != null" > #{tag1,jdbcType=VARCHAR}, </if> <if test="tag2 != null" > #{tag2,jdbcType=VARCHAR}, </if> <if test="content != null" > #{content,jdbcType=LONGVARCHAR}, </if> </trim> </insert> <update id="updateByPrimaryKeySelective" parameterType="com.linuxidc.model.Article" > update article_t <set > <if test="title != null" > title = #{title,jdbcType=VARCHAR}, </if> <if test="author != null" > author = #{author,jdbcType=VARCHAR}, </if> <if test="date != null" > date = #{date,jdbcType=TIMESTAMP}, </if> <if test="zan != null" > zan = #{zan,jdbcType=INTEGER}, </if> <if test="pinglun != null" > pinglun = #{pinglun,jdbcType=INTEGER}, </if> <if test="fenxiang != null" > fenxiang = #{fenxiang,jdbcType=INTEGER}, </if> <if test="tag1 != null" > tag1 = #{tag1,jdbcType=VARCHAR}, </if> <if test="tag2 != null" > tag2 = #{tag2,jdbcType=VARCHAR}, </if> <if test="content != null" > content = #{content,jdbcType=LONGVARCHAR}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.linuxidc.model.Article" > update article_t set title = #{title,jdbcType=VARCHAR}, author = #{author,jdbcType=VARCHAR}, date = #{date,jdbcType=TIMESTAMP}, zan = #{zan,jdbcType=INTEGER}, pinglun = #{pinglun,jdbcType=INTEGER}, fenxiang = #{fenxiang,jdbcType=INTEGER}, tag1 = #{tag1,jdbcType=VARCHAR}, tag2 = #{tag2,jdbcType=VARCHAR}, content = #{content,jdbcType=LONGVARCHAR} where id = #{id,jdbcType=INTEGER} </update> <update id="updateByPrimaryKey" parameterType="com.linuxidc.model.Article" > update article_t set title = #{title,jdbcType=VARCHAR}, author = #{author,jdbcType=VARCHAR}, date = #{date,jdbcType=TIMESTAMP}, zan = #{zan,jdbcType=INTEGER}, pinglun = #{pinglun,jdbcType=INTEGER}, fenxiang = #{fenxiang,jdbcType=INTEGER}, tag1 = #{tag1,jdbcType=VARCHAR}, tag2 = #{tag2,jdbcType=VARCHAR} where id = #{id,jdbcType=INTEGER} </update> </mapper>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/13278.html