16.2.30(实现邀人入队的退出球队功能)

1、着几天又写了个小项目,写下来给以后的自己看看。

首先是项目截图

 然后是需要用到的数据库表,只是用到了表的部分数据

 

 2、下面是代码的实现了(逆向工程的顺序来的)

(1)ibatis_team_quit.xml(sqlmaqconfig.xml的配置就不多言了)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap>

	<cacheModel id="teamIntegral" type="memory" readOnly="true"
		serialize="false">
		<flushInterval hours="24" />
	</cacheModel>
	
	<update id="updateTeamUserState" >
		<![CDATA[
			UPDATE
				t_team_user
			SET
				visit_state=9
			WHERE	
				user_id	=
				(SELECT 
					user_id
				FROM
					t_user_info
				WHERE
					openfire_username=#openfire_username#)
			AND
				team_id = #team_id#
		]]>
	</update>
</sqlMap>

 (2)TeamQuitDao.java

package com.enjoy.golf.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

@Repository
public class TeamQuitDao extends BaseDao{
	public int quitTeam(String openfire_username,int team_id){
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("openfire_username", openfire_username);
			map.put("team_id", team_id);
			return this.getSqlMapClientTemplate().update("updateTeamUserState",map);
		}
	}

 (3)TeamQuitService.java

package com.enjoy.golf.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.enjoy.golf.dao.TeamQuitDao;
import com.enjoy.golf.po.golf.response.BaseResponse;

@Service
public class TeamQuitService {
	@Resource
	TeamQuitDao teamquitDao;
	
	@Transactional(readOnly = false)
	//更新球员退出球队状态
	public BaseResponse quitTeam(String openfire_username,int team_id){
		return teamquitDao.quitTeam(openfire_username, team_id) == 1? 
				new BaseResponse("0", "成功退出"):
				new BaseResponse("1","退出不成功") ;
		
//		int flg=  teamquitDao.quitTeam(openfire_username, team_id)
//		if(flg == 1){
//			return new BaseResponse("0", "成功退出"); 
//		}
//		return new BaseResponse("1","退出失败");
	}
}

 (4)TeamQuitController.java

package com.enjoy.golf.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.enjoy.golf.po.golf.response.BaseResponse;
import com.enjoy.golf.service.TeamQuitService;

@Controller
@RequestMapping("teamquit")
public class TeamQuitController {
	
	@Resource private TeamQuitService teamquitService;
	
	@RequestMapping(value = "quit",method = RequestMethod.POST)
	public  @ResponseBody BaseResponse quitTeam(
			@RequestParam(defaultValue = "")String openfire_username,
			@RequestParam(defaultValue = "")int team_id){
				return teamquitService.quitTeam(openfire_username, team_id);
			}

}

 (5)TeamQuitDaoTest.java

package test.dao;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.enjoy.golf.dao.TeamQuitDao;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring/root-context.xml" })
public class TeamQuitDaoTest {

	@Resource TeamQuitDao teamquitDao;
	
	@Test
	public void testTeamQuit(){
		System.out.println(teamquitDao.quitTeam("oStHpjncrfHDW_Ozk6vtVnYuDsNU", 14));
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值