Commit b575638b by gechengyang

提交Smh注解方式代码样例

parent 0fcf0bf0
......@@ -85,8 +85,11 @@
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
......
package com.brilliance.entity;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@Table(name="smh")
public class Smh {
@Id
@Column(name="inr")
private String inr;
@Column(name="crtfrm")
private String crtfrm;
@Column(name = "dattim")
private Date dattim;
public String getInr() {
return inr;
}
public void setInr(String smhinr) {
this.inr = smhinr;
}
public String getCrtfrm() {
return crtfrm;
}
public void setCrtfrm(String crtfrm) {
this.crtfrm = crtfrm;
}
public Date getDattim() {
return dattim;
}
public void setDattim(Date dateTime) {
this.dattim = dateTime;
}
}
......@@ -8,5 +8,7 @@ public interface LckMapper {
int insertSelective(Lck record);
int deleteByPrimaryKey(@Param("txt") String txt, @Param("nam") String nam);
Lck selectLck(@Param("nam") String userName, @Param("txt") String txtInfo);
int deleteByPrimaryKey(@Param("txt") String txtInfo,@Param("nam") String userName);
}
\ No newline at end of file
package com.brilliance.mapper;
import com.brilliance.entity.Smh;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
public interface SmhMapper {
//@Select({"select * from user where age=#{age}"})
@Select({"select * from smh where inr= #{inr} "})
Smh selectSmh(@Param("inr") String inr);
@Insert({"insert into smh(inr,crtfrm,dattim) values (#{inr},#{crtfrm},#{dattim})"})
int insert(Smh smh);
}
\ No newline at end of file
......@@ -4,6 +4,8 @@ import com.brilliance.entity.Lck;
import com.brilliance.mapper.LckMapper;
import com.brilliance.service.LckService;
import org.apache.commons.lang.reflect.MethodUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -18,6 +20,7 @@ import java.util.Date;
*/
@Service
public class LckServiceImpl implements LckService {
private static Logger logger=LoggerFactory.getLogger(LckServiceImpl.class);
@Autowired
private LckMapper lckMapper;
......@@ -38,10 +41,19 @@ public class LckServiceImpl implements LckService {
if(inrObj==null) {
return false;
}
String inr= (String) inrObj;
lck.setTxt(modeType+inr);
String txt=modeType+inr;
Lck lck1 = lckMapper.selectLck(userName, modeType);
if(lck1!=null){
logger.info("lck has been exsist,lck txt=【"+lck1.getTxt()+"】");
return false;
}
logger.info("logger test");
lck.setTxt(txt);
lck.setNam(userName);
lck.setDattim(new Date());
int insert = lckMapper.insert(lck);
if(insert>0)
return true;
......
......@@ -8,8 +8,8 @@
<properties resource="dbConfig.properties"></properties>
<classPathEntry location="E:\programFile\work\MavenRepository\com\oracle\ojdbc6\11.2.0.3\ojdbc6-11.2.0.3.jar" />
<!--<classPathEntry location="E:\programFile\work\MavenRepository\com\oracle\ojdbc6\11.2.0.3\ojdbc6-11.2.0.3.jar" />-->
<classPathEntry location="${jdbc.driverLocation}"/>
<!--指定特定数据库的jdbc驱动jar包的位置-->
......@@ -60,13 +60,13 @@
<!-- <property name="enableSubPackages" value="true"/>-->
</javaClientGenerator>
<!--<table schema="test" tableName="LCK" domainObjectName="Lck" enableCountByExample="false"
<table schema="test" tableName="LCK" domainObjectName="Lck" enableCountByExample="false"
enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"/>-->
selectByExampleQueryId="false"/>
<table schema="test" tableName="MPI" domainObjectName="Mpi" enableCountByExample="false"
<!-- <table schema="test" tableName="MPI" domainObjectName="Mpi" enableCountByExample="false"
enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"/>
selectByExampleQueryId="false"/>-->
<!--
<table schema="test" tableName="MPS" domainObjectName="Mps" enableCountByExample="false"
enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<properties resource="dbConfig.properties"/>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driverClass}"/>
<property name="url" value="${jdbc.connectionURL}"/>
<property name="username" value="${jdbc.userId}"/>
<property name="password" value="${jdbc.password}"/>
</dataSource>
</environment>
</environments>
<mappers>
<package name="com/brilliance/mapper"/>
<!--<mapper resource="com/brilliance/mapper/MpsMapper.xml"/>
<mapper resource="com/brilliance/mapper/MpiMapper.xml"/>
<mapper resource="com/brilliance/mapper/MpeMapper.xml"/>
<mapper resource="com/brilliance/mapper/LckMapper.xml"/>-->
</mappers>
</configuration>
......@@ -19,7 +19,6 @@
<mappers>
<!-- <package name="mappers"/>-->
<!--<mapper resource="com/brilliance/mappers/MpsMapper.xml"/>-->
<mapper resource="com/brilliance/mapper/MpsMapper.xml"/>
<mapper resource="com/brilliance/mapper/MpiMapper.xml"/>
<mapper resource="com/brilliance/mapper/MpeMapper.xml"/>
......
package com.brilliance.test;
import com.brilliance.entity.Lck;
import com.brilliance.entity.Mpi;
import com.brilliance.entity.Mps;
import com.brilliance.entity.Smh;
import com.brilliance.mapper.LckMapper;
import com.brilliance.mapper.MpiMapper;
import com.brilliance.mapper.MpsMapper;
import com.brilliance.mapper.SmhMapper;
import com.brilliance.util.DbCommonUtil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
......@@ -12,9 +17,33 @@ import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
public class MybatisTest {
@Test
public void test_annotation() throws Exception {
String resource = "mybatis-config-annotation.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
// sqlSessionFactory.getConfiguration().addMapper(MpsMapper.class);
//2. 获取SqlSession对象,用它来执行sql
SqlSession openSession = sqlSessionFactory.openSession();
SmhMapper smhMapper = openSession.getMapper(SmhMapper.class);
Smh smh = smhMapper.selectSmh("00001074");
System.out.println(smh.getDattim());
System.out.println(smh.getInr());
Smh smh1=new Smh();
smh1.setInr("TESTINR1");
smh1.setCrtfrm("TTT");
smh1.setDattim(new Date());
int insert = smhMapper.insert(smh1);
System.out.println("insert==="+insert);
openSession.commit();
openSession.close();
}
@Test
public void test() throws Exception {
String resource = "mybatis-config.xml";
......@@ -35,12 +64,20 @@ public class MybatisTest {
SqlSession openSession = DbCommonUtil.getSqlSession();
MpsMapper mpsMapper = openSession.getMapper(MpsMapper.class);
int cnt = mpsMapper.counterMps(">");
Mps mps = mpsMapper.selectByPrimaryKey("00000972");
System.out.println(mps.getLstdattim());
System.out.println("cnt="+cnt);
MpiMapper mpiMapper = openSession.getMapper(MpiMapper.class);
Mpi mpi = mpiMapper.getMpi("CFIX2022080100000901", "<");
System.out.println(mpi.getInr());
LckMapper lckMapper=openSession.getMapper(LckMapper.class);
Lck lck = lckMapper.selectLck("bgUser4", "mps00001421");
if(lck!=null) {
System.out.println(lck.getDattim());
}
DbCommonUtil.close(openSession);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment