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>
mybatise应用
猜你喜欢
转载自yuhuiblog6338999322098842.iteye.com/blog/2243024
今日推荐
周排行