-
配置内容查看全部
-
mybatis-config配置全局属性
未在配置文件中配置
查看全部 -
mybatis-config配置文件
查看全部 -
使用java代码配置datasource
查看全部 -
使用java代码
配置sqlsessionfactory
查看全部 -
异常处理
查看全部 -
insert update get
查看全部 -
package com.forsaken.mina.web; import com.forsaken.mina.entity.Area; import com.forsaken.mina.service.AreaService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; import java.util.List; import java.util.Map; @RestController @RequestMapping("/superadmin") public class AreaController { @Autowired private AreaService areaService; @RequestMapping(value = "/listarea", method = RequestMethod.GET) private Map<String, Object> listArea() { Map<String, Object> modelMap = new HashMap<>(); List<Area> list = areaService.getAreaList(); modelMap.put("areaList", list); return modelMap; } @RequestMapping(value = "/getareabyid", method = RequestMethod.GET) private Map<String, Object> getAreaById(Integer areaId) { Map<String, Object> modelMap = new HashMap<>(); Area area = areaService.getAreaById(areaId); modelMap.put("area", area); return modelMap; } @RequestMapping(value = "/addarea", method = RequestMethod.POST) private Map<String, Object> addArea(@RequestBody Area area) { Map<String, Object> modelMap = new HashMap<>(); modelMap.put("success", areaService.addArea(area)); return modelMap; } @RequestMapping(value = "/modifyarea", method = RequestMethod.POST) private Map<String, Object> modifyArea(@RequestBody Area area) { Map<String, Object> modelMap = new HashMap<>(); //修改区域信息 modelMap.put("success", areaService.modifyArea(area)); return modelMap; } @RequestMapping(value = "/removearea", method = RequestMethod.GET) private Map<String, Object> removeArea(Integer areaId) { Map<String, Object> modelMap = new HashMap<>(); modelMap.put("success", areaService.deleteArea(areaId)); return modelMap; } }
查看全部 -
package com.forsaken.mina.service.impl; import com.forsaken.mina.dao.AreaDao; import com.forsaken.mina.entity.Area; import com.forsaken.mina.service.AreaService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.List; @Service public class AreaServiceImpl implements AreaService { @Autowired private AreaDao areaDao; @Override public List<Area> queryArea() { return areaDao.queryArea(); } @Override public Area queryAreaById(int areaId) { return areaDao.queryAreaById(areaId); } /** * 当抛出RuntimeException时事务Transactional才会回滚 * @param area * @return */ @Transactional @Override public boolean addArea(Area area) { if (area.getAreaName() != null && !"".equals(area.getAreaName())) { area.setCreateTime(new Date()); area.setLastEditTime(new Date()); try { int effectedNum = areaDao.insertArea(area); if (effectedNum > 0) { return true; } else { throw new RuntimeException("插入区域信息失败!"); } } catch (Exception e) { throw new RuntimeException("插入区域信息失败:" + e.getMessage()); } } else { throw new RuntimeException("区域信息不能为空!"); } } @Override public boolean modifyArea(Area area) { //空值判断,主要是areaId不为空 if (area.getAreaId() != null && area.getAreaId() > 0) { //设置默认值 area.setLastEditTime(new Date()); try { //更新区域信息 int effectedNum = areaDao.updateArea(area); if (effectedNum > 0) { return true; } else { throw new RuntimeException("更新区域信息失败!"); } } catch (Exception e) { throw new RuntimeException("更新区域信息失败:" + e.getMessage()); } } else { throw new RuntimeException("区域信息不能为空!"); } } @Override public boolean deleteArea(int areaId) { if (areaId > 0) { try { //删除区域信息 int effectedNum = areaDao.deleteArea(areaId); if (effectedNum > 0) { return true; } else { throw new RuntimeException("删除区域信息失败!"); } } catch (Exception e) { throw new RuntimeException("删除区域信息失败:" + e.getMessage()); } } else { throw new RuntimeException("区域ID不能为空!"); } } }
查看全部 -
package com.forsaken.mina.dao; import com.forsaken.mina.entity.Area; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.util.Date; import java.util.List; import static org.junit.Assert.*; @RunWith(SpringRunner.class) @SpringBootTest public class AreaDaoTest { @Autowired private AreaDao areaDao; @Test @Ignore public void queryArea() { List<Area> areaList = areaDao.queryArea(); assertEquals(2, areaList.size()); } @Test @Ignore public void queryAreaById() { Area area = areaDao.queryAreaById(1); assertEquals("东苑", area.getAreaName()); } @Test @Ignore public void insertArea() { Area area = new Area(); area.setAreaName("南苑"); area.setPriority(1); int effectedNum = areaDao.insertArea(area); assertEquals(1, effectedNum); } @Test @Ignore public void updateArea() { Area area = new Area(); area.setAreaName("西苑"); area.setAreaId(3); area.setLastEditTime(new Date()); int effectedNum = areaDao.updateArea(area); assertEquals(1, effectedNum); } @Test @Ignore public void deleteArea() { int effectedNum = areaDao.deleteArea(3); assertEquals(1, effectedNum); } }
查看全部 -
@MapperScan("包名"):类上加这个注解表示要让spring自动扫描这个包下的mapper
查看全部 -
获取配置文件中属性的值时不仅仅需要在要赋值的属性上加上@Value注解还要在类上加上@Configuration注解
查看全部 -
getter and setter idea快捷键为 alt+insert
查看全部 -
https://gitee.com/xiangze/areadisplay
https://gitee.com/xiangze/demo查看全部 -
git:
https://gitee.com/xiangze/areadisplay
https://gitee.com/xiangze/demo查看全部
举报
0/150
提交
取消