//查询,返回list<map>
list<map<string, object>> list = sqlmapper.selectlist("select * from country where id < 11");
//查询,返回指定的实体类
list<country> countrylist = sqlmapper.selectlist("select * from country where id < 11", country.class);
//查询,带参数
countrylist = sqlmapper.selectlist("select * from country where id < #{id}", 11, country.class);
//复杂点的查询,这里参数和上面不同的地方,在于传入了一个对象
country country = new country();
country.setid(11);
countrylist = sqlmapper.selectlist("<script>" +
"select * from country " +
" <where>" +
" <if test="id != null">" +
" id < #{id}" +
" </if>" +
" </where>" +
"</script>", country, country.class);
selectone
map<string, object> map = sqlmapper.selectone("select * from country where id = 35");
map = sqlmapper.selectone("select * from country where id = #{id}", 35);
country country = sqlmapper.selectone("select * from country where id = 35", country.class);
country = sqlmapper.selectone("select * from country where id = #{id}", 35, country.class);
insert,update,delete
//insert
int result = sqlmapper.insert("insert into country values(1921,'天朝','tc')");
country tc = new country();
tc.setid(1921);
tc.setcountryname("天朝");
tc.setcountrycode("tc");
//注意这里的countrycode和countryname故意写反的
result = sqlmapper.insert("insert into country values(#{id},#{countrycode},#{countryname})"
, tc);
//update
result = sqlmapper.update("update country set countryname = '天朝' where id = 35");
tc = new country();
tc.setid(35);
tc.setcountryname("天朝");
int result = sqlmapper.update("update country set countryname = #{countryname}" +
" where id in(select id from country where countryname like 'a%')", tc);
//delete
result = sqlmapper.delete("delete from country where id = 35");
result = sqlmapper.delete("delete from country where id = #{id}", 35);