您的位置:首页 > 编程语言 > Java开发

Springboot + Mybatis (注解+动态Sql)+RESTFUL+thymeleaf

2018-03-15 00:03 976 查看
添加了一个SqlProvider,进行动态Sql的编写
在Mapper类中使用selectProvider注解



因为我们这个查询是有两个参数 
在超过一个参数的情况下,@SelectProvide方法必须接受Map<String, Object>做为参数,
如果参数使用了@Param注解,那么参数在Map中以@Param的值为key, para.get("empno") 
如果参数没有使用@Param注解,那么参数在Map中以参数的顺序为key,para.get("1") ;
public class SqlProvider {

public String findEmpbyEmpNoandENameSql(Map<String, Object> param) {
String sql = new SQL().SELECT("*")
.FROM("emp")
.WHERE("EMPNO LIKE '%" + param.get("empno") + "%'")
.AND()
.WHERE("ENAME LIKE '%" + param.get("ename") + "%'")
.toString();
System.out.println("SQL" + sql);
return sql;
}
}
官方文档:http://www.mybatis.org/mybatis-3/statement-builders.html

集成thymeleaf需要添加配置依赖和配置文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--去掉HTML5校验-->
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
</dependency>
<dependency>
<groupId>org.unbescape</groupId>
<artifactId>unbescape</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>RESTFUl
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: