您的位置:首页 > 移动开发

mybatis逆向工程的Example类用法==笔记==【单表操作只需调用,多表查询需要自定义sql+mapper接口方法(待补全)】

2017-11-25 22:50 2496 查看
======上代码:

===版本1:

@Service
public class BaseDictServiceImpl implements BaseDictService {

//查询数据字典表,注入数据字典表mapper接口代理对象
@Autowired
private BaseDictMapper baseDictMapper;

/**
* 需求:根据类别码查询类别信息
* 参数:String typeCode
* 返回值:List<BaseDict>
* ==========每个实体类【生成的Mapper文件 ,所有的单表操作,都已经定义好了SQL,只需要添加添加条件即可】
* ====对于多表查询,只有自己 创建 example对象,封装查询条件。
*/
public List<BaseDict> findBaseDictWithTypeCode(String typeCode) {
//===example用来封装查询条件
BaseDictExample example = new BaseDictExample();
Criteria criteria = example.createCriteria();
//=======所有的单表查询,example里都有,根据方法名调用即可。
criteria.andDictTypeCodeNotEqualTo(typeCode);
//===######【以上三行代码,实现封装 单表查询参数】

//使用example查询对象,执行查询
//===mapper的方法也是 生成的,===单表查询,真的不需要自定义任何方法。
List<BaseDict> list = baseDictMapper.selectByExample(example);

return list;
}

}

 

===版本2:

@Controller
public class CustomerController {

@Autowired
BaseDictService baseDictService;

/*
//=============typeCode 配置到配置文件里。==【配置文件读取+注解在实体类显示】
<!-- ====读取配置文件里的 typeCode -->
<context:property-placeholder location="classpath:resources.properties"/>

* */
@Value("${CUST_SOURCE_CODE}")
// final String CUST_SOURCE_CODE;
String CUST_SOURCE_CODE;

@Value("${CUST_INDUSTRY_CODE}")
String CUST_INDUSTRY_CODE;

@Value("${CUST_LEVEL_CODE}")
String CUST_LEVEL_CODE;//ok

/**
* 需求:加载客户列表页面
* 业务需求: 加载客户列表页面之前,需要初始化 客户来源下拉列表,客户行业下拉列表,客户级别下拉列表
*/
@RequestMapping("list")
public String showCustomList(Model model){
//===查询======####====熟悉BaseDict表结构含义
// //客户行业下拉列表,
// List<BaseDict> industryList = baseDictService.findBaseDictWithTypeCode("001");
// //初始化 客户来源下拉列表,
// List<BaseDict> sourceList = baseDictService.findBaseDictWithTypeCode("002");
// //客户级别下拉列表
// List<BaseDict> levelList = baseDictService.findBaseDictWithTypeCode("006");

//=============typeCode 配置到配置文件里。==【配置文件读取+注解在实体类显示】
//初始化 客户来源下拉列表,
List<BaseDict> sourceList = baseDictService.findBaseDictWithTypeCode(CUST_SOURCE_CODE);
//客户行业下拉列表,
List<BaseDict> industryList = baseDictService.findBaseDictWithTypeCode(CUST_INDUSTRY_CODE);
//客户级别下拉列表
List<BaseDict> levelList = baseDictService.findBaseDictWithTypeCode(CUST_LEVEL_CODE);

//=========传到页面
model.addAttribute("fromType", sourceList);
model.addAttribute("industryType", industryList);
model.addAttribute("levelType", levelList);

return "list";//逻辑视图:list.jsp
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐