package org.zln.dao;
import org.springframework.stereotype.Repository;
import org.zln.domain.Message;
import java.util.List;
/**
* Created by sherry on 000006/7/6 19:16.
*/
@Repository
public class MessageDao extends BaseDao {
public List queryMessageList(String command,String description){
return sqlSessionTemplate.selectList("org.zln.domain.Message.queryMessageList");
}
}
-- 测试用表
create table User (
id identity
,username varchar(100)
,password varchar(100)
);
test-data.sql
insert into User (username,password) values ('姓名1','pd1');
insert into User (username,password) values ('姓名2','pd2');
insert into User (username,password) values ('姓名3','pd3');
insert into User (username,password) values ('姓名4','pd4');
insert into User (username,password) values ('姓名5','pd5');
insert into User (username,password) values ('姓名6','pd6');
insert into User (username,password) values ('姓名7','pd7');
insert into User (username,password) values ('姓名8','pd8');
insert into User (username,password) values ('姓名9','pd9');
insert into User (username,password) values ('姓名10','pd10');
insert into User (username,password) values ('姓名11','pd11');
数据源配置
package org.zln.spb.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import javax.sql.DataSource;
/**
* 数据库相关配置
* Created by nbcoolkid on 2017-06-26.
*/
@Configuration
public class DbConfig {
/**
* H2嵌入式数据库,用于开发
* @return
*/
@Bean(destroyMethod = "shutdown")
@Primary
@Profile("dev")
public DataSource dataSourceH2(){
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.addScript("classpath:sql/schema.sql")
.addScript("classpath:sql/test-data.sql")
.setScriptEncoding("UTF-8")
.build();
}
}
Dao
UserMapper
package org.zln.spb.dao.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.zln.spb.pojo.vo.User;
/**
* Created by nbcoolkid on 2017-06-26.
*/
@Mapper
public interface UserMapper {
User selectByPrimaryKey(int id);
}
UserMapper.xml
测试
package org.zln.spb.dao.mapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.*;
/**
* Created by nbcoolkid on 2017-06-26.
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class UserMapperTest {
@Autowired
private UserMapper userMapper;
@Test
public void selectByPrimaryKey() throws Exception {
System.out.println("UserMapper:"+userMapper);
System.out.println(userMapper.selectByPrimaryKey(1));
}
}
MyBatis配置文件详解
Mybatis映射文件详解
动态SQL元素
if
and role_name like concat('%',#{roleName},'%')
choose、when、otherwise
and role_no=#{roleNo}
and role_name like concat('%',#{roleName},'%')
and note is not null
什么是Thrift
The Apache Thrift software framework, for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and s
org.json.JSONException: No value for items
在JSON解析中会遇到一种错误,很常见的错误
06-21 12:19:08.714 2098-2127/com.jikexueyuan.secret I/System.out﹕ Result:{"status":1,"page":1,&