Spring入门

 最简单的服务器

 

  • Controller:接收web请求

//示例
@Controller
public class IndexController {
    @RequestMapping("/") 
    @ResponseBody  //用于显示文本
    public String index() { 
        return "Hello NowCoder"; 
    } 
    @RequestMapping(value = "/profile/{groupId}/{userId}") 
    @ResponseBody 
    public String profile(@PathVariable("groupId") String groupId, 
                          @PathVariable("userId") int userId, 
                          @RequestParam(value = "type", defaultValue = "1") int type,
                          @RequestParam(value = "key", defaultValue = "nowcoder") String key) { 
        return String.format("{%s},{%d},{%d},{%s}", groupId, userId, type, key); 

    }
}

 

  • Service:各种函数,通过调取DAO层中的方法,与本地服务器中的数据进行交互

 

  • DAO层:提供数据支持,使方法变量与数据库中的数据进行交互

package com.example.wenda_new1.dao;


import com.example.wenda_new1.model.User;
import org.apache.ibatis.annotations.*;


//示例
@Mapper
public interface UserDAO {
    String TABLE_NAME = "user";
    String INSERT_FIELDS = " name, password, salt, head_url";
    String SELECT_FIELDS  ="id, "+INSERT_FIELDS;

    @Insert({"insert into ",TABLE_NAME,"(",INSERT_FIELDS,
            ") values(#{name},#{password},#{salt},#{headUrl})"})
    int addUser(User user);

    @Select({"select ",SELECT_FIELDS, " from",TABLE_NAME," where id=#{id}"})
    User selectById(int id);

    @Select({"select ",SELECT_FIELDS, " from",TABLE_NAME," where name=#{name}"})
    User selectByName(String name);

    @Update({"update ",TABLE_NAME," set password=#{password} where id=#{id}"})
    void updatePassword(User user);

    @Delete({"delete from ",TABLE_NAME," where id=#{id}"})
    void deleteById(int id);
}

 

Request&response(HttpServletResponse&HttpServletRequest)

request/response
request

参数解析

cookie读取

response

页面内容返回

cookie下发(response.addCookie(new Cookie(key, value));)

 

 

 

 

重定向

301:永久转移

302:临时转移

 

IOC: 依赖注入

AOP:面向切面编程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值