`
zhangdaiscott
  • 浏览: 404494 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
8fb25857-16b4-3681-ab5e-e319f45c42a8
Jeecg快速开发平台
浏览量:0
文章分类
社区版块
存档分类

【jeecg-mybatis版本】 mybatis+spring mvc 完美整合方案 查询,保存,更新,删除自动生成

阅读更多

Jeecg-Mybatis版本代码生成器演示视频 

  http://pan.baidu.com/share/link?shareid=243717&uk=2668473880 
简要说明 
JEECG[J2EE Code Generation] 
代码生成:根据表生成对应的Bean,Service,Dao,Action,XML,JSP等,增删改查功能直接使用,实现了快速开发 
jeecg-mybatis-framework,采用SpringMVC+Mybatis等主流框架 
支持数据库: Mysql,Oracle10g 
前端:使用Jquery和Easyui技术.JS封装简洁,操作简单. 
权限:对菜单,按钮控制.根据登陆用户权限展示拥有的菜单和按钮. 
拦截:对所有无权限URL进行拦截,防止手动发送HTTP请求,确保系统全性. 


Java代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE mapper  
  3.   PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"  
  4.   "http://mybatis.org/dtd/mybatis-3-mapper.dtd">  
  5. <mapper namespace="scott.dao.demo.JeecgNoteDao" >   
  6. <!-- Result Map-->  
  7. <resultMap id="BaseResultMap" type="scott.entity.demo.JeecgNote" >  
  8.     <result column="id" property="id"/>  
  9.     <result column="title" property="title"/>  
  10.     <result column="content" property="content"/>  
  11.     <result column="crtuser" property="crtuser"/>  
  12.     <result column="crtuser_name" property="crtuser_name"/>  
  13.     <result column="create_dt" property="create_dt"/>  
  14.     <result column="deleted" property="deleted"/>  
  15. </resultMap>  
  16.          
  17. <!-- jeecg_note table all fields -->  
  18. <sql id="Base_Column_List" >  
  19.      id,title,content,crtuser,crtuser_name,create_dt,deleted  
  20. </sql>  
  21.      
  22.      
  23. <!-- 查询条件 -->  
  24. <sql id="Example_Where_Clause">  
  25. where 1=1  
  26. <trim  suffixOverrides="," >  
  27.     <if test="id != null and id != ''" >  
  28.         and id =  #{id}  
  29.     </if>  
  30.     <if test="title != null and title != ''" >  
  31.         and title =  #{title}  
  32.     </if>  
  33.     <if test="content != null and content != ''" >  
  34.         and content =  #{content}  
  35.     </if>  
  36.     <if test="crtuser != null and crtuser != ''" >  
  37.         and crtuser =  #{crtuser}  
  38.     </if>  
  39.     <if test="crtuser_name != null and crtuser_name != ''" >  
  40.         and crtuser_name =  #{crtuser_name}  
  41.     </if>  
  42.     <if test="create_dt != null and create_dt != ''" >  
  43.         and create_dt =  #{create_dt}  
  44.     </if>  
  45.     <if test="deleted != null and deleted != ''" >  
  46.         and deleted =  #{deleted}  
  47.     </if>  
  48. </trim>  
  49. </sql>  
  50.      
  51.   
  52. <!-- 插入记录 -->  
  53. <insert id="add" parameterType="Object" >  
  54. <selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">  
  55.     SELECT LAST_INSERT_ID()  
  56.   </selectKey>  
  57.   insert into jeecg_note(id,title,content,crtuser,crtuser_name,create_dt,deleted)  
  58.  values(#{id},#{title},#{content},#{crtuser},#{crtuser_name},#{create_dt},#{deleted})  
  59. </insert>  
  60.   
  61. <!-- 根据id,修改记录-->    
  62.  <update id="update" parameterType="Object" >  
  63.   update jeecg_note set title=#{title},content=#{content},crtuser=#{crtuser},crtuser_name=#{crtuser_name},create_dt=#{create_dt},deleted=#{deleted} where id=#{id}  
  64.  </update>  
  65.    
  66.  <!-- 修改记录,只修改只不为空的字段 -->  
  67. <update id="updateBySelective" parameterType="Object" >  
  68.     update jeecg_note set   
  69.     <trim  suffixOverrides="," >  
  70.     <if test="title != null  ">  
  71.         title=#{title},  
  72.     </if>  
  73.     <if test="content != null  ">  
  74.         content=#{content},  
  75.     </if>  
  76.     <if test="crtuser != null  ">  
  77.         crtuser=#{crtuser},  
  78.     </if>  
  79.     <if test="crtuser_name != null  ">  
  80.         crtuser_name=#{crtuser_name},  
  81.     </if>  
  82.     <if test="create_dt != null  ">  
  83.         create_dt=#{create_dt},  
  84.     </if>  
  85.     <if test="deleted != null  ">  
  86.         deleted=#{deleted},  
  87.     </if>  
  88.     </trim> where id=#{id}  
  89. </update>  
  90.   
  91. <!-- 删除记录 -->  
  92. <delete id="delete" parameterType="Object">  
  93.     delete   from jeecg_note where id = #{id}  
  94. </delete>  
  95.    
  96. <!-- 根据id查询 公告 -->  
  97. <select id="queryById"  resultMap="BaseResultMap" parameterType="Object">  
  98.     select <include refid="Base_Column_List" />   
  99.      from jeecg_note where id = #{id}  
  100. </select>  
  101.   
  102. <!-- 公告 列表总数-->  
  103. <select id="queryByCount" resultType="java.lang.Integer"  parameterType="Object">  
  104.     select count(1) from jeecg_note   
  105.     <include refid="Example_Where_Clause"/>  
  106. </select>  
  107.       
  108. <!-- 查询公告列表 -->  
  109. <select id="queryByList" resultMap="BaseResultMap"  parameterType="Object">  
  110.     select   
  111.     <include refid="Base_Column_List"/>  
  112.     from jeecg_note   
  113.     <include refid="Example_Where_Clause"/>  
  114.     <if test="pager.orderCondition != null and pager.orderCondition != ''" >  
  115.       ${pager.orderCondition}  
  116.     </if>  
  117.     <if test="pager.mysqlQueryCondition != null and pager.mysqlQueryCondition != ''" >  
  118.        ${pager.mysqlQueryCondition}  
  119.     </if>  
  120. </select>  
  121.       
  122. </mapper>     
1
2
分享到:
评论
5 楼 LinApex 2014-06-07  
已经失效了
4 楼 jueyue 2013-11-14  
顶一个
3 楼 hellostory 2013-11-14  
还有,有些写法个人觉得可以更简练些、命名也可以更优雅些(有些看起来好像是直接用mybatis官方代码生成器,╮(╯▽╰)╭ ),比如SQL Wheres
<sql id="sqlWheres">
	<trim prefix="WHERE" prefixOverrides="AND |OR ">
		<if test="id!=null">AND supplier_id=#{id}</if>
		<if test="code!=null and code!=''">AND supplier_code LIKE #{code}</if>
	</trim>
</sql>
2 楼 hellostory 2013-11-14  
为什么不直接使用Mybatis的useGeneratedKeyskeyProperty,而另起炉灶用“<selectKey>”?
1 楼 zhjxzhj 2013-11-14  
好东西  先顶一个

相关推荐

Global site tag (gtag.js) - Google Analytics