1.Mapper.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.test.dao.StrategyDao">
<resultMap id="StrategyResultMap" type="com.test.entity.Strategy">
<result property="id" column="id"/>
<result property="projectId" column="project_id"/>
<result property="strategyType" column="strategy_type"/>
<result property="strategyName" column="strategy_name"/>
<result property="alias" column="alias"/>
</resultMap>
<select id="findNameList" resultType="java.util.Map" parameterType="com.test.entity.Strategy">
SELECT DISTINCT t.strategy_name strategyName,t.alias from test_strategy t WHERE
t.project_id=
AND (t.strategy_name LIKE concat('%',
or t.alias LIKE concat('%',
</select>
</mapper>
2.Dao
@MyBatisRepository
public interface StrategyDao extends ICrudDao<Strategy, Integer> {
List<Map<String,Object>> findNameList(Strategy entity);
}
3.service
public List<Map<String, Object>> findNameList(Strategy strategy) throws Exception {
try {
return dao.findNameList(strategy);
} catch (Exception var3) {
throw new MySqlException("P2101", "数据库执行异常", var3);
}
}
public class MySqlException extends ServiceException {
public MySqlException(String errorCode, Object[] args) {
super(errorCode, args);
}
public MySqlException(String errorCode) {
super(errorCode);
}
public MySqlException(String errorCode, String message) {
super(errorCode, message);
}
public MySqlException(String errorCode, String message, Throwable cause) {
super(errorCode, message, cause);
}
}
4.Controller
@RequestMapping("/nameList")
public Map<String, Object> findNameList(@RequestBody Strategy strategy) throws Exception {
try {
return result(strategyService.findNameList(strategy));
} catch (Exception e) {
throw e;
}
}
-----------
public Map<String, Object> result(Object object) {
Map<String, Object> result = new HashMap();
ResultUtil.addSuccessResult(result, object);
return result;
}
-------
public class ResultUtil {
public ResultUtil() {
}
public static void addSuccessResult(Map<String, Object> resultMap, Object data) {
resultMap.put("result", "1");
resultMap.put("msg", "调用成功!");
resultMap.put("code", "200");
resultMap.put("data", data);
}
}