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));
}
}