springmvc下的mybatis的sharding分表
立即下载
资源介绍:
springmvc下的mybatis的sharding分表,执行resources下的database.sql建立mysql的分表,修改applicationContext.xml的数据库用户名和密码,既可以运行maven项目,详细开发过程如我的博客地址:http://blog.csdn.net/zhulin40/article/details/38705105
package com.action;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.model.ShardTestBean;
import com.service.ShardTestManager;
/**
* /shardTest/1 HTTP GET => 得到id = 1的shardTest /shardTest/1 HTTP DELETE => 删除 id = 1的shardTest
* /shardTest/1 HTTP PUT => 更新id = 1的shardTest /shardTest HTTP POST => 新增shardTest
*
* @author shiling
*
*/
@Controller
@RequestMapping("shardTest")
public class ShardTestAction {
private static Logger log = Logger.getLogger(ShardTestAction.class);
@Autowired
private ShardTestManager shardTestManager;
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ModelAndView get(@PathVariable String id) {
ModelAndView mv = new ModelAndView();
if (StringUtils.isNotEmpty(id)) {
mv.addObject("shardTestName", "获取用户信息成功 get" + id);
}
ShardTestBean shardTestBean = shardTestManager.get(id);
mv.addObject("shardTestBean", shardTestBean);
mv.setViewName("shardtestedit");
log.info("获取用户信息成功 get");
return mv;
}
@RequestMapping(value = "/",method = RequestMethod.POST)
public ModelAndView add(ShardTestBean shardTestBean) {
ModelAndView mv = new ModelAndView();
shardTestManager.add(shardTestBean);
mv.addObject("shardTestBean", shardTestBean);
mv.setViewName("shardtestedit");
log.info("添加用户信息成功 post");
return mv;
}
@RequestMapping(value = "/",method = RequestMethod.GET)
public ModelAndView list() {
ModelAndView mv = new ModelAndView();
List list = shardTestManager.queryForlist();
mv.addObject("list", list);
mv.setViewName("shardtestlist");
log.info("查询用户列表信息成功 get");
return mv;
}
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public ModelAndView update(@PathVariable String id, ShardTestBean shardTestBean) {
ModelAndView mv = new ModelAndView();
if (StringUtils.isNotEmpty(id)) {
mv.addObject("shardTestName", "修改用户信息成功 put" + id);
}
shardTestManager.update(shardTestBean);
mv.addObject("shardTestBean", shardTestBean);
mv.setViewName("shardtestedit");
log.info("修改用户信息成功 put");
return mv;
}
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public ModelAndView delete(@PathVariable String id, ShardTestBean shardTestBean) {
ModelAndView mv = new ModelAndView();
if (StringUtils.isNotEmpty(id)) {
mv.addObject("shardTestName", "删除用户信息成功 delete" + id);
}
shardTestManager.delete(id);
mv.addObject("shardTestBean", shardTestBean);
mv.setViewName("shardtestedit");
log.info("删除用户信息成功 delete");
return mv;
}
}