一、dispatcher-servlet.xml配置
二、applicationContext.xml配置
三、Controller 类
@Controller
@RequestMapping("/api")
public class TestController {
private static Logger logger = Logger.getLogger(ShopController.class);
@Autowired
TestService testService; //需要调用Spring逻辑服务类
@RequestMapping(value="/login.do",method = RequestMethod.POST)
public void login(HttpServletRequest request, HttpServletResponse response) {
}
}
四、Service类
//定义Sevice接口
public interface TestService {
String login(HttpServletRequest request, String userName, String password);
}
//定义ServiceImpl实现类型
@Service("ShopService")
public class TestServiceImpl implements ShopService{
@Autowired
TestDao testDao; //mybatis 持久化服务接口
@Override
public String login(HttpServletRequest request, String userName, String password) {
}
五、myBatis持久化服务接口
@Repository
public interface TestDao {
//查询语句
@Select("select Top 1 * from Face_Register where telNo=#{telNo}")
Face_Register getByTelephone(String telNo);
//存储过程
@Select("{call dbo.Page(" +
"#{map.out_PageCount,mode=OUT,jdbcType=INTEGER},"+ //总页数输出
"#{map.out_ResultCount,mode=OUT,jdbcType=INTEGER},"+ //总记录数输出
"#{map.out_SQL,mode=OUT,jdbcType=NVARCHAR}," + //返回数据库SQL查询语句
"#{map.in_Table,mode=IN,jdbcType=NVARCHAR},"+ //查询表名
"#{map.in_Key,mode=IN,jdbcType=VARCHAR}," + //主键
"#{map.in_Fields,mode=IN,jdbcType=NVARCHAR}," + //查询字段
"#{map.in_Where,mode=IN,jdbcType=NVARCHAR}," + //查询条件
"#{map.in_Order,mode=IN,jdbcType=NVARCHAR}," + //排序字段
"#{map.in_Begin,mode=IN,jdbcType=INTEGER}," + //开始位置
"#{map.in_PageIndex,mode=IN,jdbcType=INTEGER}," + //当前页数
"#{map.in_PageSize,mode=IN,jdbcType=INTEGER})}") //页大小
@Options(statementType= StatementType.CALLABLE)
List getByAttrs(@Param("map") Map map);
//插入语句
@Insert("insert into Face_Register(name,openId,telNo,applyTime,state,imgUrl,cardNo) " +"values(#{faceRegister.name},#{faceRegister.openId},#{faceRegister.telNo},getDate(),#{faceRegister.state}," +"#{faceRegister.imgUrl},#{faceRegister.cardNo})")
long add(@Param("faceRegister") Face_Register faceRegister);
//修改语句
@Update("update Face_Register set state=#{state} where id=#{id} and state<>2")
long approve(@Param("id") int id,@Param("state") int state);
}