发表于: 2020-06-19 00:03:21
2 1549
今天完成的事情:
写完了所有的Service以及其实现类:
如:
AccountService:
package com.jnshu.service;
import com.jnshu.pojo.Account;
import java.util.List;
public interface AccountService {
int deleteByPrimaryKey(Long id);//删除账户
int insert(Account record);//新增账户
List<Account> selectAccount(Account record);//查询账户
int updateByPrimaryKeySelective(Account record);//编辑账户
}
AccountServiceImpl:
package com.jnshu.service;
import com.jnshu.dao.AccountMapper;
import com.jnshu.pojo.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class AccountServiceImpl implements AccountService {
@Autowired
private AccountMapper accountMapper;
public int deleteByPrimaryKey(Long id){
accountMapper.deleteByPrimaryKey(id);
return 1;
}//删除账户
public int insert(Account record){
accountMapper.insert(record);
return 1;
}//新增账户
public List<Account> selectAccount(Account record){
return accountMapper.selectAccount(record);
}//查询账户
public int updateByPrimaryKeySelective(Account record){
accountMapper.updateByPrimaryKeySelective(record);
return 1;
}//编辑账户
}
接下来编写Controller层:
package com.jnshu.controller;
import com.jnshu.pojo.Account;
import com.jnshu.service.AccountService;
import net.sf.json.JSONArray;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
public class AccountController {
@Autowired
private AccountService accountService;
@GetMapping("/Account")
@ResponseBody
public JSONArray selectAccount(@Param("username")String username){
Account account = new Account();
account.setUsername(username);
List<Account> list = accountService.selectAccount(account);
JSONArray jsonArray =JSONArray.fromObject(list);
return jsonArray;
}
@PostMapping("/Account")
public String insertAccount(@Param("username")String username,@Param("password")String password){
Account account = new Account();
account.setId(0L);
account.setUsername(username);
account.setPassword(password);
account.setRole("市场");
account.setCreateby("管理员");
account.setCreateat(20200618L);
account.setUpdateby("管理员");
account.setUpdateat(20200618L);
accountService.insert(account);
return "success";
}
}
明天计划完成的事情:
完成剩下的Controller编写。
评论