程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> 關於Oracle數據庫 >> Oracle在Mybatis中SQL語句的配置方法

Oracle在Mybatis中SQL語句的配置方法

編輯:關於Oracle數據庫

數據庫中有下劃線的字段在實體中應采用駝峰命名法,如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 + "]";
 }
}

以上所述是小編給大家介紹的Oracle在Mybatis中SQL語句的配置 ,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved