上传文件至 /
This commit is contained in:
commit
d8816735b1
|
@ -0,0 +1,35 @@
|
|||
package com.hnucm.springboot.springboot1.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
@Controller
|
||||
public class LoginController {
|
||||
@RequestMapping("/login")
|
||||
public String login(){
|
||||
return "login.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/logincommit")
|
||||
public String logincommit(String username,String password){
|
||||
// todo -》 数据库中验证
|
||||
if (username.equals("admin") && password.equals("123456")){
|
||||
return "success.html";
|
||||
}
|
||||
return "fail.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/uploadcommit")
|
||||
public String uploadcommit(MultipartFile file) throws IOException {
|
||||
String filename = UUID.randomUUID().toString() +file.getOriginalFilename();
|
||||
File file1 = new File("D:/data/");
|
||||
file.transferTo(new File(file1,filename));
|
||||
return "success.html";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.hnucm.springboot.springboot1.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
public class NewsController {
|
||||
@RequestMapping("/news/{newsid}")
|
||||
public String index(@PathVariable String newsid, Model model){
|
||||
model.addAttribute("newsid",newsid);
|
||||
return "news.html";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.hnucm.springboot.springboot1.controller;
|
||||
|
||||
import com.hnucm.springboot.springboot1.model.Person;
|
||||
import com.hnucm.springboot.springboot1.model.StuCard;
|
||||
import com.hnucm.springboot.springboot1.service.PersonService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//单表增删改查 多表 1对1 1对多 多对多 增删改 查(复杂)
|
||||
//1对1 person idcard(学生证) 外键
|
||||
|
||||
|
||||
@Controller
|
||||
public class PersonController {
|
||||
@Autowired
|
||||
private PersonService personService;
|
||||
|
||||
@RequestMapping("/personpage")
|
||||
public String getPersonPage(Model model){
|
||||
model.addAttribute("personlist",personService.getAllPerson());
|
||||
return "personpage.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/addpersonpage")
|
||||
public String addpersonpage(){
|
||||
return "addperson.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/addpersoncommit")
|
||||
public String addpersoncommit(String name,int age,String stuid,String classname){
|
||||
Person person = new Person();
|
||||
person.setName(name);
|
||||
person.setAge(age);
|
||||
StuCard stuCard = new StuCard();
|
||||
stuCard.setClassname(classname);
|
||||
stuCard.setStuid(stuid);
|
||||
person.setStuCard(stuCard);
|
||||
|
||||
personService.addPerson(person);
|
||||
return "redirect:/personpage";
|
||||
}
|
||||
@RequestMapping("/deleteperson")
|
||||
public String deleteperson(int id,int stuid){
|
||||
personService.deletePerson(id,stuid);
|
||||
return "redirect:/personpage";
|
||||
}
|
||||
|
||||
@RequestMapping("/updatepersonpage")
|
||||
public String updatepersonpage(Person person,Model model){
|
||||
model.addAttribute("person",person);
|
||||
return "updateperson.html";
|
||||
}
|
||||
|
||||
@RequestMapping("/updatepersoncommit")
|
||||
public String updatepersoncommit(Person person){
|
||||
personService.updatePerson(person);
|
||||
return "redirect:/personpage";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.hnucm.springboot.springboot1;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Springboot1Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Springboot1Application.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.hnucm.springboot.springboot1.controller;
|
||||
|
||||
import com.hnucm.springboot.springboot1.model.User;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
public class TestController {
|
||||
|
||||
//返回网页
|
||||
@RequestMapping("/test")
|
||||
public String index(Model model){
|
||||
//todo 数据库查询得到
|
||||
User user = new User();
|
||||
user.setId(1);
|
||||
user.setName("张三");
|
||||
user.setAge(20);
|
||||
List<User> userList = new ArrayList<>();
|
||||
for (int i = 0 ;i < 10; i ++){
|
||||
User user1 = new User();
|
||||
user1.setId(i);
|
||||
user1.setName("张三" + i);
|
||||
user1.setAge(20);
|
||||
userList.add(user1);
|
||||
}
|
||||
model.addAttribute("name","张三");
|
||||
model.addAttribute("user",user);
|
||||
model.addAttribute("userList",userList);
|
||||
return "test.html";
|
||||
}
|
||||
|
||||
// ResponseBody 返回JSON数据 User对象转成JSON字符串返回 app端+小程序
|
||||
@ResponseBody
|
||||
@RequestMapping("/user")
|
||||
public User index1(){
|
||||
User user = new User();
|
||||
user.setId(1);
|
||||
user.setName("张三");
|
||||
user.setAge(20);
|
||||
return user;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue