数据库中有下划线的字段在实体中应采用驼峰命名法,如p_name对应pname,实例如下:
1.xml文件中sql语句配置(geteway.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.soecode.hbdw.gateway.dao.gatewaydao"> <cache></cache> <!-- 目的:为dao接口方法提供sql语句配置 --> <select id="querybyid" resulttype="gateway" parametertype="int"> <!-- 具体的sql --> select * from p_gateway where gateway_id = #{gatewayid} </select> <select id="querybyname" resulttype="gateway" parametertype="java.lang.string"> <!-- 具体的sql --> select * from p_gateway where gateway_name=#{gatewayname} </select> <delete id="delgateway" parametertype="java.lang.integer"> delete from p_gateway where gateway_id = #{gatewayid} </delete> <update id="updategateway" > <!-- ignore 主键冲突,报错 --> update p_gateway set gateway_name= #{gatewayname}, gateway_num= #{gatewaynum}, gateway_nature= #{gatewaynature}, gateway_supply= #{gatewaysupply}, remark= #{remark} where gateway_id = #{gatewayid} </update> </mapper>
2.entity实体配置(gateway.java文件)
package com.soecode.hbdw.gateway.entity; import java.io.serializable; import java.util.date; public class gateway implements serializable{ /** * */ private static final long serialversionuid = 1l; private int gatewayid; private string gatewayname; private string gatewaynum; private string gatewaynature; private string gatewaysupply; private string remark; public int getgatewayid() { return gatewayid; } public void setgatewayid(int gatewayid) { this.gatewayid = gatewayid; } public string getgatewayname() { return gatewayname; } public void setgatewayname(string gatewayname) { this.gatewayname = gatewayname; } public string getgatewaynum() { return gatewaynum; } public void setgatewaynum(string gatewaynum) { this.gatewaynum = gatewaynum; } public string getgatewaynature() { return gatewaynature; } public void setgatewaynature(string gatewaynature) { this.gatewaynature = gatewaynature; } public string getgatewaysupply() { return gatewaysupply; } public void setgatewaysupply(string gatewaysupply) { this.gatewaysupply = gatewaysupply; } public string getremark() { return remark; } public void setremark(string remark) { this.remark = remark; } public static long getserialversionuid() { return serialversionuid; } @override public string tostring() { return "gateway [gatewayid=" + gatewayid + ", gatewayname=" + gatewayname + ", gatewaynum=" + gatewaynum + ", gatewaynature=" + gatewaynature + ", gatewaysupply=" + gatewaysupply + ", remark=" + remark + "]"; } }
以上所述是www.887551.com给大家介绍的oracle在mybatis中sql语句的配置 ,希望对大家有所帮助