spring.datasource.url=jdbc:mysql://localhost:3306/lx?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=root
mybatis.configuration.map-underscore-to-camel-case=true
字节码处理
@Controller
public class AgentController {
@Autowired
private AgentMapper agentMapper;
@RequestMapping("/add")
public String add(Agent agent){
agentMapper.add(agent);
return "redirect:/select";
}
@RequestMapping("/")
public String index(){
return "a/index.html";
}
@RequestMapping("/select")
public String select(Model model){
List<Agent> list =agentMapper.select();
model.addAttribute("list",list);
return "a/select.html";
}
@RequestMapping("/delete")
public String delete(Agent agent, Model model){
agentMapper.delete(agent);
List<Agent> list =agentMapper.select();
model.addAttribute("list",list);
return "a/delete.html";
}
@RequestMapping("/update")
public String update(Agent agent, Model model){
Agent list = agentMapper.update(agent);
model.addAttribute("agent",list);
return "a/update.html";
}
@RequestMapping("/setupdate")
public String setUpdate(Agent agent){
agentMapper.delete(agent);
agentMapper.add(agent);
return "redirect:/select";
}
}
@Options(useGeneratedKeys = true, keyProperty = "id")
@Insert("INSERT INTO AGENT VALUES(null,#{sex},#{name},#{age})")
int add(Agent agent);
@Select("select * from agent")
List<Agent> select();
@Mapper
public interface AgentMapper {
@Options(useGeneratedKeys = true, keyProperty = "id")
@Insert("INSERT INTO AGENT VALUES(null,#{sex},#{name},#{age})")
int add(Agent agent);
@Select("select * from agent")
List<Agent> select();
@Delete("DELETE FROM AGENT WHERE ID = #{id}")
void delete(Agent agent);
@Select("select * from agent where id = #{id}")
Agent update(Agent agent);
}