4.0.0 com.likejin myweb 1.0-SNAPSHOT war myweb Maven Webapp http://www.example.com src/main/java **/*.* src/main/resources **/*.* 5.1.6.RELEASE mysql mysql-connector-java 5.1.32 org.springframework spring-tx ${spring-version} org.springframework spring-context ${spring-version} org.springframework spring-beans ${spring-version} org.springframework spring-jdbc ${spring-version} org.springframework spring-webmvc ${spring-version} org.springframework spring-core ${spring-version} org.springframework spring-jdbc ${spring-version} com.baomidou mybatis-plus 2.3 com.mchange c3p0 0.9.5.2 log4j log4j 1.2.12 jstl jstl 1.2 taglibs standard 1.1.2 org.thymeleaf thymeleaf-spring5 3.0.12.RELEASE org.thymeleaf thymeleaf 3.0.12.RELEASE
Archetype Created Web Application characterEncodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding utf-8 forceRequestEncoding true forceResponseEncoding true characterEncodingFilter /* DispatcherServlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:springmvc.xml 1 DispatcherServlet /
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:13306/mytest?useUnicode=true&characterEncoding=utf8&useSSL=false
jdbc.username=root
jdbc.password=abc123
package com.likejin.myweb.pojo;public class User {private Integer uid;private Integer password;private String uname;@Overridepublic String toString() {return "User{" +"uid=" + uid +", password=" + password +", uname=" + uname +'}';}public User(Integer uid, Integer password, String uname) {this.uid = uid;this.password = password;this.uname = uname;}public User() {}public Integer getUid() {return uid;}public User(Integer uid, Integer password) {this.uid = uid;this.password = password;}public void setUid(Integer uid) {this.uid = uid;}public Integer getPassword() {return password;}public void setPassword(Integer password) {this.password = password;}public String getUname() {return uname;}public void setUname(String uname) {this.uname = uname;}
}
package com.likejin.myweb.dao;import com.likejin.myweb.pojo.User;
import org.springframework.stereotype.Component;public interface UserDao {User selectone(User user);
}
package com.likejin.myweb.service;import com.likejin.myweb.pojo.User;
import org.springframework.stereotype.Service;public interface UserService {User getUser(User user);
}
package com.likejin.myweb.service.impl;import com.likejin.myweb.dao.UserDao;
import com.likejin.myweb.pojo.User;
import com.likejin.myweb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class UserServiceImpl implements UserService {@AutowiredUserDao userDao;@Overridepublic User getUser(User user) {User selectone = userDao.selectone(user);return selectone;}
}
package com.likejin.myweb.controller;import com.likejin.myweb.pojo.User;
import com.likejin.myweb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;@Controller
@RequestMapping(value="/login")
public class LoginController {@AutowiredUserService userService;@RequestMapping(value="/check")public String checkLogin( User user,Model model){User user1 = userService.getUser(user);if(user1==null){return "error";}else{model.addAttribute("name",user1.getUname());return "success";}}
}
Hello World!
<%@ page pageEncoding="UTF-8"%>用户登录
Title
你好
asa
Title
点击此处重新登录
//访问资源地址为/user/my/133
@GetMapping("/user/{username}/{password}")public String getUserInfo(@PathVariable("username") String username,@PathVariable("password") String password)
///user?username=123&password=123
@GetMapping("/user")public String getUserInfo(@RequestParam("username") String username,@RequestParam("password") String password)
HiddenHttpMethodFilter org.springframework.web.filter.HiddenHttpMethodFilter HiddenHttpMethodFilter /*
Insert title here
我是html页面
dianwoceshi
package com.likejin.myweb.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;@Controller
@RequestMapping(value="/data")
public class RestfulController {@RequestMapping(value = "/employees", method = RequestMethod.GET)public String get(){System.out.println("get");return "success";}@RequestMapping(value = "/employees", method = RequestMethod.POST)public String add() {System.out.println("post");return "success";}@RequestMapping(value = "/employees", method = RequestMethod.PUT)public String update() {System.out.println("put");return "success";}@RequestMapping(value = "/employees/{id}", method = RequestMethod.DELETE)@ResponseBodypublic String delete(@PathVariable Long id) {System.out.println("delete");return "success";}}
@Controller
@RequestMapping(value="/test")
public class AjaxRestController {@RequestMapping(value="/ajaxrest")public String test( Model model){return "testAjax";}
}
跳转到
此时表单提交的路径不是localhost:8080/web/data/employees
而是
localhost:8080/web/test/data/employees
如何解释?