mybatise应用
来源:互联网 发布:好看的香港电影 知乎 编辑:程序博客网 时间:2024/06/07 02:31
mybatise实体加@table标签开启更新后可以通过改变这个类改变数据库,不加在sql操作回写结果也一样,可以理解即是一个bo
result中的只要sql查出的有的即可,实体中的只要,返回中的有的即可
有参数传入操作不声明也可
操作名字和dao中方法名字相同,
mybatis中实体中的set,get返回前台的时候,对应依据map.xml文件中的
@Column(name = "SENDER_FULLNAME")
private String senderFullname;
@Column(name = "RECEIVER_FULLNAME")
private String receiverFullname;这两个的cloumn标签写错了用的时候一句标签对应map.xml文件中的属性
xml文件操作语句参数等类型标签注意用对,返回基本类型resulttype,返回实体resultmap,入参类型只要和dao中一致自动转。
@Table(name = "ORG_ORGANIZATION")
public class OrganizationDto extends LongIdObject {
//参数类型有就写,没有就不写 可以传map参数
<select id="querySupplierList" resultMap="DTOBaseResultMap" parameterType="hashmap">
SELECT a.*,c.TITLE AS PROVINCE,d.TITLE AS CITY ,e.TITLE AS AREA
FROM ORG_ORGANIZATION a
LEFT JOIN SYS_DICT_DATA c ON a.PROVINCE_ID=c.ID
LEFT JOIN SYS_DICT_DATA d ON a.CITY_ID=d.ID
LEFT JOIN SYS_DICT_DATA e ON a.AREA_ID=e.ID
WHERE a.ORG_TYPE='0'
<if test="orgName!=null and orgName!=''">
AND a.ORG_NAME like concat('%',#{orgName},'%')
</if>
<if test="linktel!=null and linktel!=''">
AND a.LINKTEL like concat('%',#{linktel},'%')
</if>
</select>
<update id="updateByPrimaryKeySelective" parameterType="com.wondersgroup.employeeBenefits.core.bases.dto.Add" >
update tadd
<set >
<if test="tname != null" >
tname = #{tname,jdbcType=VARCHAR},
</if>
<if test="tpwd != null" >
tpwd = #{tpwd,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.wondersgroup.employeeBenefits.core.bases.dto.Add" >
update tadd
set tname = #{tname,jdbcType=VARCHAR},
tpwd = #{tpwd,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
================================
<!-- myBatis文件配置含义 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
<property name="mapperLocations" >
<array>
<value> classpath:com/wondersgroup/employeeBenefits/core/bases/mapping/*.xml</value>//配合使用dao的配置
<value> classpath:com/wondersgroup/employeeBenefits/core/author/mapping/*.xml</value>
</array>
</property>
<property name="mapperLocations" >
<array>
<value> classpath:com/wondersgroup/employeeBenefits/core/**/*.xml</value>等效
</array>
</property>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>
dialect=mysql
reasonable=true
</value>
</property>
</bean>
<bean class="com.github.abel533.mapperhelper.MapperInterceptor">
<property name="properties">
<value>
mappers=com.github.abel533.mapper.Mapper
IDENTITY=mysql
notEmpty=true
</value>
</property>
</bean>
</array>
</property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com/wondersgroup/employeeBenefits/core/*/dao" />//配合使用xml的配置
<!-- com/wondersgroup/benefit/cloud/model/core/mapper/dao -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
result中的只要sql查出的有的即可,实体中的只要,返回中的有的即可
有参数传入操作不声明也可
操作名字和dao中方法名字相同,
mybatis中实体中的set,get返回前台的时候,对应依据map.xml文件中的
@Column(name = "SENDER_FULLNAME")
private String senderFullname;
@Column(name = "RECEIVER_FULLNAME")
private String receiverFullname;这两个的cloumn标签写错了用的时候一句标签对应map.xml文件中的属性
xml文件操作语句参数等类型标签注意用对,返回基本类型resulttype,返回实体resultmap,入参类型只要和dao中一致自动转。
@Table(name = "ORG_ORGANIZATION")
public class OrganizationDto extends LongIdObject {
//参数类型有就写,没有就不写 可以传map参数
<select id="querySupplierList" resultMap="DTOBaseResultMap" parameterType="hashmap">
SELECT a.*,c.TITLE AS PROVINCE,d.TITLE AS CITY ,e.TITLE AS AREA
FROM ORG_ORGANIZATION a
LEFT JOIN SYS_DICT_DATA c ON a.PROVINCE_ID=c.ID
LEFT JOIN SYS_DICT_DATA d ON a.CITY_ID=d.ID
LEFT JOIN SYS_DICT_DATA e ON a.AREA_ID=e.ID
WHERE a.ORG_TYPE='0'
<if test="orgName!=null and orgName!=''">
AND a.ORG_NAME like concat('%',#{orgName},'%')
</if>
<if test="linktel!=null and linktel!=''">
AND a.LINKTEL like concat('%',#{linktel},'%')
</if>
</select>
<update id="updateByPrimaryKeySelective" parameterType="com.wondersgroup.employeeBenefits.core.bases.dto.Add" >
update tadd
<set >
<if test="tname != null" >
tname = #{tname,jdbcType=VARCHAR},
</if>
<if test="tpwd != null" >
tpwd = #{tpwd,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.wondersgroup.employeeBenefits.core.bases.dto.Add" >
update tadd
set tname = #{tname,jdbcType=VARCHAR},
tpwd = #{tpwd,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
================================
<!-- myBatis文件配置含义 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
<property name="mapperLocations" >
<array>
<value> classpath:com/wondersgroup/employeeBenefits/core/bases/mapping/*.xml</value>//配合使用dao的配置
<value> classpath:com/wondersgroup/employeeBenefits/core/author/mapping/*.xml</value>
</array>
</property>
<property name="mapperLocations" >
<array>
<value> classpath:com/wondersgroup/employeeBenefits/core/**/*.xml</value>等效
</array>
</property>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>
dialect=mysql
reasonable=true
</value>
</property>
</bean>
<bean class="com.github.abel533.mapperhelper.MapperInterceptor">
<property name="properties">
<value>
mappers=com.github.abel533.mapper.Mapper
IDENTITY=mysql
notEmpty=true
</value>
</property>
</bean>
</array>
</property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com/wondersgroup/employeeBenefits/core/*/dao" />//配合使用xml的配置
<!-- com/wondersgroup/benefit/cloud/model/core/mapper/dao -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
0 0
- mybatise 应用
- mybatise应用
- Mybatise
- spring+mybatise
- Mybatise插件
- mybatise框架相关
- SpringMVC+MyBatise开发流程
- mybatise学习笔记
- mybatise配置文件通配
- mybatise模糊查询拼接语句
- spring和mybatise的整合
- Mybatise示例的employeeMapping.xml
- springmvc +mybatise 框架的搭建步骤
- oracle数据库,mybatise批量插入数据
- mybatise大于等于,小于等于比较运算
- Mybatise与数据库连接的xml配置文件
- mybatise自定义插件或者叫mybatise拦截器,动态修改sql语句
- SpringMVC+Spring3.0+Mybatise+Extjs4.0+Json 包冲突
- 【原创】pythonchalleng——第8题
- mybatise配置文件通配
- 【原创】pythonchalleng——第9题
- 用Maven插件生成Mybatis代码
- 命名sql的常见用法
- mybatise应用
- 【原创】pythonchalleng——第10题
- 【原创】pythonchalleng——第11题
- springmvc值的传递(从后台到前台)
- SCOI 2017 酱油记
- LeetCode 540. Single Element in a Sorted Array
- USACO-2.1.1- The Castle
- 【原创】pythonchalleng——第12题
- springmvc值的传递(从前台到后台)