分配前引用的局部变量“最高”

时间:2019-03-31 04:35:41

标签: python python-3.x

我尝试通过该函数调用,但是仍然弹出此错误消息。

 @Configuration
    @EnableWebMvc
    @ComponentScan(basePackages = { "org.websparrow.controller", "org.websparrow.dao" })
    public class WebMvcConfig {

        @Bean
        public InternalResourceViewResolver viewResolver() {

            InternalResourceViewResolver vr = new InternalResourceViewResolver();
            vr.setPrefix("/");
            vr.setSuffix(".jsp");

            return vr;
        }

        @Bean
        public MultipartResolver multipartResolver() {
            return new CommonsMultipartResolver();
        }

        @Bean
        public DriverManagerDataSource getDataSource() {

            DriverManagerDataSource ds = new DriverManagerDataSource();
            ds.setDriverClassName("com.mysql.jdbc.Driver");
            ds.setUrl("jdbc:mysql://localhost:3306/yourdatabase");
            ds.setUsername("root");
            ds.setPassword("");

            return ds;
        }

        @Bean
        public ImageDao getConnectionObject() {
            return new ImageDao(getDataSource());
        }
    }
    public class ImageDao {

        private JdbcTemplate jdbcTemplate;

        public ImageDao(DataSource dataSource) {
            jdbcTemplate = new JdbcTemplate(dataSource);
        }

        public int inserRecords(String name, Integer age, MultipartFile photo) throws IOException {

            byte[] photoBytes = photo.getBytes();

            String sql = "INSERT INTO STUDENT(NAME,AGE,PHOTO) VALUES (?,?,?)";

            return jdbcTemplate.update(sql, new Object[] { name, age, photoBytes });
        }
    }

    @Controller
    public class ImageController {

        @Autowired
        ImageDao imageDao;

        @RequestMapping(value = "/InsertImage", method = RequestMethod.POST)
        public ModelAndView save(@RequestParam("name") String name, @RequestParam("age") Integer age,
                @RequestParam("photo") MultipartFile photo) {

            try {
                imageDao.inserRecords(name, age, photo);

                return new ModelAndView("index", "msg", "Records succesfully inserted into database.");

            } catch (Exception e) {
                return new ModelAndView("index", "msg", "Error: " + e.getMessage());
            }
        }
    }
//Database
    CREATE TABLE `student` (
      `id` int(5) NOT NULL AUTO_INCREMENT,
      `name` varchar(30) DEFAULT NULL,
      `age` int(3) DEFAULT NULL,
      `photo` mediumblob,
      PRIMARY KEY (`id`)
    );**strong text**
//html form
<form action="InsertImage" method="post" enctype="multipart/form-data">

<pre>

    Name: <input type="text" name="name">

    Age: <input type="number" name="age">

    Photo: <input type="file" name="photo">

    <input type="submit" value="Submit">

</pre>

</form>

2 个答案:

答案 0 :(得分:1)

假设其中一个:

  • iex> ExpectBehaviour.use_behaviour(ClaimsItImplementsButDoesNot) ** (UndefinedFunctionError) function ClaimsItImplementsButDoesNot.foo/0 is undefined or private, but the behaviour ExpectBehaviour expects it to be present 为空;或
  • iex> ExpectBehaviour.use_behaviour(DoesNotImplementOrClaimTo) ** (UndefinedFunctionError) function DoesNotImplementOrClaimTo.foo/0 is undefined or private self.getstockList()的所有成员都是负面的

然后,您的代码将永远不会为r.value(...)分配任何值,因此,您对self.getstocklist()的尝试将导致您看到的异常。

假设在这种情况下您想返回highest。然后,为return highest

提供默认值
None

答案 1 :(得分:0)

我相信问题有时是if块不会触发。如果发生这种情况,则使用编写代码的方式,您仍将尝试返回最高值,但是如果没有if块触发,则不会创建该值。

您可能会去if if块。