基于web公交查询系统---搭建mvc连接数据库(我的毕业设计,进度继续)

建立一个spring的项目:我在已经做过的项目基础下做的,所以接口连接数据库挺快。

 

 搭建好的。对应好数据库:

前几天进度已经完成简单的设计:

 

 完成登录,用户管理(修改删除)。

 

 

 继续的数据库的信息获取,搭建mvc步骤:

创建:BusinfoController 

@Controller
public class BusinfoController {

    @Autowired
    private BusinfoService businfoService;

    @RequestMapping("/businfo")//获取businfo接口
    @ResponseBody
    public List<Businfo> getAll(){
        return businfoService.getAllBusinfo();
    }



    @RequestMapping("/businfo/delete")
    @ResponseBody
    public int delete(@RequestBody BigInteger ids){

        return businfoService.deleteById(ids);
    }
    @RequestMapping("/businfo/create")
    @ResponseBody
    public Response<Businfo> create(@RequestBody  Businfo businfo){
        Response<Businfo> response = new Response<>();
        Businfo newId = businfoService.create(businfo);
        if(newId == null){
            response.setSuccess(false);
            response.setMessage("同名用户已经存在。");
            response.setData(null);
        }else{
            response.setSuccess(true);
            response.setMessage("创建用户成功");
            response.setData(businfo);
        }
        return response;
    }
    @RequestMapping("/businfo/login")
    @ResponseBody
    public Response<Businfo> login(@RequestBody  Businfo businfo){
        Response<Businfo> response = new Response<>();
        return response;
    }
}

  创建dao中

BusinfoMapper:

 

 

继续:mapper

model中:Businfo(数据对应数据库表)

 

 

 

 

server中:

 

 扩展service:

@Service
public class BusinfoServiceImpl implements BusinfoService {

    @Autowired
    private BusinfoMapper businfoMapper;

    @Override
    public List<Businfo> getAllBusinfo() {
        return businfoMapper.selectList(null);
    }

    @Override
    public Businfo create(Businfo businfo) {
        QueryWrapper<Businfo> qww = new QueryWrapper<>();
        qww.lambda().eq(Businfo::getId,businfo.getId());
        if( businfoMapper.selectCount(qww)>=1){
            return  null;
        }else{
            businfoMapper.insert(businfo);
        }

        return businfo;
    }

    @Override
    public Businfo login(Businfo businfo) {

        businfoMapper.deleteById(0);
        QueryWrapper<Businfo> qww = new QueryWrapper<>();
        qww.lambda().eq(Businfo::getId,businfo.getId());
        if( businfoMapper.selectCount(qww)>=1){
            return  null;
        }else{
            businfoMapper.insert(businfo);
        }
        return businfo;
    }

    @Override
    public Businfo update(Businfo businfo) {
        return null;
    }

    @Override
    public int deleteById(BigInteger ids) {
        businfoMapper.deleteById(ids);
        return 0;
    }

    @Override
    public int deleteByIds(BigInteger[] ids) {
        for(BigInteger id : ids){
            Businfo user = businfoMapper.selectById(id);
            if(user == null){
                return 0;
            }
        }
        for(BigInteger id : ids){
            businfoMapper.deleteById(id);
        }

        return ids.length;
    }
} 

映射的mapper

 

 最终获取到数据库的信息:

 

 

 

 

posted @ 2019-12-05 17:29  代码是肥钦喔  阅读(359)  评论(0编辑  收藏  举报